diff --git a/src/indexer.cc b/src/indexer.cc index d77be6f7..34e28744 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1089,7 +1089,7 @@ public: if (IndexFile *db = param.ConsumeFile(*FE)) { std::string file_name = FileName(*File); 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 { @@ -1343,7 +1343,8 @@ Index(CompletionManager *completion, WorkingFiles *wfiles, VFS *vfs, // dependency set. for (auto &[_, path] : param.SeenUniqueID) 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; diff --git a/src/indexer.h b/src/indexer.h index 2bbce4e0..f919327f 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -15,7 +15,8 @@ #include "utils.h" #include -#include +#include +#include #include #include @@ -220,7 +221,7 @@ struct IndexInclude { // information - a line is good enough for clicking. int line = 0; // Absolute path to the index. - std::string resolved_path; + const char *resolved_path; }; struct IndexFile { @@ -254,7 +255,7 @@ struct IndexFile { std::vector skipped_ranges; std::vector includes; - llvm::StringMap dependencies; + llvm::DenseMap dependencies; std::unordered_map usr2func; std::unordered_map usr2type; std::unordered_map usr2var; diff --git a/src/pipeline.cc b/src/pipeline.cc index 8d65886d..45c0f6bd 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -325,7 +325,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles, if (entry.id >= 0) { std::lock_guard lock(project->mutex_); 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; } } } diff --git a/src/query.cc b/src/query.cc index 374c0d15..2db20d11 100644 --- a/src/query.cc +++ b/src/query.cc @@ -50,7 +50,7 @@ QueryFile::DefUpdate BuildFileDefUpdate(const IndexFile &indexed) { def.skipped_ranges = std::move(indexed.skipped_ranges); def.dependencies.reserve(indexed.dependencies.size()); 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; return {std::move(def), std::move(indexed.file_contents)}; } diff --git a/src/query.h b/src/query.h index 7241e177..6f844656 100644 --- a/src/query.h +++ b/src/query.h @@ -35,7 +35,7 @@ struct QueryFile { // Parts of the file which are disabled. std::vector skipped_ranges; // Used by |$ccls/reload|. - std::vector dependencies; + std::vector dependencies; }; using DefUpdate = std::pair; diff --git a/src/serializer.cc b/src/serializer.cc index c6da2ae0..7061015f 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -15,6 +15,7 @@ #include #include +using namespace ccls; using namespace llvm; bool gTestOutputMode = false; @@ -115,7 +116,7 @@ void Reflect(Writer &visitor, std::string_view &data) { void Reflect(Reader &vis, const char *&v) { const char *str = vis.GetString(); - v = ccls::Intern(str); + v = Intern(str); } void Reflect(Writer &vis, const char *&v) { vis.String(v); } @@ -148,33 +149,33 @@ void Reflect(Writer &visitor, std::unordered_map &map) { } // Used by IndexFile::dependencies. -void Reflect(Reader &vis, StringMap &v) { +void Reflect(Reader &vis, DenseMap &v) { std::string name; if (vis.Format() == SerializeFormat::Json) { auto &vis1 = static_cast(vis); 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 { vis.IterArray([&](Reader &entry) { Reflect(entry, name); - Reflect(entry, v[name]); + Reflect(entry, v[CachedHashStringRef(Intern(name))]); }); } } -void Reflect(Writer &vis, StringMap &v) { +void Reflect(Writer &vis, DenseMap &v) { if (vis.Format() == SerializeFormat::Json) { auto &vis1 = static_cast(vis); vis.StartObject(); for (auto &it : v) { - std::string key = it.first(); - vis1.m().Key(key.c_str()); + vis1.m().Key(it.first.val().data()); // llvm 8 -> data() vis1.m().Int64(it.second); } vis.EndObject(); } else { vis.StartArray(v.size()); for (auto &it : v) { - std::string key = it.first(); + std::string key = it.first.val().str(); Reflect(vis, key); Reflect(vis, it.second); } @@ -455,13 +456,16 @@ Deserialize(SerializeFormat format, const std::string &path, DoPathMapping(arg); for (auto &[_, path] : file->lid2path) DoPathMapping(path); - for (auto &include : file->includes) - DoPathMapping(include.resolved_path); - StringMap dependencies; + for (auto &include : file->includes) { + std::string p(include.resolved_path); + DoPathMapping(p); + include.resolved_path = Intern(p); + } + decltype(file->dependencies) dependencies; for (auto &it : file->dependencies) { - std::string path = it.first().str(); + std::string path = it.first.val().str(); DoPathMapping(path); - dependencies[path] = it.second; + dependencies[CachedHashStringRef(Intern(path))] = it.second; } file->dependencies = std::move(dependencies); }