X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FFormat.cpp;h=db95ea24088f34aa4c57234cf37b90a76854253e;hb=5cef863eee8a03e1b6b137fb283d6fe703f35d2d;hp=64e2cae56273771f47e1423fa1e6d81d6e70ee3a;hpb=1ccc20a4d7164f621706f1f759ffec3e1a7b12a5;p=folly.git diff --git a/folly/Format.cpp b/folly/Format.cpp index 64e2cae5..db95ea24 100644 --- a/folly/Format.cpp +++ b/folly/Format.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ #include +#include + #include namespace folly { @@ -48,12 +50,14 @@ void FormatValue::formatHelper( } // 2+: for null terminator and optional sign shenanigans. - char buf[2 + std::max( - 2 + DoubleToStringConverter::kMaxFixedDigitsBeforePoint + - DoubleToStringConverter::kMaxFixedDigitsAfterPoint, - std::max(8 + DoubleToStringConverter::kMaxExponentialDigits, - 7 + DoubleToStringConverter::kMaxPrecisionDigits))]; - StringBuilder builder(buf + 1, static_cast (sizeof(buf) - 1)); + constexpr int bufLen = + 2 + constexpr_max( + 2 + DoubleToStringConverter::kMaxFixedDigitsBeforePoint + + DoubleToStringConverter::kMaxFixedDigitsAfterPoint, + constexpr_max(8 + DoubleToStringConverter::kMaxExponentialDigits, + 7 + DoubleToStringConverter::kMaxPrecisionDigits)); + char buf[bufLen]; + StringBuilder builder(buf + 1, bufLen - 1); char plusSign; switch (arg.sign) { @@ -155,7 +159,7 @@ void FormatValue::formatHelper( prefixLen = 1; } - piece = fbstring(p, len); + piece = fbstring(p, size_t(len)); } @@ -164,7 +168,7 @@ void FormatArg::initSlow() { auto end = fullArgString.end(); // Parse key - auto p = static_cast(memchr(b, ':', end - b)); + auto p = static_cast(memchr(b, ':', size_t(end - b))); if (!p) { key_ = StringPiece(b, end); return; @@ -210,11 +214,11 @@ void FormatArg::initSlow() { } auto readInt = [&] { - auto const b = p; + auto const c = p; do { ++p; } while (p != end && *p >= '0' && *p <= '9'); - return to(StringPiece(b, p)); + return to(StringPiece(c, p)); }; if (*p == '*') { @@ -238,12 +242,12 @@ void FormatArg::initSlow() { } if (*p == '.') { - auto b = ++p; + auto d = ++p; while (p != end && *p >= '0' && *p <= '9') { ++p; } - if (p != b) { - precision = to(StringPiece(b, p)); + if (p != d) { + precision = to(StringPiece(d, p)); if (p != end && *p == '.') { trailingDot = true; ++p; @@ -290,7 +294,7 @@ void FormatArg::validate(Type type) const { namespace detail { void insertThousandsGroupingUnsafe(char* start_buffer, char** end_buffer) { - uint32_t remaining_digits = *end_buffer - start_buffer; + uint32_t remaining_digits = uint32_t(*end_buffer - start_buffer); uint32_t separator_size = (remaining_digits - 1) / 3; uint32_t result_size = remaining_digits + separator_size; *end_buffer = *end_buffer + separator_size;