aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/clangsupport
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2018-11-06 19:02:00 +0100
committerMarco Bubke <marco.bubke@qt.io>2018-11-08 12:51:15 +0000
commit6eb620238b31af81bb097260afb53bcac1054221 (patch)
tree7c4842e2e8a3d0630a72da993d45344f677b1288 /src/libs/clangsupport
parentd37ec2c1e511df19f48b4a621270df3e7135a731 (diff)
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 <ivan.donchevskii@qt.io>
Diffstat (limited to 'src/libs/clangsupport')
-rw-r--r--src/libs/clangsupport/filepathcache.h22
-rw-r--r--src/libs/clangsupport/filepathid.cpp2
-rw-r--r--src/libs/clangsupport/filepathid.h17
-rw-r--r--src/libs/clangsupport/filepathstorage.h8
-rw-r--r--src/libs/clangsupport/filepathstoragesources.h11
-rw-r--r--src/libs/clangsupport/filepathstoragesqlitestatementfactory.h4
6 files changed, 34 insertions, 30 deletions
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<ClangBackEnd::FilePathId>
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<long long>{}(hash);
+ return std::hash<int>{}(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<int>(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<Utils::SmallString>(sourceId);
+ auto optionalSourceName = statement.template value<Sources::SourceNameAndDirectoryId, 2>(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{