hokein created this revision. Herald added subscribers: cfe-commits, klimek.
Repository: rC Clang https://reviews.llvm.org/D45479 Files: include/clang/Tooling/Execution.h lib/Tooling/Execution.cpp Index: lib/Tooling/Execution.cpp =================================================================== --- lib/Tooling/Execution.cpp +++ lib/Tooling/Execution.cpp @@ -21,12 +21,21 @@ llvm::cl::init("standalone")); void InMemoryToolResults::addResult(StringRef Key, StringRef Value) { - KVResults.push_back({Key.str(), Value.str()}); + 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}); } std::vector<std::pair<std::string, std::string>> InMemoryToolResults::AllKVResults() { - return KVResults; + return {}; } void InMemoryToolResults::forEachResult( Index: include/clang/Tooling/Execution.h =================================================================== --- include/clang/Tooling/Execution.h +++ include/clang/Tooling/Execution.h @@ -32,6 +32,7 @@ #include "clang/Tooling/Tooling.h" #include "llvm/Support/Error.h" #include "llvm/Support/Registry.h" +#include "llvm/Support/StringSaver.h" namespace clang { namespace tooling { @@ -52,13 +53,17 @@ class InMemoryToolResults : public ToolResults { public: + InMemoryToolResults() : StringsPool(Arena) {} void addResult(StringRef Key, StringRef Value) override; std::vector<std::pair<std::string, std::string>> AllKVResults() override; void forEachResult(llvm::function_ref<void(StringRef Key, StringRef Value)> Callback) override; private: - std::vector<std::pair<std::string, std::string>> KVResults; + llvm::BumpPtrAllocator Arena; + llvm::StringSaver StringsPool; + llvm::DenseSet<llvm::StringRef> Strings; + std::vector<std::pair<llvm::StringRef, llvm::StringRef>> KVResults; }; /// \brief The context of an execution, including the information about
Index: lib/Tooling/Execution.cpp =================================================================== --- lib/Tooling/Execution.cpp +++ lib/Tooling/Execution.cpp @@ -21,12 +21,21 @@ llvm::cl::init("standalone")); void InMemoryToolResults::addResult(StringRef Key, StringRef Value) { - KVResults.push_back({Key.str(), Value.str()}); + 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}); } std::vector<std::pair<std::string, std::string>> InMemoryToolResults::AllKVResults() { - return KVResults; + return {}; } void InMemoryToolResults::forEachResult( Index: include/clang/Tooling/Execution.h =================================================================== --- include/clang/Tooling/Execution.h +++ include/clang/Tooling/Execution.h @@ -32,6 +32,7 @@ #include "clang/Tooling/Tooling.h" #include "llvm/Support/Error.h" #include "llvm/Support/Registry.h" +#include "llvm/Support/StringSaver.h" namespace clang { namespace tooling { @@ -52,13 +53,17 @@ class InMemoryToolResults : public ToolResults { public: + InMemoryToolResults() : StringsPool(Arena) {} void addResult(StringRef Key, StringRef Value) override; std::vector<std::pair<std::string, std::string>> AllKVResults() override; void forEachResult(llvm::function_ref<void(StringRef Key, StringRef Value)> Callback) override; private: - std::vector<std::pair<std::string, std::string>> KVResults; + llvm::BumpPtrAllocator Arena; + llvm::StringSaver StringsPool; + llvm::DenseSet<llvm::StringRef> Strings; + std::vector<std::pair<llvm::StringRef, llvm::StringRef>> KVResults; }; /// \brief The context of an execution, including the information about
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits