diff options
author | Marco Bubke <marco.bubke@qt.io> | 2019-08-06 13:12:03 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2019-08-27 11:51:28 +0000 |
commit | f9fb4508d4b73b59b7a7a3c74c009cdccb24d21c (patch) | |
tree | e4ebcfda4cd6a0021ff7730187310a460057db8e /src/libs/clangsupport/filepathcache.h | |
parent | 912b4763e00437d32759ba948e9bc678ff53b6be (diff) | |
download | qt-creator-f9fb4508d4b73b59b7a7a3c74c009cdccb24d21c.tar.gz |
Clang: Optimize file path cache
We now fetch all directories and sources from the database at file
path cache creation.
Change-Id: I92510b49a234128f4c82b840611db82ead3f1a54
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/libs/clangsupport/filepathcache.h')
-rw-r--r-- | src/libs/clangsupport/filepathcache.h | 81 |
1 files changed, 17 insertions, 64 deletions
diff --git a/src/libs/clangsupport/filepathcache.h b/src/libs/clangsupport/filepathcache.h index 4845416d22..1771f5b6c3 100644 --- a/src/libs/clangsupport/filepathcache.h +++ b/src/libs/clangsupport/filepathcache.h @@ -29,6 +29,7 @@ #include "filepath.h" #include "filepathexceptions.h" #include "filepathid.h" +#include "filepathstoragesources.h" #include "filepathview.h" #include "stringcache.h" @@ -39,84 +40,36 @@ namespace ClangBackEnd { template <typename FilePathStorage> class CLANGSUPPORT_GCCEXPORT FilePathCache { - class FileNameView - { - public: - friend bool operator==(const FileNameView &first, const FileNameView &second) - { - return first.directoryId == second.directoryId - && first.fileName == second.fileName; - } - - static - int compare(FileNameView first, FileNameView second) noexcept - { - int directoryDifference = first.directoryId - second.directoryId; - - if (directoryDifference) - return directoryDifference; - - return Utils::compare(first.fileName, second.fileName); - } - - public: - Utils::SmallStringView fileName; - int directoryId; - }; - - class FileNameEntry - { - public: - FileNameEntry(Utils::SmallStringView fileName, int directoryId) - : fileName(fileName), - directoryId(directoryId) - {} - - FileNameEntry(FileNameView view) - : fileName(view.fileName), - directoryId(view.directoryId) - {} - - friend bool operator==(const FileNameEntry &first, const FileNameEntry &second) - { - return first.directoryId == second.directoryId - && first.fileName == second.fileName; - } - - operator FileNameView() const - { - return {fileName, directoryId}; - } - - operator Utils::SmallString() && - { - return std::move(fileName); - } - - public: - Utils::SmallString fileName; - int directoryId; - }; - using DirectoryPathCache = StringCache<Utils::PathString, Utils::SmallStringView, int, SharedMutex, decltype(&Utils::reverseCompare), - Utils::reverseCompare>; + Utils::reverseCompare, + Sources::Directory>; using FileNameCache = StringCache<FileNameEntry, FileNameView, int, SharedMutex, decltype(&FileNameView::compare), - FileNameView::compare>; + FileNameView::compare, + Sources::Source>; + + FilePathCache(const FilePathCache &) = default; + FilePathCache &operator=(const FilePathCache &) = default; + public: FilePathCache(FilePathStorage &filePathStorage) : m_filePathStorage(filePathStorage) - {} + { + m_directoryPathCache.populate(filePathStorage.fetchAllDirectories()); + m_fileNameCache.populate(filePathStorage.fetchAllSources()); + } + + FilePathCache(FilePathCache &&) = default; + FilePathCache &operator=(FilePathCache &&) = default; - FilePathCache(const FilePathCache &) = delete; - FilePathCache &operator=(const FilePathCache &) = delete; + FilePathCache clone() { return *this; } FilePathId filePathId(FilePathView filePath) const { |