From 6364692e15df4375043debe5566a57d8149c768a Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 5 Nov 2020 12:15:58 +0100 Subject: [PATCH] Utils: Move set algorithms to Utils So it can be used in other plugins which does not depend on clang. Change-Id: I80b9f44609921951444e13c5fd35476c047ad579 Reviewed-by: hjk Reviewed-by: Eike Ziller --- src/libs/clangsupport/clangsupport-lib.pri | 1 - src/libs/clangsupport/filestatuscache.cpp | 9 ++++----- src/libs/clangsupport/modifiedtimechecker.h | 13 ++++++++----- src/libs/clangsupport/stringcache.h | 4 ++-- src/libs/utils/CMakeLists.txt | 1 + src/libs/{clangsupport => utils}/set_algorithm.h | 5 +++-- src/libs/utils/utils-lib.pri | 3 ++- src/libs/utils/utils.qbs | 3 ++- .../source/projectpartsmanager.cpp | 7 ++++--- 9 files changed, 26 insertions(+), 20 deletions(-) rename src/libs/{clangsupport => utils}/set_algorithm.h (98%) diff --git a/src/libs/clangsupport/clangsupport-lib.pri b/src/libs/clangsupport/clangsupport-lib.pri index fa4a06fe77c..7eaee4a42aa 100644 --- a/src/libs/clangsupport/clangsupport-lib.pri +++ b/src/libs/clangsupport/clangsupport-lib.pri @@ -156,7 +156,6 @@ HEADERS += \ $$PWD/refactoringserverinterface.h \ $$PWD/refactoringserverproxy.h \ $$PWD/referencesmessage.h \ - $$PWD/set_algorithm.h \ $$PWD/stringcacheentry.h \ $$PWD/unsavedfilesupdatedmessage.h \ $$PWD/removeprojectpartsmessage.h \ diff --git a/src/libs/clangsupport/filestatuscache.cpp b/src/libs/clangsupport/filestatuscache.cpp index e8ed50a8335..3a13de79f52 100644 --- a/src/libs/clangsupport/filestatuscache.cpp +++ b/src/libs/clangsupport/filestatuscache.cpp @@ -26,9 +26,8 @@ #include "filestatuscache.h" #include "filesystem.h" -#include - #include +#include #include #include @@ -59,7 +58,7 @@ void FileStatusCache::update(FilePathIds filePathIds) m_cacheEntries.end(), filePathIds.begin(), filePathIds.end(), - make_iterator([&](auto &entry) { + Utils::make_iterator([&](auto &entry) { entry.lastModified = m_fileSystem.lastModified(entry.filePathId); })); } @@ -73,7 +72,7 @@ FilePathIds FileStatusCache::modified(FilePathIds filePathIds) const m_cacheEntries.end(), filePathIds.begin(), filePathIds.end(), - make_iterator([&](auto &entry) { + Utils::make_iterator([&](auto &entry) { auto newLastModified = m_fileSystem.lastModified(entry.filePathId); if (newLastModified > entry.lastModified) { modifiedFilePathIds.push_back(entry.filePathId); @@ -88,7 +87,7 @@ FilePathIds FileStatusCache::modified(FilePathIds filePathIds) const filePathIds.end(), m_cacheEntries.begin(), m_cacheEntries.end(), - make_iterator([&](FilePathId newFilePathId) { + Utils::make_iterator([&](FilePathId newFilePathId) { newEntries.emplace_back(newFilePathId, m_fileSystem.lastModified(newFilePathId)); modifiedFilePathIds.push_back(newFilePathId); diff --git a/src/libs/clangsupport/modifiedtimechecker.h b/src/libs/clangsupport/modifiedtimechecker.h index 58d1307daab..9d6b56d9e3d 100644 --- a/src/libs/clangsupport/modifiedtimechecker.h +++ b/src/libs/clangsupport/modifiedtimechecker.h @@ -27,7 +27,8 @@ #include "filesysteminterface.h" #include "modifiedtimecheckerinterface.h" -#include "set_algorithm.h" + +#include #include #include @@ -60,7 +61,7 @@ public: m_currentSourceTimeStamps.end(), filePathIds.begin(), filePathIds.end(), - make_iterator([&](SourceTimeStamp &sourceTimeStamp) { + Utils::make_iterator([&](SourceTimeStamp &sourceTimeStamp) { sourceTimeStamp.timeStamp = m_fileSystem.lastModified( sourceTimeStamp.sourceId); })); @@ -69,7 +70,7 @@ public: private: bool compareEntries(const SourceEntries &sourceEntries) const { - return !set_intersection_compare( + return !Utils::set_intersection_compare( m_currentSourceTimeStamps.begin(), m_currentSourceTimeStamps.end(), sourceEntries.begin(), @@ -99,12 +100,14 @@ private: sourceEntries.end(), m_currentSourceTimeStamps.begin(), m_currentSourceTimeStamps.end(), - make_iterator([&](const SourceEntry &sourceEntry) { + Utils::make_iterator([&](const SourceEntry &sourceEntry) { newTimeStamps.emplace_back(sourceEntry.sourceId, m_fileSystem.lastModified( sourceEntry.sourceId)); }), - [](auto first, auto second) { return first.sourceId < second.sourceId; }); + [](auto first, auto second) { + return first.sourceId < second.sourceId; + }); return newTimeStamps; } diff --git a/src/libs/clangsupport/stringcache.h b/src/libs/clangsupport/stringcache.h index 3185494cf37..87b92b4084a 100644 --- a/src/libs/clangsupport/stringcache.h +++ b/src/libs/clangsupport/stringcache.h @@ -25,13 +25,13 @@ #pragma once -#include "set_algorithm.h" #include "stringcachealgorithms.h" #include "stringcacheentry.h" #include "stringcachefwd.h" #include #include +#include #include #include @@ -197,7 +197,7 @@ public: strings.end(), m_strings.begin(), m_strings.end(), - make_iterator([&](StringViewType newString) { + Utils::make_iterator([&](StringViewType newString) { IndexType index = storageFunction(newString); newCacheEntries.emplace_back(newString, index); }), diff --git a/src/libs/utils/CMakeLists.txt b/src/libs/utils/CMakeLists.txt index be1f49f88d6..3ccc7a2c2d9 100644 --- a/src/libs/utils/CMakeLists.txt +++ b/src/libs/utils/CMakeLists.txt @@ -130,6 +130,7 @@ add_qtc_library(Utils savedaction.cpp savedaction.h savefile.cpp savefile.h scopedswap.h + set_algorithm.h settingsaccessor.cpp settingsaccessor.h settingsselector.cpp settingsselector.h settingsutils.h diff --git a/src/libs/clangsupport/set_algorithm.h b/src/libs/utils/set_algorithm.h similarity index 98% rename from src/libs/clangsupport/set_algorithm.h rename to src/libs/utils/set_algorithm.h index 6a17fe6f458..42a21f3f2d7 100644 --- a/src/libs/clangsupport/set_algorithm.h +++ b/src/libs/utils/set_algorithm.h @@ -27,7 +27,7 @@ #include -namespace ClangBackEnd { +namespace Utils { template class function_output_iterator @@ -116,4 +116,5 @@ Value mismatch_collect(InputIt1 first1, return value; } -} // namespace ClangBackEnd + +} // namespace Utils diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 4eeb496c8f3..e4e8be6a65f 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -298,7 +298,8 @@ HEADERS += \ $$PWD/porting.h \ $$PWD/aspects.h \ $$PWD/layoutbuilder.h \ - $$PWD/variablechooser.h + $$PWD/variablechooser.h \ + $$PWD/set_algorithm.h FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 0436fe51a6a..fb6c64b4c6e 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -236,7 +236,8 @@ Project { "savedaction.h", "savefile.cpp", "savefile.h", - "scopedswap.h", + "scopedswap.h" + "set_algorithm.h", "settingsaccessor.cpp", "settingsaccessor.h", "settingsselector.cpp", diff --git a/src/tools/clangpchmanagerbackend/source/projectpartsmanager.cpp b/src/tools/clangpchmanagerbackend/source/projectpartsmanager.cpp index 307041ed2ea..48074f440cc 100644 --- a/src/tools/clangpchmanagerbackend/source/projectpartsmanager.cpp +++ b/src/tools/clangpchmanagerbackend/source/projectpartsmanager.cpp @@ -31,9 +31,10 @@ #include #include #include -#include #include +#include + #include #include @@ -163,7 +164,7 @@ ProjectPartsManagerInterface::UpToDataProjectParts ProjectPartsManager::checkDep newSources.end(), oldSources.begin(), oldSources.end(), - make_iterator([&](SourceEntry entry) { + Utils::make_iterator([&](SourceEntry entry) { change = changedSourceType(entry, change); }), [](SourceEntry first, SourceEntry second) { @@ -185,7 +186,7 @@ ProjectPartsManagerInterface::UpToDataProjectParts ProjectPartsManager::checkDep } if (change == Change::No) { - Change change = mismatch_collect( + Change change = Utils::mismatch_collect( newSources.begin(), newSources.end(), oldSources.begin(),