[llvm] 29560a8 - [Support] Make UniqueStringSaver wrap a StringSet
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Thu May 14 08:14:26 PDT 2020
Author: Benjamin Kramer
Date: 2020-05-14T17:11:44+02:00
New Revision: 29560a89ddcaf3af9b8a73d98d968a0911d21e27
URL: https://github.com/llvm/llvm-project/commit/29560a89ddcaf3af9b8a73d98d968a0911d21e27
DIFF: https://github.com/llvm/llvm-project/commit/29560a89ddcaf3af9b8a73d98d968a0911d21e27.diff
LOG: [Support] Make UniqueStringSaver wrap a StringSet
This is slightly more efficient while providing exactly the same
semantics.
Added:
Modified:
llvm/include/llvm/Support/StringSaver.h
llvm/lib/Support/StringSaver.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/StringSaver.h b/llvm/include/llvm/Support/StringSaver.h
index c54044e3986c..b6b3c054d07d 100644
--- a/llvm/include/llvm/Support/StringSaver.h
+++ b/llvm/include/llvm/Support/StringSaver.h
@@ -9,7 +9,7 @@
#ifndef LLVM_SUPPORT_STRINGSAVER_H
#define LLVM_SUPPORT_STRINGSAVER_H
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Allocator.h"
@@ -36,12 +36,8 @@ class StringSaver final {
///
/// Compared to StringSaver, it does more work but avoids saving the same string
/// multiple times.
-///
-/// Compared to StringPool, it performs fewer allocations but doesn't support
-/// refcounting/deletion.
class UniqueStringSaver final {
- StringSaver Strings;
- llvm::DenseSet<llvm::StringRef> Unique;
+ StringSet<BumpPtrAllocator &> Strings;
public:
UniqueStringSaver(BumpPtrAllocator &Alloc) : Strings(Alloc) {}
diff --git a/llvm/lib/Support/StringSaver.cpp b/llvm/lib/Support/StringSaver.cpp
index f7ccfb97ea79..999f37a9a75d 100644
--- a/llvm/lib/Support/StringSaver.cpp
+++ b/llvm/lib/Support/StringSaver.cpp
@@ -19,8 +19,5 @@ StringRef StringSaver::save(StringRef S) {
}
StringRef UniqueStringSaver::save(StringRef S) {
- auto R = Unique.insert(S);
- if (R.second) // cache miss, need to actually save the string
- *R.first = Strings.save(S); // safe replacement with equal value
- return *R.first;
+ return Strings.insert(S).first->getKey();
}
More information about the llvm-commits
mailing list