[libcxx-commits] [PATCH] D111948: [Demangle] Add prepend functionality to OutputString
David Blaikie via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 26 16:24:34 PDT 2021
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2d77b272a8f9: [Demangle] Add prepend functionality to OutputString (authored by ljmf00, committed by dblaikie).
Repository:
rG LLVM Github Monorepo
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,21 @@
std::free(OB.getBuffer());
}
+
+TEST(OutputBufferTest, 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,17 @@
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,17 @@
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.382478.patch
Type: text/x-patch
Size: 1855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211026/88e40576/attachment.bin>
More information about the libcxx-commits
mailing list