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 @@
#pragma once
#include "stringcachefwd.h"
#include <utils/smallstringview.h>
#include <utils/smallstringfwd.h>
......@@ -52,11 +54,11 @@ public:
void unlock() {}
};
template <typename StringType>
template <typename StringType, typename IndexType>
class StringCacheEntry
{
public:
StringCacheEntry(StringType &&string, uint id)
StringCacheEntry(StringType &&string, IndexType id)
: string(std::move(string)),
id(id)
{}
......@@ -77,22 +79,27 @@ public:
}
StringType string;
uint id;
IndexType id;
};
template <typename StringType>
using StringCacheEntries = std::vector<StringCacheEntry<StringType>>;
template <typename StringType, typename IndexType>
using StringCacheEntries = std::vector<StringCacheEntry<StringType, IndexType>>;
using FileCacheCacheEntry = StringCacheEntry<Utils::PathString, FilePathIndex>;
using FileCacheCacheEntries = std::vector<FileCacheCacheEntry>;
template <typename StringType,
typename Mutex = NonLockingMutex>
typename IndexType,
typename Mutex>
class StringCache
{
using const_iterator = typename StringCacheEntries<StringType>::const_iterator;
using CacheEnties = StringCacheEntries<StringType, IndexType>;
using const_iterator = typename CacheEnties::const_iterator;
class Found
{
public:
typename StringCacheEntries<StringType>::const_iterator iterator;
typename CacheEnties::const_iterator iterator;
bool wasFound;
};
......@@ -103,14 +110,14 @@ public:
m_indices.reserve(1024);
}
void populate(StringCacheEntries<StringType> &&entries)
void populate(CacheEnties &&entries)
{
uncheckedPopulate(std::move(entries));
checkEntries();
}
void uncheckedPopulate(StringCacheEntries<StringType> &&entries)
void uncheckedPopulate(CacheEnties &&entries)
{
std::sort(entries.begin(), entries.end());
......@@ -123,7 +130,7 @@ public:
}
uint stringId(Utils::SmallStringView stringView)
IndexType stringId(Utils::SmallStringView stringView)
{
std::lock_guard<Mutex> lock(m_mutex);
......@@ -136,11 +143,11 @@ public:
}
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::vector<uint> ids;
std::vector<IndexType> ids;
ids.reserve(strings.size());
std::transform(strings.begin(),
......@@ -151,19 +158,19 @@ public:
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);
}
Utils::SmallStringView string(uint id) const
Utils::SmallStringView string(IndexType id) const
{
std::lock_guard<Mutex> lock(m_mutex);
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);
......@@ -173,7 +180,7 @@ public:
std::transform(ids.begin(),
ids.end(),
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;
}
......@@ -191,24 +198,24 @@ private:
return {range.first, range.first != range.second};
}
void incrementLargerOrEqualIndicesByOne(uint newIndex)
void incrementLargerOrEqualIndicesByOne(IndexType newIndex)
{
std::transform(m_indices.begin(),
m_indices.end(),
m_indices.begin(),
[&] (uint index) {
[&] (IndexType index) {
return index >= newIndex ? ++index : index;
});
}
uint insertString(const_iterator beforeIterator,
IndexType insertString(const_iterator beforeIterator,
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 newIndex = uint(std::distance(m_strings.begin(), inserted));
auto newIndex = IndexType(std::distance(m_strings.begin(), inserted));
incrementLargerOrEqualIndicesByOne(newIndex);
......@@ -226,12 +233,13 @@ private:
}
private:
StringCacheEntries<StringType> m_strings;
std::vector<uint> m_indices;
CacheEnties m_strings;
std::vector<IndexType> m_indices;
mutable Mutex m_mutex;
};
template <typename Mutex = NonLockingMutex>
using FilePathCache = StringCache<Utils::PathString, Mutex>;
template <typename Mutex>
using FilePathCache = StringCache<Utils::PathString, FilePathIndex, Mutex>;
using FilePathIndices = std::vector<FilePathIndex>;
} // namespace ClangBackEnd
......@@ -29,14 +29,17 @@
namespace ClangBackEnd {
using FilePathIndex = long long int;
class NonLockingMutex;
template <typename StringType,
typename IndexType,
typename Mutex>
class StringCache;
template <typename Mutex = NonLockingMutex>
using FilePathCache = StringCache<Utils::PathString, Mutex>;
using FilePathCache = StringCache<Utils::PathString, FilePathIndex, Mutex>;
} // namespace ClangBackEnd
......@@ -83,27 +83,27 @@ protected:
{
}
template<typename... Values>
void bindValues(Values... values)
template<typename... ValueType>
void bindValues(ValueType... values)
{
bindValuesByIndex(1, values...);
}
template<typename... Values>
void write(Values... values)
template<typename... ValueType>
void write(ValueType... values)
{
bindValuesByIndex(1, values...);
execute();
}
template<typename... Values>
void bindNameValues(Values... values)
template<typename... ValueType>
void bindNameValues(ValueType... values)
{
bindValuesByName(values...);
}
template<typename... Values>
void writeNamed(Values... values)
template<typename... ValueType>
void writeNamed(ValueType... values)
{
bindValuesByName(values...);
execute();
......@@ -117,45 +117,45 @@ protected:
void setBindingColumnNames(const Utils::SmallStringVector &bindingColumnNames);
const Utils::SmallStringVector &bindingColumnNames() const;
template <typename... ResultType>
std::vector<std::tuple<ResultType...>> tupleValues(std::size_t reserveSize)
template <typename... ResultTypes>
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;
resultValues.reserve(reserveSize);
while (next())
emplaceTupleValues<Container, ResultType...>(resultValues);
emplaceTupleValues<Container, ResultTypes...>(resultValues);
reset();
return resultValues;
}
template <typename... ResultType,
typename... QueryType>
std::vector<std::tuple<ResultType...>> tupleValues(std::size_t reserveSize, const QueryType&... queryValues)
template <typename... ResultTypes,
typename... QueryTypes>
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;
resultValues.reserve(reserveSize);
bindValues(queryValues...);
while (next())
emplaceTupleValues<Container, ResultType...>(resultValues);
emplaceTupleValues<Container, ResultTypes...>(resultValues);
reset();
return resultValues;
}
template <typename... ResultType,
typename... ElementType>
std::vector<std::tuple<ResultType...>> tupleValues(std::size_t reserveSize,
const std::vector<std::tuple<ElementType...>> &queryTuples)
template <typename... ResultTypes,
typename... QueryElementTypes>
std::vector<std::tuple<ResultTypes...>> tupleValues(std::size_t reserveSize,
const std::vector<std::tuple<QueryElementTypes...>> &queryTuples)
{
using Container = std::vector<std::tuple<ResultType...>>;
using Container = std::vector<std::tuple<ResultTypes...>>;
Container resultValues;
resultValues.reserve(reserveSize);
......@@ -163,7 +163,7 @@ protected:
bindTupleValues(queryTuple);
while (next())
emplaceTupleValues<Container, ResultType...>(resultValues);
emplaceTupleValues<Container, ResultTypes...>(resultValues);
reset();
}
......@@ -171,12 +171,12 @@ protected:
return resultValues;
}
template <typename... ResultType,
template <typename... ResultTypes,
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)
{
using Container = std::vector<std::tuple<ResultType...>>;
using Container = std::vector<std::tuple<ResultTypes...>>;
Container resultValues;
resultValues.reserve(reserveSize);
......@@ -184,7 +184,7 @@ protected:
bindValues(queryValue);
while (next())
emplaceTupleValues<Container, ResultType...>(resultValues);
emplaceTupleValues<Container, ResultTypes...>(resultValues);
reset();
}
......@@ -193,7 +193,7 @@ protected:
}
template <typename ResultType,
typename... ResultEntryType>
typename... ResultEntryTypes>
std::vector<ResultType> structValues(std::size_t reserveSize)
{
using Container = std::vector<ResultType>;
......@@ -201,7 +201,7 @@ protected:
resultValues.reserve(reserveSize);
while (next())
pushBackStructValues<Container, ResultEntryType...>(resultValues);
pushBackStructValues<Container, ResultEntryTypes...>(resultValues);
reset();
......@@ -209,9 +209,9 @@ protected:
}
template <typename ResultType,
typename... ResultEntryType,
typename... QueryType>
std::vector<ResultType> structValues(std::size_t reserveSize, const QueryType&... queryValues)
typename... ResultEntryTypes,
typename... QueryTypes>
std::vector<ResultType> structValues(std::size_t reserveSize, const QueryTypes&... queryValues)
{
using Container = std::vector<ResultType>;
Container resultValues;
......@@ -220,7 +220,7 @@ protected:
bindValues(queryValues...);
while (next())
pushBackStructValues<Container, ResultEntryType...>(resultValues);
pushBackStructValues<Container, ResultEntryTypes...>(resultValues);
reset();
......@@ -228,7 +228,7 @@ protected:
}
template <typename ResultType,
typename... ResultEntryType,
typename... ResultEntryTypes,
typename QueryElementType>
std::vector<ResultType> structValues(std::size_t reserveSize,
const std::vector<QueryElementType> &queryValues)
......@@ -241,7 +241,7 @@ protected:
bindValues(queryValue);
while (next())
pushBackStructValues<Container, ResultEntryType...>(resultValues);
pushBackStructValues<Container, ResultEntryTypes...>(resultValues);
reset();
}
......@@ -250,10 +250,10 @@ protected:
}
template <typename ResultType,
typename... ResultEntryType,
typename... QueryElementType>
typename... ResultEntryTypes,
typename... QueryElementTypes>
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>;
Container resultValues;
......@@ -263,7 +263,7 @@ protected:
bindTupleValues(queryTuple);
while (next())
pushBackStructValues<Container, ResultEntryType...>(resultValues);
pushBackStructValues<Container, ResultEntryTypes...>(resultValues);
reset();
}
......@@ -272,7 +272,7 @@ protected:
}
template <typename ResultType,
typename... ElementType>
typename... ElementTypes>
std::vector<ResultType> values(std::size_t reserveSize)
{
std::vector<ResultType> resultValues;
......@@ -327,8 +327,8 @@ protected:
}
template <typename ResultType,
typename... QueryType>
std::vector<ResultType> values(std::size_t reserveSize, const QueryType&... queryValues)
typename... QueryTypes>
std::vector<ResultType> values(std::size_t reserveSize, const QueryTypes&... queryValues)
{
std::vector<ResultType> resultValues;
resultValues.reserve(reserveSize);
......@@ -379,74 +379,74 @@ protected:
SqliteDatabaseBackend &databaseBackend);
private:
template <typename Container,
typename... ResultType,
int... Index>
void emplaceTupleValues(Container &container, std::integer_sequence<int, Index...>)
template <typename ContainerType,
typename... ResultTypes,
int... ColumnIndices>
void emplaceTupleValues(ContainerType &container, std::integer_sequence<int, ColumnIndices...>)
{
container.emplace_back(value<ResultType>(Index)...);
container.emplace_back(value<ResultTypes>(ColumnIndices)...);
}
template <typename Container,
typename... ResultType>
void emplaceTupleValues(Container &container)
template <typename ContainerType,
typename... ResultTypes>
void emplaceTupleValues(ContainerType &container)
{
emplaceTupleValues<Container, ResultType...>(container, std::make_integer_sequence<int, sizeof...(ResultType)>{});
emplaceTupleValues<ContainerType, ResultTypes...>(container, std::make_integer_sequence<int, sizeof...(ResultTypes)>{});
}
template <typename Container,
typename... ResultEntryType,
int... Index>
void pushBackStructValues(Container &container, std::integer_sequence<int, Index...>)
template <typename ContainerType,
typename... ResultEntryTypes,
int... ColumnIndices>
void pushBackStructValues(ContainerType &container, std::integer_sequence<int, ColumnIndices...>)
{
using ResultType = typename Container::value_type;
container.push_back(ResultType{value<ResultEntryType>(Index)...});
using ResultType = typename ContainerType::value_type;
container.push_back(ResultType{value<ResultEntryTypes>(ColumnIndices)...});
}
template <typename Container,
typename... ResultEntryType>
void pushBackStructValues(Container &container)
template <typename ContainerType,
typename... ResultEntryTypes>
void pushBackStructValues(ContainerType &container)
{
pushBackStructValues<Container, ResultEntryType...>(container, std::make_integer_sequence<int, sizeof...(ResultEntryType)>{});
pushBackStructValues<ContainerType, ResultEntryTypes...>(container, std::make_integer_sequence<int, sizeof...(ResultEntryTypes)>{});
}
template<typename Type>
void bindValuesByIndex(int index, Type value)
template<typename ValueType>
void bindValuesByIndex(int index, ValueType value)
{
bind(index, value);
}
template<typename Type, typename... Value>
void bindValuesByIndex(int index, Type value, Value... values)
template<typename ValueType, typename... ValueTypes>
void bindValuesByIndex(int index, ValueType value, ValueTypes... values)
{
bind(index, value);
bindValuesByIndex(index + 1, values...);
}
template<typename Type>
void bindValuesByName(Utils::SmallStringView name, Type value)
template<typename ValueType>
void bindValuesByName(Utils::SmallStringView name, ValueType value)
{
bind(bindingIndexForName(name), value);
}
template<typename Type, typename... Values>
void bindValuesByName(Utils::SmallStringView name, Type value, Values... values)
template<typename ValueType, typename... ValueTypes>
void bindValuesByName(Utils::SmallStringView name, ValueType value, ValueTypes... values)
{
bind(bindingIndexForName(name), value);
bindValuesByName(values...);
}
template <typename TupleType, std::size_t... Index>
void bindTupleValuesElement(const TupleType &tuple, std::index_sequence<Index...>)
template <typename TupleType, std::size_t... ColumnIndices>
void bindTupleValuesElement(const TupleType &tuple, std::index_sequence<ColumnIndices...>)
{
bindValues(std::get<Index>(tuple)...);
bindValues(std::get<ColumnIndices>(tuple)...);
}
template <typename TupleType,
typename Indices = std::make_index_sequence<std::tuple_size<TupleType>::value>>
typename ColumnIndices = std::make_index_sequence<std::tuple_size<TupleType>::value>>
void bindTupleValues(const TupleType &element)
{
bindTupleValuesElement(element, Indices());
bindTupleValuesElement(element, ColumnIndices());
}
private:
......
......@@ -140,6 +140,8 @@ public:
return m_pointer[0] == characterToSearch;
}
private:
const char *m_pointer;
size_type m_size;
......
......@@ -50,7 +50,7 @@ using ClangBackEnd::PchGenerator;
using ClangBackEnd::PchManagerClientProxy;
using ClangBackEnd::PchManagerServer;
using ClangBackEnd::ProjectParts;
using ClangBackEnd::StringCache;
using ClangBackEnd::FilePathCache;
class ApplicationEnvironment : public ClangBackEnd::Environment
{
......@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
const QString connection = processArguments(application);
StringCache<Utils::PathString> filePathCache;
FilePathCache<> filePathCache;
ClangPathWatcher<QFileSystemWatcher, QTimer> includeWatcher(filePathCache);
ApplicationEnvironment environment;
PchGenerator<QProcess> pchGenerator(environment);
......
......@@ -37,8 +37,8 @@ namespace ClangBackEnd {
class WatcherEntry
{
public:
uint id;
uint path;
FilePathIndex id;
FilePathIndex path;
friend bool operator==(const WatcherEntry &first, const WatcherEntry &second)
{
......@@ -50,12 +50,12 @@ public:
return std::tie(first.path, first.id) < std::tie(second.path, second.id);
}
friend bool operator<(const WatcherEntry &entry, uint path)
friend bool operator<(const WatcherEntry &entry, FilePathIndex path)
{
return entry.path < path;
}
friend bool operator<(uint path, const WatcherEntry &entry)
friend bool operator<(FilePathIndex path, const WatcherEntry &entry)
{
return path < entry.path;
}
......@@ -63,12 +63,14 @@ public:
using WatcherEntries = std::vector<WatcherEntry>;
using IdCache = StringCache<Utils::SmallString, FilePathIndex, NonLockingMutex>;
template <typename FileSystemWatcher,
typename Timer>
class ClangPathWatcher : public ClangPathWatcherInterface
{
public:
ClangPathWatcher(StringCache<Utils::PathString> &pathCache,
ClangPathWatcher(FilePathCache<> &pathCache,
ClangPathWatcherNotifier *notifier=nullptr)
: m_pathCache(pathCache),
m_notifier(notifier)
......@@ -130,9 +132,9 @@ unittest_public:
return ids;
}
std::vector<uint> convertToIdNumbers(const Utils::SmallStringVector &ids)
std::vector<FilePathIndex> convertToIdNumbers(const Utils::SmallStringVector &ids)
{
std::vector<uint> idNumbers = m_idCache.stringIds(ids);
std::vector<FilePathIndex> idNumbers = m_idCache.stringIds(ids);
std::sort(idNumbers.begin(), idNumbers.end());
......@@ -149,19 +151,19 @@ unittest_public:
}