[llvm] 8f79b0f - [llvm] Do not zero out write_unsigned_impl internal buffer
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 22:59:49 PST 2023
Author: serge-sans-paille
Date: 2023-01-26T07:59:33+01:00
New Revision: 8f79b0fe0047d6a3857ab2dd4bd121a1c4e3afba
URL: https://github.com/llvm/llvm-project/commit/8f79b0fe0047d6a3857ab2dd4bd121a1c4e3afba
DIFF: https://github.com/llvm/llvm-project/commit/8f79b0fe0047d6a3857ab2dd4bd121a1c4e3afba.diff
LOG: [llvm] Do not zero out write_unsigned_impl internal buffer
Current implementation uselessly calls memset on its internal buffer
while it does not read the non overwritten part.
Differential Revision: https://reviews.llvm.org/D142464
Added:
Modified:
llvm/lib/Support/NativeFormatting.cpp
llvm/unittests/Support/NativeFormatTests.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/NativeFormatting.cpp b/llvm/lib/Support/NativeFormatting.cpp
index 6e8137c405b80..3b9273e1eaadb 100644
--- a/llvm/lib/Support/NativeFormatting.cpp
+++ b/llvm/lib/Support/NativeFormatting.cpp
@@ -58,10 +58,7 @@ static void write_unsigned_impl(raw_ostream &S, T N, size_t MinDigits,
static_assert(std::is_unsigned_v<T>, "Value is not unsigned!");
char NumberBuffer[128];
- std::memset(NumberBuffer, '0', sizeof(NumberBuffer));
-
- size_t Len = 0;
- Len = format_to_buffer(N, NumberBuffer);
+ size_t Len = format_to_buffer(N, NumberBuffer);
if (IsNegative)
S << '-';
diff --git a/llvm/unittests/Support/NativeFormatTests.cpp b/llvm/unittests/Support/NativeFormatTests.cpp
index 197fad1f83cfc..5568727bcc90a 100644
--- a/llvm/unittests/Support/NativeFormatTests.cpp
+++ b/llvm/unittests/Support/NativeFormatTests.cpp
@@ -48,6 +48,8 @@ std::string format_number(double D, FloatStyle Style,
TEST(NativeFormatTest, BasicIntegerTests) {
// Simple integers with no decimal.
EXPECT_EQ("0", format_number(0, IntegerStyle::Integer));
+ EXPECT_EQ("1", format_number(1, IntegerStyle::Integer));
+ EXPECT_EQ("-1", format_number(-1, IntegerStyle::Integer));
EXPECT_EQ("2425", format_number(2425, IntegerStyle::Integer));
EXPECT_EQ("-2425", format_number(-2425, IntegerStyle::Integer));
More information about the llvm-commits
mailing list