QmlDesigner: Remove findInSorted function

Using std::lower_bound is more generic and we have less code which
could lead to less bugs.

Change-Id: Iacf6ea550182b51a8d5dd6b18a92de68914f4df1
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marco Bubke
2021-04-27 10:31:29 +02:00
parent 3862f67b8d
commit c4c3d4cc33
5 changed files with 40 additions and 216 deletions

View File

@@ -39,7 +39,6 @@ using QmlDesigner::StorageCacheException;
using uint64 = unsigned long long;
using QmlDesigner::findInSorted;
using Utils::compare;
using Utils::reverseCompare;
@@ -53,21 +52,16 @@ public:
MockFilePathStorage &storage;
};
using CacheWithMockLocking = QmlDesigner::StorageCache<Utils::PathString,
Utils::SmallStringView,
int,
StorageAdapter,
NiceMock<MockMutex>,
decltype(&Utils::reverseCompare),
Utils::reverseCompare>;
auto less(Utils::SmallStringView first, Utils::SmallStringView second) -> bool
{
return Utils::reverseCompare(first, second) < 0;
};
using CacheWithoutLocking = QmlDesigner::StorageCache<Utils::PathString,
Utils::SmallStringView,
int,
StorageAdapter,
NiceMock<MockMutexNonLocking>,
decltype(&Utils::reverseCompare),
Utils::reverseCompare>;
using CacheWithMockLocking = QmlDesigner::
StorageCache<Utils::PathString, Utils::SmallStringView, int, StorageAdapter, NiceMock<MockMutex>, less>;
using CacheWithoutLocking = QmlDesigner::
StorageCache<Utils::PathString, Utils::SmallStringView, int, StorageAdapter, NiceMock<MockMutexNonLocking>, less>;
template<typename Cache>
class StorageCache : public testing::Test
@@ -275,111 +269,6 @@ TYPED_TEST(StorageCache, MultipleEntries)
ASSERT_THROW(this->cache.populate(std::move(entries)), StorageCacheException);
}
TYPED_TEST(StorageCache, DontFindInSorted)
{
auto found = findInSorted(this->filePaths.cbegin(), this->filePaths.cend(), "/file/pathFoo", compare);
ASSERT_FALSE(found.wasFound);
}
TYPED_TEST(StorageCache, FindInSortedOne)
{
auto found = findInSorted(this->filePaths.cbegin(), this->filePaths.cend(), "/file/pathOne", compare);
ASSERT_TRUE(found.wasFound);
}
TYPED_TEST(StorageCache, FindInSortedTwo)
{
auto found = findInSorted(this->filePaths.cbegin(), this->filePaths.cend(), "/file/pathTwo", compare);
ASSERT_TRUE(found.wasFound);
}
TYPED_TEST(StorageCache, FindInSortedTree)
{
auto found = findInSorted(this->filePaths.cbegin(),
this->filePaths.cend(),
"/file/pathThree",
compare);
ASSERT_TRUE(found.wasFound);
}
TYPED_TEST(StorageCache, FindInSortedFour)
{
auto found = findInSorted(this->filePaths.cbegin(), this->filePaths.cend(), "/file/pathFour", compare);
ASSERT_TRUE(found.wasFound);
}
TYPED_TEST(StorageCache, FindInSortedFife)
{
auto found = findInSorted(this->filePaths.cbegin(), this->filePaths.cend(), "/file/pathFife", compare);
ASSERT_TRUE(found.wasFound);
}
TYPED_TEST(StorageCache, DontFindInSortedReverse)
{
auto found = findInSorted(this->reverseFilePaths.cbegin(),
this->reverseFilePaths.cend(),
"/file/pathFoo",
reverseCompare);
ASSERT_FALSE(found.wasFound);
}
TYPED_TEST(StorageCache, FindInSortedOneReverse)
{
auto found = findInSorted(this->reverseFilePaths.cbegin(),
this->reverseFilePaths.cend(),
"/file/pathOne",
reverseCompare);
ASSERT_TRUE(found.wasFound);
}
TYPED_TEST(StorageCache, FindInSortedTwoReverse)
{
auto found = findInSorted(this->reverseFilePaths.cbegin(),
this->reverseFilePaths.cend(),
"/file/pathTwo",
reverseCompare);
ASSERT_TRUE(found.wasFound);
}
TYPED_TEST(StorageCache, FindInSortedTreeReverse)
{
auto found = findInSorted(this->reverseFilePaths.cbegin(),
this->reverseFilePaths.cend(),
"/file/pathThree",
reverseCompare);
ASSERT_TRUE(found.wasFound);
}
TYPED_TEST(StorageCache, FindInSortedFourReverse)
{
auto found = findInSorted(this->reverseFilePaths.cbegin(),
this->reverseFilePaths.cend(),
"/file/pathFour",
reverseCompare);
ASSERT_TRUE(found.wasFound);
}
TYPED_TEST(StorageCache, FindInSortedFifeReverse)
{
auto found = findInSorted(this->reverseFilePaths.cbegin(),
this->reverseFilePaths.cend(),
"/file/pathFife",
reverseCompare);
ASSERT_TRUE(found.wasFound);
}
TYPED_TEST(StorageCache, IdIsReadAndWriteLockedForUnknownEntry)
{
InSequence s;