From 6eb620238b31af81bb097260afb53bcac1054221 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 6 Nov 2018 19:02:00 +0100 Subject: Clang: Refactor FilePathId We don't need the directory id any more. It's not used widely any way. Task-number: QTCREATORBUG-21443 Change-Id: Ia95ea4c72fe9530ac56262f61f17faca04d313ba Reviewed-by: Ivan Donchevskii --- src/libs/clangsupport/filepathcache.h | 22 +++++++++++----------- src/libs/clangsupport/filepathid.cpp | 2 +- src/libs/clangsupport/filepathid.h | 17 +++++------------ src/libs/clangsupport/filepathstorage.h | 8 ++++---- src/libs/clangsupport/filepathstoragesources.h | 11 +++++++++++ .../filepathstoragesqlitestatementfactory.h | 4 ++-- 6 files changed, 34 insertions(+), 30 deletions(-) (limited to 'src/libs') diff --git a/src/libs/clangsupport/filepathcache.h b/src/libs/clangsupport/filepathcache.h index d0c8a529dff..bdd925a79c8 100644 --- a/src/libs/clangsupport/filepathcache.h +++ b/src/libs/clangsupport/filepathcache.h @@ -133,7 +133,7 @@ public: return m_filePathStorage.fetchSourceId(directoryId, fileName); }); - return {directoryId, fileNameId}; + return fileNameId; } FilePath filePath(FilePathId filePathId) const @@ -141,20 +141,20 @@ public: if (Q_UNLIKELY(!filePathId.isValid())) throw NoFilePathForInvalidFilePathId(); - auto fetchFilePath = [&] (int id) { return m_filePathStorage.fetchDirectoryPath(id); }; - - Utils::PathString directoryPath = m_directoryPathCache.string(filePathId.directoryId, - fetchFilePath); + auto fetchSoureNameAndDirectoryId = [&] (int id) { + auto entry = m_filePathStorage.fetchSourceNameAndDirectoryId(id); + return FileNameEntry{entry.sourceName, entry.directoryId}; + }; + FileNameEntry entry = m_fileNameCache.string(filePathId.filePathId, + fetchSoureNameAndDirectoryId); - auto fetchSoureName = [&] (int id) { - return FileNameEntry{m_filePathStorage.fetchSourceName(id), filePathId.directoryId}; - }; + auto fetchDirectoryPath = [&] (int id) { return m_filePathStorage.fetchDirectoryPath(id); }; - Utils::SmallString fileName = m_fileNameCache.string(filePathId.filePathId, - fetchSoureName); + Utils::PathString directoryPath = m_directoryPathCache.string(entry.directoryId, + fetchDirectoryPath); - return FilePath{directoryPath, fileName}; + return FilePath{directoryPath, entry.fileName}; } private: diff --git a/src/libs/clangsupport/filepathid.cpp b/src/libs/clangsupport/filepathid.cpp index 7d059e0ea27..2491bc02d07 100644 --- a/src/libs/clangsupport/filepathid.cpp +++ b/src/libs/clangsupport/filepathid.cpp @@ -31,7 +31,7 @@ namespace ClangBackEnd { QDebug operator<<(QDebug debug, const FilePathId &filePathId) { - debug.nospace() << "(" << filePathId.directoryId << ", " << filePathId.filePathId << ")"; + debug.nospace() << "(" << filePathId.filePathId << ")"; return debug; } diff --git a/src/libs/clangsupport/filepathid.h b/src/libs/clangsupport/filepathid.h index 38762bd44bf..88426d93fcb 100644 --- a/src/libs/clangsupport/filepathid.h +++ b/src/libs/clangsupport/filepathid.h @@ -39,14 +39,14 @@ class FilePathId { public: constexpr FilePathId() = default; - FilePathId(int directoryId, int filePathId) - : directoryId(directoryId), - filePathId(filePathId) + + FilePathId(int filePathId) + : filePathId(filePathId) {} bool isValid() const { - return directoryId >= 0 && filePathId >= 0; + return filePathId >= 0; } friend bool operator==(FilePathId first, FilePathId second) @@ -66,7 +66,6 @@ public: friend QDataStream &operator<<(QDataStream &out, const FilePathId &filePathId) { - out << filePathId.directoryId; out << filePathId.filePathId; return out; @@ -74,14 +73,12 @@ public: friend QDataStream &operator>>(QDataStream &in, FilePathId &filePathId) { - in >> filePathId.directoryId; in >> filePathId.filePathId; return in; } public: - int directoryId = -1; int filePathId = -1; }; @@ -97,11 +94,7 @@ template<> struct hash using result_type = std::size_t; result_type operator()(const argument_type& filePathId) const { - long long hash = filePathId.directoryId; - hash = hash << 32; - hash += filePathId.filePathId; - - return std::hash{}(hash); + return std::hash{}(filePathId.filePathId); } }; diff --git a/src/libs/clangsupport/filepathstorage.h b/src/libs/clangsupport/filepathstorage.h index 69388a45d24..5917504dbf3 100644 --- a/src/libs/clangsupport/filepathstorage.h +++ b/src/libs/clangsupport/filepathstorage.h @@ -165,14 +165,14 @@ public: return statement.template value(directoryId, sourceName); } - Utils::SmallString fetchSourceName(int sourceId) + Sources::SourceNameAndDirectoryId fetchSourceNameAndDirectoryId(int sourceId) { try { Sqlite::DeferredTransaction transaction{m_statementFactory.database}; - ReadStatement &statement = m_statementFactory.selectSourceNameFromSourcesBySourceId; + ReadStatement &statement = m_statementFactory.selectSourceNameAndDirectoryIdFromSourcesBySourceId; - auto optionalSourceName = statement.template value(sourceId); + auto optionalSourceName = statement.template value(sourceId); if (!optionalSourceName) throw SourceNameIdDoesNotExists(); @@ -181,7 +181,7 @@ public: return optionalSourceName.value(); } catch (const Sqlite::StatementIsBusy &) { - return fetchSourceName(sourceId); + return fetchSourceNameAndDirectoryId(sourceId); } } diff --git a/src/libs/clangsupport/filepathstoragesources.h b/src/libs/clangsupport/filepathstoragesources.h index 7561aca908e..e76cb3b2cf6 100644 --- a/src/libs/clangsupport/filepathstoragesources.h +++ b/src/libs/clangsupport/filepathstoragesources.h @@ -69,6 +69,17 @@ public: int sourceId; Utils::PathString sourceName; }; + +class SourceNameAndDirectoryId +{ +public: + SourceNameAndDirectoryId(Utils::SmallStringView sourceName, int directoryId) + : sourceName(sourceName), directoryId(directoryId) + {} + + Utils::SmallString sourceName; + int directoryId = -1; +}; } // namespace ClangBackEnd } // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathstoragesqlitestatementfactory.h b/src/libs/clangsupport/filepathstoragesqlitestatementfactory.h index 71e2c3e7734..dbf80717753 100644 --- a/src/libs/clangsupport/filepathstoragesqlitestatementfactory.h +++ b/src/libs/clangsupport/filepathstoragesqlitestatementfactory.h @@ -65,8 +65,8 @@ public: "SELECT sourceId FROM sources WHERE directoryId = ? AND sourceName = ?", database }; - ReadStatement selectSourceNameFromSourcesBySourceId{ - "SELECT sourceName FROM sources WHERE sourceId = ?", + ReadStatement selectSourceNameAndDirectoryIdFromSourcesBySourceId{ + "SELECT sourceName, directoryId FROM sources WHERE sourceId = ?", database }; WriteStatement insertIntoSources{ -- cgit v1.2.3 From 9b1e7e440a217f70d2cbd6df3582efcfc3e4d341 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 7 Nov 2018 17:48:25 +0100 Subject: Clang: Add BuildDependenciesStorage Task-number: QTCREATORBUG-21378 Change-Id: Ibcb90239d240653b21f12a7b96a7775e5b0b4319 Reviewed-by: Ivan Donchevskii --- src/libs/clangsupport/refactoringdatabaseinitializer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libs') diff --git a/src/libs/clangsupport/refactoringdatabaseinitializer.h b/src/libs/clangsupport/refactoringdatabaseinitializer.h index 0b212c3a58a..653397b3175 100644 --- a/src/libs/clangsupport/refactoringdatabaseinitializer.h +++ b/src/libs/clangsupport/refactoringdatabaseinitializer.h @@ -95,7 +95,6 @@ public: table.addColumn("sourceId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey); const Sqlite::Column &directoryIdColumn = table.addColumn("directoryId", Sqlite::ColumnType::Integer); const Sqlite::Column &sourceNameColumn = table.addColumn("sourceName", Sqlite::ColumnType::Text); - table.addColumn("sourceType", Sqlite::ColumnType::Integer); table.addUniqueIndex({directoryIdColumn, sourceNameColumn}); table.initialize(database); @@ -135,6 +134,7 @@ public: table.setName("projectPartsSources"); const Sqlite::Column &projectPartIdColumn = table.addColumn("projectPartId", Sqlite::ColumnType::Integer); const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); + table.addColumn("sourceType", Sqlite::ColumnType::Integer); table.addUniqueIndex({sourceIdColumn, projectPartIdColumn}); table.addIndex({projectPartIdColumn}); @@ -163,6 +163,7 @@ public: table.addColumn("sourceId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey); table.addColumn("size", Sqlite::ColumnType::Integer); table.addColumn("lastModified", Sqlite::ColumnType::Integer); + table.addColumn("buildDependencyTimeStamp", Sqlite::ColumnType::Integer); table.addColumn("isInPrecompiledHeader", Sqlite::ColumnType::Integer); table.initialize(database); } -- cgit v1.2.3