[PATCH] D135119: [scudo] Optimize scudo test string allocation
Dominic Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 9 17:23:05 PST 2022
ddcc updated this revision to Diff 481801.
ddcc added a comment.
Call new reserve() method
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D135119/new/
https://reviews.llvm.org/D135119
Files:
compiler-rt/lib/scudo/standalone/string_utils.h
compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
Index: compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
===================================================================
--- compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
+++ compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
@@ -43,9 +43,11 @@
}
TEST(ScudoStringsTest, ClearLarge) {
+ constexpr char appendString[] = "123";
scudo::ScopedString Str;
+ Str.reserve(sizeof(appendString) * 10000);
for (int i = 0; i < 10000; ++i)
- Str.append("123");
+ Str.append(appendString);
Str.clear();
EXPECT_EQ(0ul, Str.length());
EXPECT_EQ('\0', *Str.data());
@@ -76,6 +78,7 @@
// of it with variations of append. The expectation is for nothing to crash.
const scudo::uptr PageSize = scudo::getPageSizeCached();
scudo::ScopedString Str;
+ Str.reserve(2 * PageSize);
Str.clear();
fillString(Str, 2 * PageSize);
Str.clear();
Index: compiler-rt/lib/scudo/standalone/string_utils.h
===================================================================
--- compiler-rt/lib/scudo/standalone/string_utils.h
+++ compiler-rt/lib/scudo/standalone/string_utils.h
@@ -28,6 +28,7 @@
void append(const char *Format, va_list Args);
void append(const char *Format, ...) FORMAT(2, 3);
void output() const { outputRaw(String.data()); }
+ void reserve(size_t Size) { String.reserve(Size + 1); }
private:
Vector<char> String;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135119.481801.patch
Type: text/x-patch
Size: 1380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221210/6ffeebef/attachment.bin>
More information about the llvm-commits
mailing list