Commit 8a1b239c by Abseil Team Committed by Copybara-Service

Remove two_ASCII_digits and replace with a scalar algorithm

PiperOrigin-RevId: 539900072
Change-Id: I675386e3184f6f5ab70b851add970c91d1dde9c5
parent 77111e3d
...@@ -113,27 +113,29 @@ size_t FormatBoundedFields(absl::LogSeverity severity, absl::Time timestamp, ...@@ -113,27 +113,29 @@ size_t FormatBoundedFields(absl::LogSeverity severity, absl::Time timestamp,
char* p = buf.data(); char* p = buf.data();
*p++ = absl::LogSeverityName(severity)[0]; *p++ = absl::LogSeverityName(severity)[0];
const absl::TimeZone::CivilInfo ci = tz->At(timestamp); const absl::TimeZone::CivilInfo ci = tz->At(timestamp);
absl::numbers_internal::PutTwoDigits(static_cast<size_t>(ci.cs.month()), p); absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(ci.cs.month()), p);
p += 2; p += 2;
absl::numbers_internal::PutTwoDigits(static_cast<size_t>(ci.cs.day()), p); absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(ci.cs.day()), p);
p += 2; p += 2;
*p++ = ' '; *p++ = ' ';
absl::numbers_internal::PutTwoDigits(static_cast<size_t>(ci.cs.hour()), p); absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(ci.cs.hour()), p);
p += 2; p += 2;
*p++ = ':'; *p++ = ':';
absl::numbers_internal::PutTwoDigits(static_cast<size_t>(ci.cs.minute()), p); absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(ci.cs.minute()),
p);
p += 2; p += 2;
*p++ = ':'; *p++ = ':';
absl::numbers_internal::PutTwoDigits(static_cast<size_t>(ci.cs.second()), p); absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(ci.cs.second()),
p);
p += 2; p += 2;
*p++ = '.'; *p++ = '.';
const int64_t usecs = absl::ToInt64Microseconds(ci.subsecond); const int64_t usecs = absl::ToInt64Microseconds(ci.subsecond);
absl::numbers_internal::PutTwoDigits(static_cast<size_t>(usecs / 10000), p); absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(usecs / 10000), p);
p += 2; p += 2;
absl::numbers_internal::PutTwoDigits(static_cast<size_t>(usecs / 100 % 100), absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(usecs / 100 % 100),
p); p);
p += 2; p += 2;
absl::numbers_internal::PutTwoDigits(static_cast<size_t>(usecs % 100), p); absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(usecs % 100), p);
p += 2; p += 2;
*p++ = ' '; *p++ = ' ';
PutLeadingWhitespace(tid, p); PutLeadingWhitespace(tid, p);
......
...@@ -106,7 +106,7 @@ class IntDigits { ...@@ -106,7 +106,7 @@ class IntDigits {
char *p = storage_ + sizeof(storage_); char *p = storage_ + sizeof(storage_);
do { do {
p -= 2; p -= 2;
numbers_internal::PutTwoDigits(static_cast<size_t>(v % 100), p); numbers_internal::PutTwoDigits(static_cast<uint32_t>(v % 100), p);
v /= 100; v /= 100;
} while (v); } while (v);
if (p[0] == '0') { if (p[0] == '0') {
......
...@@ -242,6 +242,15 @@ inline char* EncodeFullU32(uint32_t n, char* out_str) { ...@@ -242,6 +242,15 @@ inline char* EncodeFullU32(uint32_t n, char* out_str) {
} // namespace } // namespace
void numbers_internal::PutTwoDigits(uint32_t i, char* buf) {
assert(i < 100);
uint32_t base = kTwoZeroBytes;
uint32_t div10 = (i * kDivisionBy10Mul) / kDivisionBy10Div;
uint32_t mod10 = i - 10u * div10;
base += div10 + (mod10 << 8);
little_endian::Store16(buf, static_cast<uint16_t>(base));
}
char* numbers_internal::FastIntToBuffer(uint32_t n, char* out_str) { char* numbers_internal::FastIntToBuffer(uint32_t n, char* out_str) {
if (n < 100) { if (n < 100) {
out_str = EncodeHundred(n, out_str); out_str = EncodeHundred(n, out_str);
...@@ -1090,25 +1099,6 @@ ABSL_CONST_INIT ABSL_DLL const char kHexTable[513] = ...@@ -1090,25 +1099,6 @@ ABSL_CONST_INIT ABSL_DLL const char kHexTable[513] =
"e0e1e2e3e4e5e6e7e8e9eaebecedeeef" "e0e1e2e3e4e5e6e7e8e9eaebecedeeef"
"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"; "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
ABSL_CONST_INIT ABSL_DLL const char two_ASCII_digits[100][2] = {
{'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'}, {'0', '5'},
{'0', '6'}, {'0', '7'}, {'0', '8'}, {'0', '9'}, {'1', '0'}, {'1', '1'},
{'1', '2'}, {'1', '3'}, {'1', '4'}, {'1', '5'}, {'1', '6'}, {'1', '7'},
{'1', '8'}, {'1', '9'}, {'2', '0'}, {'2', '1'}, {'2', '2'}, {'2', '3'},
{'2', '4'}, {'2', '5'}, {'2', '6'}, {'2', '7'}, {'2', '8'}, {'2', '9'},
{'3', '0'}, {'3', '1'}, {'3', '2'}, {'3', '3'}, {'3', '4'}, {'3', '5'},
{'3', '6'}, {'3', '7'}, {'3', '8'}, {'3', '9'}, {'4', '0'}, {'4', '1'},
{'4', '2'}, {'4', '3'}, {'4', '4'}, {'4', '5'}, {'4', '6'}, {'4', '7'},
{'4', '8'}, {'4', '9'}, {'5', '0'}, {'5', '1'}, {'5', '2'}, {'5', '3'},
{'5', '4'}, {'5', '5'}, {'5', '6'}, {'5', '7'}, {'5', '8'}, {'5', '9'},
{'6', '0'}, {'6', '1'}, {'6', '2'}, {'6', '3'}, {'6', '4'}, {'6', '5'},
{'6', '6'}, {'6', '7'}, {'6', '8'}, {'6', '9'}, {'7', '0'}, {'7', '1'},
{'7', '2'}, {'7', '3'}, {'7', '4'}, {'7', '5'}, {'7', '6'}, {'7', '7'},
{'7', '8'}, {'7', '9'}, {'8', '0'}, {'8', '1'}, {'8', '2'}, {'8', '3'},
{'8', '4'}, {'8', '5'}, {'8', '6'}, {'8', '7'}, {'8', '8'}, {'8', '9'},
{'9', '0'}, {'9', '1'}, {'9', '2'}, {'9', '3'}, {'9', '4'}, {'9', '5'},
{'9', '6'}, {'9', '7'}, {'9', '8'}, {'9', '9'}};
bool safe_strto32_base(absl::string_view text, int32_t* value, int base) { bool safe_strto32_base(absl::string_view text, int32_t* value, int base) {
return safe_int_internal<int32_t>(text, value, base); return safe_int_internal<int32_t>(text, value, base);
} }
......
...@@ -125,8 +125,6 @@ namespace numbers_internal { ...@@ -125,8 +125,6 @@ namespace numbers_internal {
ABSL_DLL extern const char kHexChar[17]; // 0123456789abcdef ABSL_DLL extern const char kHexChar[17]; // 0123456789abcdef
ABSL_DLL extern const char ABSL_DLL extern const char
kHexTable[513]; // 000102030405060708090a0b0c0d0e0f1011... kHexTable[513]; // 000102030405060708090a0b0c0d0e0f1011...
ABSL_DLL extern const char
two_ASCII_digits[100][2]; // 00, 01, 02, 03...
// Writes a two-character representation of 'i' to 'buf'. 'i' must be in the // Writes a two-character representation of 'i' to 'buf'. 'i' must be in the
// range 0 <= i < 100, and buf must have space for two characters. Example: // range 0 <= i < 100, and buf must have space for two characters. Example:
...@@ -134,10 +132,7 @@ ABSL_DLL extern const char ...@@ -134,10 +132,7 @@ ABSL_DLL extern const char
// PutTwoDigits(42, buf); // PutTwoDigits(42, buf);
// // buf[0] == '4' // // buf[0] == '4'
// // buf[1] == '2' // // buf[1] == '2'
inline void PutTwoDigits(size_t i, char* buf) { void PutTwoDigits(uint32_t i, char* buf);
assert(i < 100);
memcpy(buf, two_ASCII_digits[i], 2);
}
// safe_strto?() functions for implementing SimpleAtoi() // safe_strto?() functions for implementing SimpleAtoi()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment