about summary refs log tree commit diff
path: root/absl/strings
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2017-12-12T19·23-0800
committerTitus Winters <titus@google.com>2017-12-12T19·25-0500
commit04edad3801ec0b1091df9157b879d8f6a50c5036 (patch)
tree58bbb0af82117ec59f79481468317a1ff244eaed /absl/strings
parentdc0282d09809f3337529fd790c57a92d63752451 (diff)
Changes imported from Abseil "staging" branch:
  - 46a4bd582619bfc4799c1a907316e914ed0c0105 Fixes to mutex_nonprod.  Apparently this has never built.... by Greg Falcon <gfalcon@google.com>
  - 4bcf6f013aeee53057527d70100de8535aec9b93 Add some comments to copts.bzl by Tom Manshreck <shreck@google.com>
  - 54cf717b1c5dfb814721f92a8eb9df5587f5f758 Internal change by Abseil Team <absl-team@google.com>
  - d1f1c7e6e61358300963b7bd50c203740a49297d Eliminate kFast{UInt,Int}{32,64}ToBufferSize constants by Jorg Brown <jorg@google.com>

GitOrigin-RevId: 46a4bd582619bfc4799c1a907316e914ed0c0105
Change-Id: I129b6b3d27d9ae2c6eb21d6e44a52d10399ef8aa
Diffstat (limited to 'absl/strings')
-rw-r--r--absl/strings/internal/numbers_test_common.inc10
-rw-r--r--absl/strings/numbers_test.cc35
2 files changed, 15 insertions, 30 deletions
diff --git a/absl/strings/internal/numbers_test_common.inc b/absl/strings/internal/numbers_test_common.inc
index e165b3bea5c6..81d2a1b70510 100644
--- a/absl/strings/internal/numbers_test_common.inc
+++ b/absl/strings/internal/numbers_test_common.inc
@@ -17,16 +17,6 @@
 
 namespace {
 
-// Previously documented minimum buffer sizes for Fast*ToBuffer functions.
-// NOTE(edk): These should be deleted and uses replaced with kFastToBufferSize
-//            once existing code has been fixed to use kFastToBufferSize.
-enum {
-  kFastInt32ToBufferSize = 12,
-  kFastInt64ToBufferSize = 22,
-  kFastUInt32ToBufferSize = 12,
-  kFastUInt64ToBufferSize = 22
-};
-
 template <typename IntType>
 bool Itoa(IntType value, int base, std::string* destination) {
   destination->clear();
diff --git a/absl/strings/numbers_test.cc b/absl/strings/numbers_test.cc
index 817604d78c7f..ff3120f5c57b 100644
--- a/absl/strings/numbers_test.cc
+++ b/absl/strings/numbers_test.cc
@@ -28,11 +28,6 @@
 
 namespace {
 
-using absl::numbers_internal::FastInt32ToBuffer;
-using absl::numbers_internal::FastInt64ToBuffer;
-using absl::numbers_internal::FastUInt32ToBuffer;
-using absl::numbers_internal::FastUInt64ToBuffer;
-using absl::numbers_internal::kFastToBufferSize;
 using absl::numbers_internal::kSixDigitsToBufferSize;
 using absl::numbers_internal::safe_strto32_base;
 using absl::numbers_internal::safe_strto64_base;
@@ -116,22 +111,22 @@ TEST(ToString, PerfectDtoa) {
 }
 
 void CheckInt32(int32_t x) {
-  char buffer[kFastInt32ToBufferSize];
-  char* actual = FastInt32ToBuffer(x, buffer);
+  char buffer[absl::numbers_internal::kFastToBufferSize];
+  char* actual = absl::numbers_internal::FastInt32ToBuffer(x, buffer);
   std::string expected = std::to_string(x);
-  ASSERT_TRUE(expected == actual)
+  ASSERT_TRUE(expected == std::string(buffer, actual))
       << "Expected \"" << expected << "\", Actual \"" << actual << "\", Input "
       << x;
 }
 
 void CheckInt64(int64_t x) {
-  char buffer[kFastInt64ToBufferSize + 3];
+  char buffer[absl::numbers_internal::kFastToBufferSize + 3];
   buffer[0] = '*';
   buffer[23] = '*';
   buffer[24] = '*';
-  char* actual = FastInt64ToBuffer(x, &buffer[1]);
+  char* actual = absl::numbers_internal::FastInt64ToBuffer(x, &buffer[1]);
   std::string expected = std::to_string(x);
-  ASSERT_TRUE(expected == actual)
+  ASSERT_TRUE(expected == std::string(&buffer[1], actual))
       << "Expected \"" << expected << "\", Actual \"" << actual << "\", Input "
       << x;
   ASSERT_EQ(buffer[0], '*');
@@ -140,32 +135,32 @@ void CheckInt64(int64_t x) {
 }
 
 void CheckUInt32(uint32_t x) {
-  char buffer[kFastUInt64ToBufferSize];
-  char* actual = FastUInt32ToBuffer(x, buffer);
+  char buffer[absl::numbers_internal::kFastToBufferSize];
+  char* actual = absl::numbers_internal::FastUInt32ToBuffer(x, buffer);
   std::string expected = std::to_string(x);
-  ASSERT_TRUE(expected == actual)
+  ASSERT_TRUE(expected == std::string(buffer, actual))
       << "Expected \"" << expected << "\", Actual \"" << actual << "\", Input "
       << x;
 }
 
 void CheckUInt64(uint64_t x) {
-  char buffer[kFastUInt64ToBufferSize + 1];
-  char* actual = FastUInt64ToBuffer(x, &buffer[1]);
+  char buffer[absl::numbers_internal::kFastToBufferSize + 1];
+  char* actual = absl::numbers_internal::FastUInt64ToBuffer(x, &buffer[1]);
   std::string expected = std::to_string(x);
-  ASSERT_TRUE(expected == actual)
+  ASSERT_TRUE(expected == std::string(&buffer[1], actual))
       << "Expected \"" << expected << "\", Actual \"" << actual << "\", Input "
       << x;
 }
 
 void CheckHex64(uint64_t v) {
-  char expected[kFastUInt64ToBufferSize];
+  char expected[16 + 1];
   std::string actual = absl::StrCat(absl::Hex(v, absl::kZeroPad16));
   snprintf(expected, sizeof(expected), "%016" PRIx64, static_cast<uint64_t>(v));
   ASSERT_TRUE(expected == actual)
       << "Expected \"" << expected << "\", Actual \"" << actual << "\"";
 }
 
-void TestFastPrints() {
+TEST(Numbers, TestFastPrints) {
   for (int i = -100; i <= 100; i++) {
     CheckInt32(i);
     CheckInt64(i);
@@ -700,7 +695,7 @@ class SimpleDtoaTest : public testing::Test {
   }
 
   std::string ToNineDigits(double value) {
-    char buffer[kFastToBufferSize];  // more than enough for %.9g
+    char buffer[16];  // more than enough for %.9g
     snprintf(buffer, sizeof(buffer), "%.9g", value);
     return buffer;
   }