mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
intern strings in dependencies and IndexInclude::resolved_path
This commit is contained in:
parent
1249eb1eb0
commit
97e773081b
@ -1089,7 +1089,7 @@ public:
|
|||||||
if (IndexFile *db = param.ConsumeFile(*FE)) {
|
if (IndexFile *db = param.ConsumeFile(*FE)) {
|
||||||
std::string file_name = FileName(*File);
|
std::string file_name = FileName(*File);
|
||||||
if (file_name.size())
|
if (file_name.size())
|
||||||
db->includes.push_back({spell.start.line, std::move(file_name)});
|
db->includes.push_back({spell.start.line, Intern(file_name)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MacroDefined(const Token &Tok, const MacroDirective *MD) override {
|
void MacroDefined(const Token &Tok, const MacroDirective *MD) override {
|
||||||
@ -1343,7 +1343,8 @@ Index(CompletionManager *completion, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
// dependency set.
|
// dependency set.
|
||||||
for (auto &[_, path] : param.SeenUniqueID)
|
for (auto &[_, path] : param.SeenUniqueID)
|
||||||
if (path != entry->path && path != entry->import_file)
|
if (path != entry->path && path != entry->import_file)
|
||||||
entry->dependencies[path] = param.file2mtime[path];
|
entry->dependencies[llvm::CachedHashStringRef(Intern(path))] =
|
||||||
|
param.file2mtime[path];
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <clang/Basic/Specifiers.h>
|
#include <clang/Basic/Specifiers.h>
|
||||||
#include <llvm/ADT/StringMap.h>
|
#include <llvm/ADT/CachedHashString.h>
|
||||||
|
#include <llvm/ADT/DenseMap.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@ -220,7 +221,7 @@ struct IndexInclude {
|
|||||||
// information - a line is good enough for clicking.
|
// information - a line is good enough for clicking.
|
||||||
int line = 0;
|
int line = 0;
|
||||||
// Absolute path to the index.
|
// Absolute path to the index.
|
||||||
std::string resolved_path;
|
const char *resolved_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IndexFile {
|
struct IndexFile {
|
||||||
@ -254,7 +255,7 @@ struct IndexFile {
|
|||||||
std::vector<Range> skipped_ranges;
|
std::vector<Range> skipped_ranges;
|
||||||
|
|
||||||
std::vector<IndexInclude> includes;
|
std::vector<IndexInclude> includes;
|
||||||
llvm::StringMap<int64_t> dependencies;
|
llvm::DenseMap<llvm::CachedHashStringRef, int64_t> dependencies;
|
||||||
std::unordered_map<Usr, IndexFunc> usr2func;
|
std::unordered_map<Usr, IndexFunc> usr2func;
|
||||||
std::unordered_map<Usr, IndexType> usr2type;
|
std::unordered_map<Usr, IndexType> usr2type;
|
||||||
std::unordered_map<Usr, IndexVar> usr2var;
|
std::unordered_map<Usr, IndexVar> usr2var;
|
||||||
|
@ -325,7 +325,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
|
|||||||
if (entry.id >= 0) {
|
if (entry.id >= 0) {
|
||||||
std::lock_guard<std::mutex> lock(project->mutex_);
|
std::lock_guard<std::mutex> lock(project->mutex_);
|
||||||
for (auto &dep : curr->dependencies)
|
for (auto &dep : curr->dependencies)
|
||||||
project->path_to_entry_index[dep.first()] = entry.id;
|
project->path_to_entry_index[dep.first.val().str()] = entry.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ QueryFile::DefUpdate BuildFileDefUpdate(const IndexFile &indexed) {
|
|||||||
def.skipped_ranges = std::move(indexed.skipped_ranges);
|
def.skipped_ranges = std::move(indexed.skipped_ranges);
|
||||||
def.dependencies.reserve(indexed.dependencies.size());
|
def.dependencies.reserve(indexed.dependencies.size());
|
||||||
for (auto &dep : indexed.dependencies)
|
for (auto &dep : indexed.dependencies)
|
||||||
def.dependencies.push_back(dep.first());
|
def.dependencies.push_back(dep.first.val().data()); // llvm 8 -> data()
|
||||||
def.language = indexed.language;
|
def.language = indexed.language;
|
||||||
return {std::move(def), std::move(indexed.file_contents)};
|
return {std::move(def), std::move(indexed.file_contents)};
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ struct QueryFile {
|
|||||||
// Parts of the file which are disabled.
|
// Parts of the file which are disabled.
|
||||||
std::vector<Range> skipped_ranges;
|
std::vector<Range> skipped_ranges;
|
||||||
// Used by |$ccls/reload|.
|
// Used by |$ccls/reload|.
|
||||||
std::vector<std::string> dependencies;
|
std::vector<const char *> dependencies;
|
||||||
};
|
};
|
||||||
|
|
||||||
using DefUpdate = std::pair<Def, std::string>;
|
using DefUpdate = std::pair<Def, std::string>;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
using namespace ccls;
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
bool gTestOutputMode = false;
|
bool gTestOutputMode = false;
|
||||||
@ -115,7 +116,7 @@ void Reflect(Writer &visitor, std::string_view &data) {
|
|||||||
|
|
||||||
void Reflect(Reader &vis, const char *&v) {
|
void Reflect(Reader &vis, const char *&v) {
|
||||||
const char *str = vis.GetString();
|
const char *str = vis.GetString();
|
||||||
v = ccls::Intern(str);
|
v = Intern(str);
|
||||||
}
|
}
|
||||||
void Reflect(Writer &vis, const char *&v) { vis.String(v); }
|
void Reflect(Writer &vis, const char *&v) { vis.String(v); }
|
||||||
|
|
||||||
@ -148,33 +149,33 @@ void Reflect(Writer &visitor, std::unordered_map<Usr, V> &map) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Used by IndexFile::dependencies.
|
// Used by IndexFile::dependencies.
|
||||||
void Reflect(Reader &vis, StringMap<int64_t> &v) {
|
void Reflect(Reader &vis, DenseMap<CachedHashStringRef, int64_t> &v) {
|
||||||
std::string name;
|
std::string name;
|
||||||
if (vis.Format() == SerializeFormat::Json) {
|
if (vis.Format() == SerializeFormat::Json) {
|
||||||
auto &vis1 = static_cast<JsonReader&>(vis);
|
auto &vis1 = static_cast<JsonReader&>(vis);
|
||||||
for (auto it = vis1.m().MemberBegin(); it != vis1.m().MemberEnd(); ++it)
|
for (auto it = vis1.m().MemberBegin(); it != vis1.m().MemberEnd(); ++it)
|
||||||
v[it->name.GetString()] = it->value.GetInt64();
|
v[CachedHashStringRef(Intern(it->name.GetString()))] =
|
||||||
|
it->value.GetInt64();
|
||||||
} else {
|
} else {
|
||||||
vis.IterArray([&](Reader &entry) {
|
vis.IterArray([&](Reader &entry) {
|
||||||
Reflect(entry, name);
|
Reflect(entry, name);
|
||||||
Reflect(entry, v[name]);
|
Reflect(entry, v[CachedHashStringRef(Intern(name))]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Reflect(Writer &vis, StringMap<int64_t> &v) {
|
void Reflect(Writer &vis, DenseMap<CachedHashStringRef, int64_t> &v) {
|
||||||
if (vis.Format() == SerializeFormat::Json) {
|
if (vis.Format() == SerializeFormat::Json) {
|
||||||
auto &vis1 = static_cast<JsonWriter&>(vis);
|
auto &vis1 = static_cast<JsonWriter&>(vis);
|
||||||
vis.StartObject();
|
vis.StartObject();
|
||||||
for (auto &it : v) {
|
for (auto &it : v) {
|
||||||
std::string key = it.first();
|
vis1.m().Key(it.first.val().data()); // llvm 8 -> data()
|
||||||
vis1.m().Key(key.c_str());
|
|
||||||
vis1.m().Int64(it.second);
|
vis1.m().Int64(it.second);
|
||||||
}
|
}
|
||||||
vis.EndObject();
|
vis.EndObject();
|
||||||
} else {
|
} else {
|
||||||
vis.StartArray(v.size());
|
vis.StartArray(v.size());
|
||||||
for (auto &it : v) {
|
for (auto &it : v) {
|
||||||
std::string key = it.first();
|
std::string key = it.first.val().str();
|
||||||
Reflect(vis, key);
|
Reflect(vis, key);
|
||||||
Reflect(vis, it.second);
|
Reflect(vis, it.second);
|
||||||
}
|
}
|
||||||
@ -455,13 +456,16 @@ Deserialize(SerializeFormat format, const std::string &path,
|
|||||||
DoPathMapping(arg);
|
DoPathMapping(arg);
|
||||||
for (auto &[_, path] : file->lid2path)
|
for (auto &[_, path] : file->lid2path)
|
||||||
DoPathMapping(path);
|
DoPathMapping(path);
|
||||||
for (auto &include : file->includes)
|
for (auto &include : file->includes) {
|
||||||
DoPathMapping(include.resolved_path);
|
std::string p(include.resolved_path);
|
||||||
StringMap<int64_t> dependencies;
|
DoPathMapping(p);
|
||||||
|
include.resolved_path = Intern(p);
|
||||||
|
}
|
||||||
|
decltype(file->dependencies) dependencies;
|
||||||
for (auto &it : file->dependencies) {
|
for (auto &it : file->dependencies) {
|
||||||
std::string path = it.first().str();
|
std::string path = it.first.val().str();
|
||||||
DoPathMapping(path);
|
DoPathMapping(path);
|
||||||
dependencies[path] = it.second;
|
dependencies[CachedHashStringRef(Intern(path))] = it.second;
|
||||||
}
|
}
|
||||||
file->dependencies = std::move(dependencies);
|
file->dependencies = std::move(dependencies);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user