[libcxx-commits] [PATCH] D111948: [Demangle] Add prepend functionality to OutputString
Luís Ferreira via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 21 13:14:04 PDT 2021
ljmf00 updated this revision to Diff 381370.
ljmf00 added a comment.
I added more tests to cover the requested situations. I also forgot to add a free after a malloc on the testsuite. I also changed the manual for loop to memmove to benefit from optimized implementations.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111948/new/
https://reviews.llvm.org/D111948
Files:
libcxxabi/src/demangle/Utility.h
llvm/include/llvm/Demangle/Utility.h
llvm/unittests/Demangle/OutputBufferTest.cpp
Index: llvm/unittests/Demangle/OutputBufferTest.cpp
===================================================================
--- llvm/unittests/Demangle/OutputBufferTest.cpp
+++ llvm/unittests/Demangle/OutputBufferTest.cpp
@@ -60,3 +60,22 @@
std::free(OB.getBuffer());
}
+
+TEST(OutputStringTest, Prepend)
+{
+ OutputBuffer OB;
+
+ OB.prepend("n");
+ EXPECT_EQ("n", toString(OB));
+
+ OB << "abc";
+ OB.prepend("def");
+ EXPECT_EQ("defnabc", toString(OB));
+
+ OB.setCurrentPosition(3);
+
+ OB.prepend("abc");
+ EXPECT_EQ("abcdef", toString(OB));
+
+ std::free(OB.getBuffer());
+}
Index: llvm/include/llvm/Demangle/Utility.h
===================================================================
--- llvm/include/llvm/Demangle/Utility.h
+++ llvm/include/llvm/Demangle/Utility.h
@@ -95,6 +95,18 @@
OutputBuffer &operator<<(StringView R) { return (*this += R); }
+ OutputBuffer prepend(StringView R)
+ {
+ size_t Size = R.size();
+
+ grow(Size);
+ std::memmove(Buffer + Size, Buffer, CurrentPosition);
+ std::memcpy(Buffer, R.begin(), Size);
+ CurrentPosition += Size;
+
+ return *this;
+ }
+
OutputBuffer &operator<<(char C) { return (*this += C); }
OutputBuffer &operator<<(long long N) {
Index: libcxxabi/src/demangle/Utility.h
===================================================================
--- libcxxabi/src/demangle/Utility.h
+++ libcxxabi/src/demangle/Utility.h
@@ -95,6 +95,18 @@
OutputBuffer &operator<<(StringView R) { return (*this += R); }
+ OutputBuffer prepend(StringView R)
+ {
+ size_t Size = R.size();
+
+ grow(Size);
+ std::memmove(Buffer + Size, Buffer, CurrentPosition);
+ std::memcpy(Buffer, R.begin(), Size);
+ CurrentPosition += Size;
+
+ return *this;
+ }
+
OutputBuffer &operator<<(char C) { return (*this += C); }
OutputBuffer &operator<<(long long N) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111948.381370.patch
Type: text/x-patch
Size: 1862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211021/f369f441/attachment.bin>
More information about the libcxx-commits
mailing list