[PATCH] D42113: [clangd] Deduplicate symbols collected in global-symbol-builder tool.
Eric Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 17 10:29:36 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322722: [clangd] Deduplicate symbols collected in global-symbol-builder tool. (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.
Repository:
rL LLVM
https://reviews.llvm.org/D42113
Files:
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
Index: clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
+++ clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -105,7 +105,22 @@
llvm::errs() << llvm::toString(std::move(Err)) << "\n";
}
+ // Deduplicate the result by key and keep the longest value.
+ // FIXME(ioeric): Merge occurrences, rather than just dropping all but one.
+ // Definitions and forward declarations have the same key and may both have
+ // information. Usage count will need to be aggregated across occurrences,
+ // too.
+ llvm::StringMap<llvm::StringRef> UniqueSymbols;
Executor->get()->getToolResults()->forEachResult(
- [](llvm::StringRef, llvm::StringRef Value) { llvm::outs() << Value; });
+ [&UniqueSymbols](llvm::StringRef Key, llvm::StringRef Value) {
+ auto Ret = UniqueSymbols.try_emplace(Key, Value);
+ if (!Ret.second) {
+ // If key already exists, keep the longest value.
+ llvm::StringRef &V = Ret.first->second;
+ V = V.size() < Value.size() ? Value : V;
+ }
+ });
+ for (const auto &Sym : UniqueSymbols)
+ llvm::outs() << Sym.second;
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42113.130210.patch
Type: text/x-patch
Size: 1342 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180117/a0bfb09b/attachment.bin>
More information about the cfe-commits
mailing list