Index: base/strings/string_number_conversions.cc |
diff --git a/base/strings/string_number_conversions.cc b/base/strings/string_number_conversions.cc |
index 16d98c8a3e9d4deb4655f75b31e052f2cacf459c..0a237cecf59d3e72f8cbddccad5cd9fdf7dc2647 100644 |
--- a/base/strings/string_number_conversions.cc |
+++ b/base/strings/string_number_conversions.cc |
@@ -27,30 +27,31 @@ struct IntToStringT { |
static STR IntToString(INT value) { |
// log10(2) ~= 0.3 bytes needed per bit or per byte log10(2**8) ~= 2.4. |
// So round up to allocate 3 output characters per byte, plus 1 for '-'. |
- const int kOutputBufSize = |
+ const size_t kOutputBufSize = |
3 * sizeof(INT) + std::numeric_limits<INT>::is_signed; |
- // Allocate the whole string right away, we will right back to front, and |
+ // Create the string in a temporary buffer, write it back to front, and |
// then return the substr of what we ended up using. |
- STR outbuf(kOutputBufSize, 0); |
+ typedef typename STR::value_type CHR; |
Mark Mentovai
2015/09/25 15:35:28
https://chromium-cpp.appspot.com/: use “using CHR
Adam Rice
2015/09/25 17:35:36
Done.
|
+ CHR outbuf[kOutputBufSize]; |
// The ValueOrDie call below can never fail, because UnsignedAbs is valid |
// for all valid inputs. |
auto res = CheckedNumeric<INT>(value).UnsignedAbs().ValueOrDie(); |
- typename STR::iterator it(outbuf.end()); |
+ CHR* i = outbuf + kOutputBufSize; |
Mark Mentovai
2015/09/25 15:35:27
You can save outbuf + kOutputBufSize in an “end” v
Adam Rice
2015/09/25 17:35:36
Done.
|
do { |
- --it; |
- DCHECK(it != outbuf.begin()); |
- *it = static_cast<typename STR::value_type>((res % 10) + '0'); |
+ --i; |
+ DCHECK(i != outbuf); |
+ *i = static_cast<CHR>((res % 10) + '0'); |
res /= 10; |
} while (res != 0); |
if (IsValueNegative(value)) { |
- --it; |
- DCHECK(it != outbuf.begin()); |
- *it = static_cast<typename STR::value_type>('-'); |
+ --i; |
+ DCHECK(i != outbuf); |
+ *i = static_cast<CHR>('-'); |
} |
- return STR(it, outbuf.end()); |
+ return STR(i, outbuf + kOutputBufSize); |
} |
}; |