numeric/str: Improve base10 encode performance
This adds a generic mechanism for coalescing writes into multi-digit
chunks in order to reduce the number of division operations that
bottleneck the encoding process.
Change-Id: Iaf0967b2a44820c75cad73390b81a6a53d97b27a
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/numeric/str.cpp b/test/numeric/str.cpp
index 5646045..008cbe5 100644
--- a/test/numeric/str.cpp
+++ b/test/numeric/str.cpp
@@ -10,7 +10,7 @@
TEST(IntToStr, Uint8_10)
{
IntToStr<10, uint8_t> enc;
- static_assert(enc.buf_size == 3);
+ static_assert(enc.buf_size == 4);
char buf[enc.buf_size];
EXPECT_EQ("0", std::string_view(buf, enc(buf, 0)));
EXPECT_EQ("42", std::string_view(buf, enc(buf, 42)));
@@ -22,7 +22,7 @@
TEST(IntToStr, Int8_10)
{
IntToStr<10, int8_t> enc;
- static_assert(enc.buf_size == 4);
+ static_assert(enc.buf_size == 5);
char buf[enc.buf_size];
EXPECT_EQ("42", std::string_view(buf, enc(buf, 42)));
EXPECT_EQ("-127", std::string_view(buf, enc(buf, -127)));
@@ -31,7 +31,7 @@
TEST(IntToStr, Uint16_10)
{
IntToStr<10, uint16_t> enc;
- static_assert(enc.buf_size == 5);
+ static_assert(enc.buf_size == 6);
char buf[enc.buf_size];
EXPECT_EQ("55255", std::string_view(buf, enc(buf, 55255, 3)));
}