From 72faa129c3b588db3fbc6bab203f76bd8f7a68a0 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 13 Mar 2025 15:28:27 +0100 Subject: [PATCH] QmlDesigner: Remove SourcePathCache::sourceContextAndSourceId() SourcePathCache::sourceId() already contains the source id. Change-Id: I2ba783aea99af4d54c1beeda250f9b5e8f2460f4 Reviewed-by: Thomas Hartmann Reviewed-by: Burak Hancerli --- .../projectstorage/projectstorageupdater.cpp | 3 +- .../sourcepathstorage/sourcepathcache.h | 10 +-- .../sourcepathcacheinterface.h | 3 - tests/unit/tests/mocks/sourcepathcachemock.h | 5 -- .../sourcepathcache-test.cpp | 85 ------------------- 5 files changed, 4 insertions(+), 102 deletions(-) diff --git a/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.cpp b/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.cpp index e535f323176..aaa2a8e0d02 100644 --- a/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.cpp +++ b/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.cpp @@ -594,7 +594,8 @@ void ProjectStorageUpdater::updateDirectory(const Utils::PathString &directoryPa NanotraceHR::Tracer tracer{"update directory", category(), keyValue("directory", directoryPath)}; SourcePath qmldirPath{directoryPath + "/qmldir"}; - auto [directoryId, qmldirSourceId] = m_pathCache.sourceContextAndSourceId(qmldirPath); + SourceId qmldirSourceId = m_pathCache.sourceId(qmldirPath); + SourceContextId directoryId = qmldirSourceId.contextId(); auto directoryState = fileState(directoryId, package, notUpdatedSourceIds); if (isExisting(directoryState)) diff --git a/src/plugins/qmldesigner/libs/designercore/sourcepathstorage/sourcepathcache.h b/src/plugins/qmldesigner/libs/designercore/sourcepathstorage/sourcepathcache.h index c7d3184f78a..1fc3fcab84d 100644 --- a/src/plugins/qmldesigner/libs/designercore/sourcepathstorage/sourcepathcache.h +++ b/src/plugins/qmldesigner/libs/designercore/sourcepathstorage/sourcepathcache.h @@ -49,8 +49,7 @@ public: } } - std::pair sourceContextAndSourceId( - SourcePathView sourcePath) const override + SourceId sourceId(SourcePathView sourcePath) const override { Utils::SmallStringView sourceContextPath = sourcePath.directory(); @@ -60,12 +59,7 @@ public: auto sourceId = m_sourcePathCache.id(sourceName); - return {sourceContextId, SourceId::create(sourceId, sourceContextId)}; - } - - SourceId sourceId(SourcePathView sourcePath) const override - { - return sourceContextAndSourceId(sourcePath).second; + return SourceId::create(sourceId, sourceContextId); } SourceId sourceId(SourceContextId sourceContextId, diff --git a/src/plugins/qmldesigner/libs/designercore/sourcepathstorage/sourcepathcacheinterface.h b/src/plugins/qmldesigner/libs/designercore/sourcepathstorage/sourcepathcacheinterface.h index 8ad961ee80c..1f78bec1eb8 100644 --- a/src/plugins/qmldesigner/libs/designercore/sourcepathstorage/sourcepathcacheinterface.h +++ b/src/plugins/qmldesigner/libs/designercore/sourcepathstorage/sourcepathcacheinterface.h @@ -22,9 +22,6 @@ public: virtual void populateIfEmpty() = 0; - virtual std::pair - sourceContextAndSourceId(SourcePathView sourcePath) const = 0; - virtual SourceId sourceId(SourcePathView sourcePath) const = 0; virtual SourceId sourceId(SourceContextId sourceContextId, diff --git a/tests/unit/tests/mocks/sourcepathcachemock.h b/tests/unit/tests/mocks/sourcepathcachemock.h index 3e04ce98600..77560057f35 100644 --- a/tests/unit/tests/mocks/sourcepathcachemock.h +++ b/tests/unit/tests/mocks/sourcepathcachemock.h @@ -32,11 +32,6 @@ public: sourceContextId, (Utils::SmallStringView directoryPath), (const, override)); - using SourceContextAndSourceId = std::pair; - MOCK_METHOD(SourceContextAndSourceId, - sourceContextAndSourceId, - (QmlDesigner::SourcePathView sourcePath), - (const, override)); MOCK_METHOD(Utils::PathString, sourceContextPath, (QmlDesigner::SourceContextId directoryPathId), diff --git a/tests/unit/tests/unittests/sourcepathstorage/sourcepathcache-test.cpp b/tests/unit/tests/unittests/sourcepathstorage/sourcepathcache-test.cpp index 572d0f57f99..dd30127cbb9 100644 --- a/tests/unit/tests/unittests/sourcepathstorage/sourcepathcache-test.cpp +++ b/tests/unit/tests/unittests/sourcepathstorage/sourcepathcache-test.cpp @@ -372,89 +372,4 @@ TEST_F(SourcePathCache, get_file_path_after_populate_if_empty) ASSERT_THAT(path, Eq("/path/to/file.cpp")); } -TEST_F(SourcePathCache, source_context_and_source_id_with_out_any_entry_call_source_context_id) -{ - EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))); - - cache.sourceContextAndSourceId(SourcePathView("/path/to/file.cpp")); -} - -TEST_F(SourcePathCache, source_context_and_source_id_with_out_any_entry_calls) -{ - EXPECT_CALL(storageMock, fetchSourceNameId(Eq("file.cpp"))); - - cache.sourceContextAndSourceId(SourcePathView("/path/to/file.cpp")); -} - -TEST_F(SourcePathCache, source_context_and_source_id_of_source_id_with_out_any_entry) -{ - SourcePathView path("/path/to/file.cpp"); - - auto sourceId = cache.sourceId(path); - - ASSERT_THAT(sourceId.contextId(), sourceContextId5); -} - -TEST_F(SourcePathCache, source_context_and_source_id_if_entry_exists_dont_call_in_strorage) -{ - cache.sourceContextAndSourceId(SourcePathView("/path/to/file.cpp")); - - EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))).Times(0); - EXPECT_CALL(storageMock, fetchSourceNameId(Eq("file.cpp"))).Times(0); - - cache.sourceContextAndSourceId(SourcePathView("/path/to/file.cpp")); -} - -TEST_F(SourcePathCache, - source_context_and_source_id_if_directory_entry_exists_dont_call_fetch_source_context_id_but_still_call_fetch_source_id) -{ - cache.sourceContextAndSourceId(SourcePathView("/path/to/file2.cpp")); - - EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))).Times(0); - EXPECT_CALL(storageMock, fetchSourceNameId(Eq("file.cpp"))); - - cache.sourceContextAndSourceId(SourcePathView("/path/to/file.cpp")); -} - -TEST_F(SourcePathCache, source_context_and_source_id_get_source_id_with_cached_value) -{ - cache.sourceContextAndSourceId(SourcePathView("/path/to/file.cpp")); - - auto sourceId = cache.sourceContextAndSourceId(SourcePathView("/path/to/file.cpp")); - - ASSERT_THAT(sourceId, Pair(sourceContextId5, sourceId542)); -} - -TEST_F(SourcePathCache, get_source_context_and_source_id_with_source_context_id_cached) -{ - cache.sourceContextAndSourceId(SourcePathView("/path/to/file.cpp")); - - auto sourceContextAndSourceId = cache.sourceContextAndSourceId( - SourcePathView("/path/to/file2.cpp")); - - ASSERT_THAT(sourceContextAndSourceId, Pair(sourceContextId5, sourceId563)); -} - -TEST_F(SourcePathCache, get_source_context_and_source_id_file_names_are_unique_for_every_directory) -{ - auto sourceContextAndSourceId = cache.sourceContextAndSourceId( - SourcePathView("/path/to/file.cpp")); - - auto sourceContextAndSourceId2 = cache.sourceContextAndSourceId( - SourcePathView("/path2/to/file.cpp")); - - ASSERT_THAT(sourceContextAndSourceId, Ne(sourceContextAndSourceId2)); -} - -TEST_F(SourcePathCache, get_source_context_and_source_id_duplicate_file_paths_are_equal) -{ - auto sourceContextAndSourceId = cache.sourceContextAndSourceId( - SourcePathView("/path/to/file.cpp")); - - auto sourceContextAndSourceId2 = cache.sourceContextAndSourceId( - SourcePathView("/path/to/file.cpp")); - - ASSERT_THAT(sourceContextAndSourceId, Eq(sourceContextAndSourceId2)); -} - } // namespace