r337682 - [Tooling] Use UniqueStringSaver. NFC

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 23 04:25:25 PDT 2018


Author: sammccall
Date: Mon Jul 23 04:25:25 2018
New Revision: 337682

URL: http://llvm.org/viewvc/llvm-project?rev=337682&view=rev
Log:
[Tooling] Use UniqueStringSaver. NFC

Modified:
    cfe/trunk/include/clang/Tooling/Execution.h
    cfe/trunk/lib/Tooling/Execution.cpp

Modified: cfe/trunk/include/clang/Tooling/Execution.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Execution.h?rev=337682&r1=337681&r2=337682&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/Execution.h (original)
+++ cfe/trunk/include/clang/Tooling/Execution.h Mon Jul 23 04:25:25 2018
@@ -57,7 +57,7 @@ public:
 /// set of different results, or a large set of duplicated results.
 class InMemoryToolResults : public ToolResults {
 public:
-  InMemoryToolResults() : StringsPool(Arena) {}
+  InMemoryToolResults() : Strings(Arena) {}
   void addResult(StringRef Key, StringRef Value) override;
   std::vector<std::pair<llvm::StringRef, llvm::StringRef>>
   AllKVResults() override;
@@ -66,8 +66,7 @@ public:
 
 private:
   llvm::BumpPtrAllocator Arena;
-  llvm::StringSaver StringsPool;
-  llvm::DenseSet<llvm::StringRef> Strings;
+  llvm::UniqueStringSaver Strings;
 
   std::vector<std::pair<llvm::StringRef, llvm::StringRef>> KVResults;
 };

Modified: cfe/trunk/lib/Tooling/Execution.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Execution.cpp?rev=337682&r1=337681&r2=337682&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Execution.cpp (original)
+++ cfe/trunk/lib/Tooling/Execution.cpp Mon Jul 23 04:25:25 2018
@@ -21,16 +21,7 @@ static llvm::cl::opt<std::string>
                  llvm::cl::init("standalone"));
 
 void InMemoryToolResults::addResult(StringRef Key, StringRef Value) {
-  auto Intern = [&](StringRef &V) {
-    auto R = Strings.insert(V);
-    if (R.second) { // A new entry, create a new string copy.
-      *R.first = StringsPool.save(V);
-    }
-    V = *R.first;
-  };
-  Intern(Key);
-  Intern(Value);
-  KVResults.push_back({Key, Value});
+  KVResults.push_back({Strings.save(Key), Strings.save(Value)});
 }
 
 std::vector<std::pair<llvm::StringRef, llvm::StringRef>>




More information about the cfe-commits mailing list