diff --git a/clang-tools-extra/clangd/index/dex/Dex.cpp b/clang-tools-extra/clangd/index/dex/Dex.cpp --- a/clang-tools-extra/clangd/index/dex/Dex.cpp +++ b/clang-tools-extra/clangd/index/dex/Dex.cpp @@ -21,6 +21,7 @@ #include "llvm/Support/ScopedPrinter.h" #include #include +#include namespace clang { namespace clangd { @@ -76,23 +77,32 @@ } // Assemble the final compressed posting lists for the added symbols. - llvm::DenseMap build() { + llvm::DenseMap build() && { llvm::DenseMap Result(/*InitialReserve=*/ TrigramDocs.size() + RestrictedCCDocs.size() + TypeDocs.size() + ScopeDocs.size() + ProximityDocs.size()); - for (const auto &E : TrigramDocs) - Result.try_emplace(Token(Token::Kind::Trigram, E.first.str()), E.second); - for (const auto &E : TypeDocs) - Result.try_emplace(Token(Token::Kind::Type, E.first()), E.second); - for (const auto &E : ScopeDocs) - Result.try_emplace(Token(Token::Kind::Scope, E.first()), E.second); - for (const auto &E : ProximityDocs) - Result.try_emplace(Token(Token::Kind::ProximityURI, E.first()), E.second); + for (auto &E : TrigramDocs) + Result.try_emplace(Token(Token::Kind::Trigram, E.first.str()), + std::move(E.second)); + TrigramDocs.clear(); + for (auto &E : TypeDocs) + Result.try_emplace(Token(Token::Kind::Type, E.first()), + std::move(E.second)); + TypeDocs.clear(); + for (auto &E : ScopeDocs) + Result.try_emplace(Token(Token::Kind::Scope, E.first()), + std::move(E.second)); + ScopeDocs.clear(); + for (auto &E : ProximityDocs) + Result.try_emplace(Token(Token::Kind::ProximityURI, E.first()), + std::move(E.second)); + ProximityDocs.clear(); if (!RestrictedCCDocs.empty()) - Result.try_emplace(RestrictedForCodeCompletion, RestrictedCCDocs); + Result.try_emplace(RestrictedForCodeCompletion, + std::move(RestrictedCCDocs)); return Result; } }; @@ -125,7 +135,7 @@ IndexBuilder Builder; for (DocID SymbolRank = 0; SymbolRank < Symbols.size(); ++SymbolRank) Builder.add(*Symbols[SymbolRank], SymbolRank); - InvertedIndex = Builder.build(); + InvertedIndex = std::move(Builder).build(); } std::unique_ptr Dex::iterator(const Token &Tok) const {