From 1f3f69b2214394d2ae77f1a8bbfdd6d0cb64f45f Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sun, 30 Jul 2017 11:31:41 -0700 Subject: [PATCH] Reuse loaded file contents in indexer; clear large state before caching. --- src/command_line.cc | 7 ++++++- src/indexer.cc | 7 +++++++ src/indexer.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/command_line.cc b/src/command_line.cc index c063876b..8110b43f 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -834,6 +834,8 @@ struct CacheManager { } std::shared_ptr UpdateAndReturnOldFile(std::shared_ptr entry) { + entry->file->ClearLargeState(); + const auto it = files_.find(entry->file->path); if (it != files_.end()) { std::shared_ptr old = std::move(it->second); @@ -895,7 +897,6 @@ bool IndexMain_DoIndex(Config* config, } assert(current_index); - // assert(previous_index); // TODO: get real value for is_interactive Index_DoIdMap response(std::move(current_index), request->perf, @@ -1162,6 +1163,10 @@ std::vector DoParseFile( // // We do this to minimize the race between indexing a file and capturing the // file contents. + // + // TODO: We might be able to optimize perf by only copying for files in + // working_files. We can pass that same set of files to the indexer as + // well. We then default to a fast file-copy if not in working set. std::vector file_contents; for (const auto& it : cache_loader->caches) { const std::unique_ptr& index = it.second; diff --git a/src/indexer.cc b/src/indexer.cc index e8c765f6..bb2237c1 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -356,6 +356,10 @@ std::string IndexFile::ToString() { return Serialize(*this); } +void IndexFile::ClearLargeState() { + file_contents_ = ""; +} + IndexType::IndexType(IndexTypeId id, const std::string& usr) : def(usr), id(id) { assert(usr.size() > 0); @@ -1603,6 +1607,9 @@ std::vector> Parse( FileConsumer file_consumer(file_consumer_shared, file); IndexParam param(&tu, &file_consumer); + for (const FileContents& contents : file_contents) { + param.file_contents[contents.path] = contents.content; + } CXFile cx_file = clang_getFile(tu.cx_tu, file.c_str()); param.primary_file = ConsumeFile(¶m, cx_file); diff --git a/src/indexer.h b/src/indexer.h index 9949f98c..c47c3ca8 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -498,6 +498,7 @@ struct IndexFile { IndexVar* Resolve(IndexVarId id); std::string ToString(); + void ClearLargeState(); }; struct FileContents {