mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-23 16:15:07 +00:00
intern strings in dependencies and IndexInclude::resolved_path
This commit is contained in:
parent
763106c3d4
commit
525b6da1ac
@ -1104,7 +1104,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 {
|
||||
@ -1368,7 +1368,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;
|
||||
|
@ -27,7 +27,8 @@ limitations under the License.
|
||||
#include "utils.h"
|
||||
|
||||
#include <clang/Basic/Specifiers.h>
|
||||
#include <llvm/ADT/StringMap.h>
|
||||
#include <llvm/ADT/CachedHashString.h>
|
||||
#include <llvm/ADT/DenseMap.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
@ -232,7 +233,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 {
|
||||
@ -266,7 +267,7 @@ struct IndexFile {
|
||||
std::vector<Range> skipped_ranges;
|
||||
|
||||
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, IndexType> usr2type;
|
||||
std::unordered_map<Usr, IndexVar> usr2var;
|
||||
|
@ -337,7 +337,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
|
||||
if (entry.id >= 0) {
|
||||
std::lock_guard<std::mutex> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,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)};
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ struct QueryFile {
|
||||
// Parts of the file which are disabled.
|
||||
std::vector<Range> skipped_ranges;
|
||||
// Used by |$ccls/reload|.
|
||||
std::vector<std::string> dependencies;
|
||||
std::vector<const char *> dependencies;
|
||||
};
|
||||
|
||||
using DefUpdate = std::pair<Def, std::string>;
|
||||
|
@ -27,6 +27,7 @@ limitations under the License.
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace ccls;
|
||||
using namespace llvm;
|
||||
|
||||
bool gTestOutputMode = false;
|
||||
@ -127,7 +128,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); }
|
||||
|
||||
@ -160,33 +161,33 @@ void Reflect(Writer &visitor, std::unordered_map<Usr, V> &map) {
|
||||
}
|
||||
|
||||
// Used by IndexFile::dependencies.
|
||||
void Reflect(Reader &vis, StringMap<int64_t> &v) {
|
||||
void Reflect(Reader &vis, DenseMap<CachedHashStringRef, int64_t> &v) {
|
||||
std::string name;
|
||||
if (vis.Format() == SerializeFormat::Json) {
|
||||
auto &vis1 = static_cast<JsonReader&>(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<int64_t> &v) {
|
||||
void Reflect(Writer &vis, DenseMap<CachedHashStringRef, int64_t> &v) {
|
||||
if (vis.Format() == SerializeFormat::Json) {
|
||||
auto &vis1 = static_cast<JsonWriter&>(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);
|
||||
}
|
||||
@ -467,13 +468,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<int64_t> 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user