[PATCH] D157015: [llvm][Support] Avoid intermediate heap allocations in `StringSaver`
Jan Svoboda via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 11:12:21 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGefcb07bf6e5f: [llvm][Support] Avoid intermediate heap allocations in `StringSaver` (authored by jansvoboda11).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157015/new/
https://reviews.llvm.org/D157015
Files:
llvm/include/llvm/Support/StringSaver.h
llvm/lib/Support/StringSaver.cpp
Index: llvm/lib/Support/StringSaver.cpp
===================================================================
--- llvm/lib/Support/StringSaver.cpp
+++ llvm/lib/Support/StringSaver.cpp
@@ -8,6 +8,8 @@
#include "llvm/Support/StringSaver.h"
+#include "llvm/ADT/SmallString.h"
+
using namespace llvm;
StringRef StringSaver::save(StringRef S) {
@@ -18,9 +20,19 @@
return StringRef(P, S.size());
}
+StringRef StringSaver::save(const Twine &S) {
+ SmallString<128> Storage;
+ return save(S.toStringRef(Storage));
+}
+
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;
}
+
+StringRef UniqueStringSaver::save(const Twine &S) {
+ SmallString<128> Storage;
+ return save(S.toStringRef(Storage));
+}
Index: llvm/include/llvm/Support/StringSaver.h
===================================================================
--- llvm/include/llvm/Support/StringSaver.h
+++ llvm/include/llvm/Support/StringSaver.h
@@ -29,7 +29,7 @@
// All returned strings are null-terminated: *save(S).end() == 0.
StringRef save(const char *S) { return save(StringRef(S)); }
StringRef save(StringRef S);
- StringRef save(const Twine &S) { return save(StringRef(S.str())); }
+ StringRef save(const Twine &S);
StringRef save(const std::string &S) { return save(StringRef(S)); }
};
@@ -51,7 +51,7 @@
// All returned strings are null-terminated: *save(S).end() == 0.
StringRef save(const char *S) { return save(StringRef(S)); }
StringRef save(StringRef S);
- StringRef save(const Twine &S) { return save(StringRef(S.str())); }
+ StringRef save(const Twine &S);
StringRef save(const std::string &S) { return save(StringRef(S)); }
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157015.546950.patch
Type: text/x-patch
Size: 1842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230803/1c5b2bef/attachment.bin>
More information about the llvm-commits
mailing list