[libcxx-commits] [libcxxabi] 2d77b27 - [Demangle] Add prepend functionality to OutputString
David Blaikie via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 26 16:24:32 PDT 2021
Author: Luís Ferreira
Date: 2021-10-26T16:24:25-07:00
New Revision: 2d77b272a8f9b5b89b022628ca30b6b896a8f725
URL: https://github.com/llvm/llvm-project/commit/2d77b272a8f9b5b89b022628ca30b6b896a8f725
DIFF: https://github.com/llvm/llvm-project/commit/2d77b272a8f9b5b89b022628ca30b6b896a8f725.diff
LOG: [Demangle] Add prepend functionality to OutputString
Implement the functionallity of prepend, required by D demangler.
Please read discussion https://reviews.llvm.org/D111414 for context.
See also https://reviews.llvm.org/D111947 .
Reviewed By: dblaikie, Geod24
Differential Revision: https://reviews.llvm.org/D111948
Added:
Modified:
libcxxabi/src/demangle/Utility.h
llvm/include/llvm/Demangle/Utility.h
llvm/unittests/Demangle/OutputBufferTest.cpp
Removed:
################################################################################
diff --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h
index 7f4d88537ccc9..733d83ad1b6ba 100644
--- a/libcxxabi/src/demangle/Utility.h
+++ b/libcxxabi/src/demangle/Utility.h
@@ -95,6 +95,17 @@ class OutputBuffer {
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) {
diff --git a/llvm/include/llvm/Demangle/Utility.h b/llvm/include/llvm/Demangle/Utility.h
index d668cecc5aefa..4fea9351a4bfc 100644
--- a/llvm/include/llvm/Demangle/Utility.h
+++ b/llvm/include/llvm/Demangle/Utility.h
@@ -95,6 +95,17 @@ class OutputBuffer {
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) {
diff --git a/llvm/unittests/Demangle/OutputBufferTest.cpp b/llvm/unittests/Demangle/OutputBufferTest.cpp
index c356ca3e74bf5..1d37f567e1d42 100644
--- a/llvm/unittests/Demangle/OutputBufferTest.cpp
+++ b/llvm/unittests/Demangle/OutputBufferTest.cpp
@@ -60,3 +60,21 @@ TEST(OutputBufferTest, Insert) {
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());
+}
More information about the libcxx-commits
mailing list