From f9fb4508d4b73b59b7a7a3c74c009cdccb24d21c Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 6 Aug 2019 13:12:03 +0200 Subject: 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 --- src/libs/clangsupport/filepathcache.h | 81 ++++++++--------------------------- 1 file changed, 17 insertions(+), 64 deletions(-) (limited to 'src/libs/clangsupport/filepathcache.h') 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 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::reverseCompare, + Sources::Directory>; using FileNameCache = StringCache; + 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 { -- cgit v1.2.1