Commit f49a1d72 authored by Marco Bubke's avatar Marco Bubke

Clang: Add symbol storage

Extend file path cache to 64 bit integer.

Change-Id: I5627f13d59a3214f389087038482cbcc8d0eb484
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 81d43b8a
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#pragma once #pragma once
#include "stringcachefwd.h"
#include <utils/smallstringview.h> #include <utils/smallstringview.h>
#include <utils/smallstringfwd.h> #include <utils/smallstringfwd.h>
...@@ -52,11 +54,11 @@ public: ...@@ -52,11 +54,11 @@ public:
void unlock() {} void unlock() {}
}; };
template <typename StringType> template <typename StringType, typename IndexType>
class StringCacheEntry class StringCacheEntry
{ {
public: public:
StringCacheEntry(StringType &&string, uint id) StringCacheEntry(StringType &&string, IndexType id)
: string(std::move(string)), : string(std::move(string)),
id(id) id(id)
{} {}
...@@ -77,22 +79,27 @@ public: ...@@ -77,22 +79,27 @@ public:
} }
StringType string; StringType string;
uint id; IndexType id;
}; };
template <typename StringType> template <typename StringType, typename IndexType>
using StringCacheEntries = std::vector<StringCacheEntry<StringType>>; using StringCacheEntries = std::vector<StringCacheEntry<StringType, IndexType>>;
using FileCacheCacheEntry = StringCacheEntry<Utils::PathString, FilePathIndex>;
using FileCacheCacheEntries = std::vector<FileCacheCacheEntry>;
template <typename StringType, template <typename StringType,
typename Mutex = NonLockingMutex> typename IndexType,
typename Mutex>
class StringCache class StringCache
{ {
using const_iterator = typename StringCacheEntries<StringType>::const_iterator; using CacheEnties = StringCacheEntries<StringType, IndexType>;
using const_iterator = typename CacheEnties::const_iterator;
class Found class Found
{ {
public: public:
typename StringCacheEntries<StringType>::const_iterator iterator; typename CacheEnties::const_iterator iterator;
bool wasFound; bool wasFound;
}; };
...@@ -103,14 +110,14 @@ public: ...@@ -103,14 +110,14 @@ public:
m_indices.reserve(1024); m_indices.reserve(1024);
} }
void populate(StringCacheEntries<StringType> &&entries) void populate(CacheEnties &&entries)
{ {
uncheckedPopulate(std::move(entries)); uncheckedPopulate(std::move(entries));
checkEntries(); checkEntries();
} }
void uncheckedPopulate(StringCacheEntries<StringType> &&entries) void uncheckedPopulate(CacheEnties &&entries)
{ {
std::sort(entries.begin(), entries.end()); std::sort(entries.begin(), entries.end());
...@@ -123,7 +130,7 @@ public: ...@@ -123,7 +130,7 @@ public:
} }
uint stringId(Utils::SmallStringView stringView) IndexType stringId(Utils::SmallStringView stringView)
{ {
std::lock_guard<Mutex> lock(m_mutex); std::lock_guard<Mutex> lock(m_mutex);
...@@ -136,11 +143,11 @@ public: ...@@ -136,11 +143,11 @@ public:
} }
template <typename Container> template <typename Container>
std::vector<uint> stringIds(const Container &strings) std::vector<IndexType> stringIds(const Container &strings)
{ {
std::lock_guard<Mutex> lock(m_mutex); std::lock_guard<Mutex> lock(m_mutex);
std::vector<uint> ids; std::vector<IndexType> ids;
ids.reserve(strings.size()); ids.reserve(strings.size());
std::transform(strings.begin(), std::transform(strings.begin(),
...@@ -151,19 +158,19 @@ public: ...@@ -151,19 +158,19 @@ public:
return ids; return ids;
} }
std::vector<uint> stringIds(std::initializer_list<StringType> strings) std::vector<IndexType> stringIds(std::initializer_list<StringType> strings)
{ {
return stringIds<std::initializer_list<StringType>>(strings); return stringIds<std::initializer_list<StringType>>(strings);
} }
Utils::SmallStringView string(uint id) const Utils::SmallStringView string(IndexType id) const
{ {
std::lock_guard<Mutex> lock(m_mutex); std::lock_guard<Mutex> lock(m_mutex);
return m_strings.at(m_indices.at(id)).string; return m_strings.at(m_indices.at(id)).string;
} }
std::vector<StringType> strings(const std::vector<uint> &ids) const std::vector<StringType> strings(const std::vector<IndexType> &ids) const
{ {
std::lock_guard<Mutex> lock(m_mutex); std::lock_guard<Mutex> lock(m_mutex);
...@@ -173,7 +180,7 @@ public: ...@@ -173,7 +180,7 @@ public:
std::transform(ids.begin(), std::transform(ids.begin(),
ids.end(), ids.end(),
std::back_inserter(strings), std::back_inserter(strings),
[&] (uint id) { return m_strings.at(m_indices.at(id)).string; }); [&] (IndexType id) { return m_strings.at(m_indices.at(id)).string; });
return strings; return strings;
} }
...@@ -191,24 +198,24 @@ private: ...@@ -191,24 +198,24 @@ private:
return {range.first, range.first != range.second}; return {range.first, range.first != range.second};
} }
void incrementLargerOrEqualIndicesByOne(uint newIndex) void incrementLargerOrEqualIndicesByOne(IndexType newIndex)
{ {
std::transform(m_indices.begin(), std::transform(m_indices.begin(),
m_indices.end(), m_indices.end(),
m_indices.begin(), m_indices.begin(),
[&] (uint index) { [&] (IndexType index) {
return index >= newIndex ? ++index : index; return index >= newIndex ? ++index : index;
}); });
} }
uint insertString(const_iterator beforeIterator, IndexType insertString(const_iterator beforeIterator,
Utils::SmallStringView stringView) Utils::SmallStringView stringView)
{ {
auto id = uint(m_indices.size()); auto id = IndexType(m_indices.size());
auto inserted = m_strings.emplace(beforeIterator, StringType(stringView), id); auto inserted = m_strings.emplace(beforeIterator, StringType(stringView), id);
auto newIndex = uint(std::distance(m_strings.begin(), inserted)); auto newIndex = IndexType(std::distance(m_strings.begin(), inserted));
incrementLargerOrEqualIndicesByOne(newIndex); incrementLargerOrEqualIndicesByOne(newIndex);
...@@ -226,12 +233,13 @@ private: ...@@ -226,12 +233,13 @@ private:
} }
private: private:
StringCacheEntries<StringType> m_strings; CacheEnties m_strings;
std::vector<uint> m_indices; std::vector<IndexType> m_indices;
mutable Mutex m_mutex; mutable Mutex m_mutex;
}; };
template <typename Mutex = NonLockingMutex> template <typename Mutex>
using FilePathCache = StringCache<Utils::PathString, Mutex>; using FilePathCache = StringCache<Utils::PathString, FilePathIndex, Mutex>;
using FilePathIndices = std::vector<FilePathIndex>;
} // namespace ClangBackEnd } // namespace ClangBackEnd
...@@ -29,14 +29,17 @@ ...@@ -29,14 +29,17 @@
namespace ClangBackEnd { namespace ClangBackEnd {
using FilePathIndex = long long int;
class NonLockingMutex; class NonLockingMutex;
template <typename StringType, template <typename StringType,
typename IndexType,
typename Mutex> typename Mutex>
class StringCache; class StringCache;
template <typename Mutex = NonLockingMutex> template <typename Mutex = NonLockingMutex>
using FilePathCache = StringCache<Utils::PathString, Mutex>; using FilePathCache = StringCache<Utils::PathString, FilePathIndex, Mutex>;
} // namespace ClangBackEnd } // namespace ClangBackEnd
...@@ -83,27 +83,27 @@ protected: ...@@ -83,27 +83,27 @@ protected:
{ {
} }
template<typename... Values> template<typename... ValueType>
void bindValues(Values... values) void bindValues(ValueType... values)
{ {
bindValuesByIndex(1, values...); bindValuesByIndex(1, values...);
} }
template<typename... Values> template<typename... ValueType>
void write(Values... values) void write(ValueType... values)
{ {
bindValuesByIndex(1, values...); bindValuesByIndex(1, values...);
execute(); execute();
} }
template<typename... Values> template<typename... ValueType>
void bindNameValues(Values... values) void bindNameValues(ValueType... values)
{ {
bindValuesByName(values...); bindValuesByName(values...);
} }
template<typename... Values> template<typename... ValueType>
void writeNamed(Values... values) void writeNamed(ValueType... values)
{ {
bindValuesByName(values...); bindValuesByName(values...);
execute(); execute();
...@@ -117,45 +117,45 @@ protected: ...@@ -117,45 +117,45 @@ protected:
void setBindingColumnNames(const Utils::SmallStringVector &bindingColumnNames); void setBindingColumnNames(const Utils::SmallStringVector &bindingColumnNames);
const Utils::SmallStringVector &bindingColumnNames() const; const Utils::SmallStringVector &bindingColumnNames() const;
template <typename... ResultType> template <typename... ResultTypes>
std::vector<std::tuple<ResultType...>> tupleValues(std::size_t reserveSize) std::vector<std::tuple<ResultTypes...>> tupleValues(std::size_t reserveSize)
{ {
using Container = std::vector<std::tuple<ResultType...>>; using Container = std::vector<std::tuple<ResultTypes...>>;
Container resultValues; Container resultValues;
resultValues.reserve(reserveSize); resultValues.reserve(reserveSize);
while (next()) while (next())
emplaceTupleValues<Container, ResultType...>(resultValues); emplaceTupleValues<Container, ResultTypes...>(resultValues);
reset(); reset();
return resultValues; return resultValues;
} }
template <typename... ResultType, template <typename... ResultTypes,
typename... QueryType> typename... QueryTypes>
std::vector<std::tuple<ResultType...>> tupleValues(std::size_t reserveSize, const QueryType&... queryValues) std::vector<std::tuple<ResultTypes...>> tupleValues(std::size_t reserveSize, const QueryTypes&... queryValues)
{ {
using Container = std::vector<std::tuple<ResultType...>>; using Container = std::vector<std::tuple<ResultTypes...>>;
Container resultValues; Container resultValues;
resultValues.reserve(reserveSize); resultValues.reserve(reserveSize);
bindValues(queryValues...); bindValues(queryValues...);
while (next()) while (next())
emplaceTupleValues<Container, ResultType...>(resultValues); emplaceTupleValues<Container, ResultTypes...>(resultValues);
reset(); reset();
return resultValues; return resultValues;
} }
template <typename... ResultType, template <typename... ResultTypes,
typename... ElementType> typename... QueryElementTypes>
std::vector<std::tuple<ResultType...>> tupleValues(std::size_t reserveSize, std::vector<std::tuple<ResultTypes...>> tupleValues(std::size_t reserveSize,
const std::vector<std::tuple<ElementType...>> &queryTuples) const std::vector<std::tuple<QueryElementTypes...>> &queryTuples)
{ {
using Container = std::vector<std::tuple<ResultType...>>; using Container = std::vector<std::tuple<ResultTypes...>>;
Container resultValues; Container resultValues;
resultValues.reserve(reserveSize); resultValues.reserve(reserveSize);
...@@ -163,7 +163,7 @@ protected: ...@@ -163,7 +163,7 @@ protected:
bindTupleValues(queryTuple); bindTupleValues(queryTuple);
while (next()) while (next())
emplaceTupleValues<Container, ResultType...>(resultValues); emplaceTupleValues<Container, ResultTypes...>(resultValues);
reset(); reset();
} }
...@@ -171,12 +171,12 @@ protected: ...@@ -171,12 +171,12 @@ protected:
return resultValues; return resultValues;
} }
template <typename... ResultType, template <typename... ResultTypes,
typename QueryElementType> typename QueryElementType>
std::vector<std::tuple<ResultType...>> tupleValues(std::size_t reserveSize, std::vector<std::tuple<ResultTypes...>> tupleValues(std::size_t reserveSize,
const std::vector<QueryElementType> &queryValues) const std::vector<QueryElementType> &queryValues)
{ {
using Container = std::vector<std::tuple<ResultType...>>; using Container = std::vector<std::tuple<ResultTypes...>>;
Container resultValues; Container resultValues;
resultValues.reserve(reserveSize); resultValues.reserve(reserveSize);
...@@ -184,7 +184,7 @@ protected: ...@@ -184,7 +184,7 @@ protected:
bindValues(queryValue); bindValues(queryValue);
while (next()) while (next())
emplaceTupleValues<Container, ResultType...>(resultValues); emplaceTupleValues<Container, ResultTypes...>(resultValues);
reset(); reset();
} }
...@@ -193,7 +193,7 @@ protected: ...@@ -193,7 +193,7 @@ protected:
} }
template <typename ResultType, template <typename ResultType,
typename... ResultEntryType> typename... ResultEntryTypes>
std::vector<ResultType> structValues(std::size_t reserveSize) std::vector<ResultType> structValues(std::size_t reserveSize)
{ {
using Container = std::vector<ResultType>; using Container = std::vector<ResultType>;
...@@ -201,7 +201,7 @@ protected: ...@@ -201,7 +201,7 @@ protected:
resultValues.reserve(reserveSize); resultValues.reserve(reserveSize);
while (next()) while (next())
pushBackStructValues<Container, ResultEntryType...>(resultValues); pushBackStructValues<Container, ResultEntryTypes...>(resultValues);
reset(); reset();
...@@ -209,9 +209,9 @@ protected: ...@@ -209,9 +209,9 @@ protected:
} }
template <typename ResultType, template <typename ResultType,
typename... ResultEntryType, typename... ResultEntryTypes,
typename... QueryType> typename... QueryTypes>
std::vector<ResultType> structValues(std::size_t reserveSize, const QueryType&... queryValues) std::vector<ResultType> structValues(std::size_t reserveSize, const QueryTypes&... queryValues)
{ {
using Container = std::vector<ResultType>; using Container = std::vector<ResultType>;
Container resultValues; Container resultValues;
...@@ -220,7 +220,7 @@ protected: ...@@ -220,7 +220,7 @@ protected:
bindValues(queryValues...); bindValues(queryValues...);
while (next()) while (next())
pushBackStructValues<Container, ResultEntryType...>(resultValues); pushBackStructValues<Container, ResultEntryTypes...>(resultValues);
reset(); reset();
...@@ -228,7 +228,7 @@ protected: ...@@ -228,7 +228,7 @@ protected:
} }
template <typename ResultType, template <typename ResultType,
typename... ResultEntryType, typename... ResultEntryTypes,
typename QueryElementType> typename QueryElementType>
std::vector<ResultType> structValues(std::size_t reserveSize, std::vector<ResultType> structValues(std::size_t reserveSize,
const std::vector<QueryElementType> &queryValues) const std::vector<QueryElementType> &queryValues)
...@@ -241,7 +241,7 @@ protected: ...@@ -241,7 +241,7 @@ protected:
bindValues(queryValue); bindValues(queryValue);
while (next()) while (next())
pushBackStructValues<Container, ResultEntryType...>(resultValues); pushBackStructValues<Container, ResultEntryTypes...>(resultValues);
reset(); reset();
} }
...@@ -250,10 +250,10 @@ protected: ...@@ -250,10 +250,10 @@ protected:
} }
template <typename ResultType, template <typename ResultType,
typename... ResultEntryType, typename... ResultEntryTypes,
typename... QueryElementType> typename... QueryElementTypes>
std::vector<ResultType> structValues(std::size_t reserveSize, std::vector<ResultType> structValues(std::size_t reserveSize,
const std::vector<std::tuple<QueryElementType...>> &queryTuples) const std::vector<std::tuple<QueryElementTypes...>> &queryTuples)
{ {
using Container = std::vector<ResultType>; using Container = std::vector<ResultType>;
Container resultValues; Container resultValues;
...@@ -263,7 +263,7 @@ protected: ...@@ -263,7 +263,7 @@ protected:
bindTupleValues(queryTuple); bindTupleValues(queryTuple);
while (next()) while (next())
pushBackStructValues<Container, ResultEntryType...>(resultValues); pushBackStructValues<Container, ResultEntryTypes...>(resultValues);
reset(); reset();
} }
...@@ -272,7 +272,7 @@ protected: ...@@ -272,7 +272,7 @@ protected:
} }
template <typename ResultType, template <typename ResultType,
typename... ElementType> typename... ElementTypes>
std::vector<ResultType> values(std::size_t reserveSize) std::vector<ResultType> values(std::size_t reserveSize)
{ {
std::vector<ResultType> resultValues; std::vector<ResultType> resultValues;
...@@ -327,8 +327,8 @@ protected: ...@@ -327,8 +327,8 @@ protected:
}