Commit 0f4133aa by Greg Falcon Committed by Copybara-Service

StrFormat() simplification: Treat %v unconditionally as %d when formatting integers.

This is a simplification but not a behavior change; we used to choose %u for unsigned ints, but %u and %d generate the same output for these types.

PiperOrigin-RevId: 539104599
Change-Id: I9d7ff561b969a6287889f95063636d6b77a4a78b
parent 163cade8
...@@ -278,24 +278,6 @@ bool ConvertIntImplInnerSlow(const IntDigits &as_digits, ...@@ -278,24 +278,6 @@ bool ConvertIntImplInnerSlow(const IntDigits &as_digits,
return true; return true;
} }
template <typename T,
typename std::enable_if<(std::is_integral<T>::value &&
std::is_signed<T>::value) ||
std::is_same<T, int128>::value,
int>::type = 0>
constexpr auto ConvertV(T) {
return FormatConversionCharInternal::d;
}
template <typename T,
typename std::enable_if<(std::is_integral<T>::value &&
std::is_unsigned<T>::value) ||
std::is_same<T, uint128>::value,
int>::type = 0>
constexpr auto ConvertV(T) {
return FormatConversionCharInternal::u;
}
template <typename T> template <typename T>
bool ConvertFloatArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl *sink) { bool ConvertFloatArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl *sink) {
if (conv.conversion_char() == FormatConversionCharInternal::v) { if (conv.conversion_char() == FormatConversionCharInternal::v) {
...@@ -332,10 +314,6 @@ bool ConvertIntArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl *sink) { ...@@ -332,10 +314,6 @@ bool ConvertIntArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl *sink) {
using U = typename MakeUnsigned<T>::type; using U = typename MakeUnsigned<T>::type;
IntDigits as_digits; IntDigits as_digits;
if (conv.conversion_char() == FormatConversionCharInternal::v) {
conv.set_conversion_char(ConvertV(T{}));
}
// This odd casting is due to a bug in -Wswitch behavior in gcc49 which causes // This odd casting is due to a bug in -Wswitch behavior in gcc49 which causes
// it to complain about a switch/case type mismatch, even though both are // it to complain about a switch/case type mismatch, even though both are
// FormatConverionChar. Likely this is because at this point // FormatConverionChar. Likely this is because at this point
...@@ -361,6 +339,7 @@ bool ConvertIntArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl *sink) { ...@@ -361,6 +339,7 @@ bool ConvertIntArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl *sink) {
case static_cast<uint8_t>(FormatConversionCharInternal::d): case static_cast<uint8_t>(FormatConversionCharInternal::d):
case static_cast<uint8_t>(FormatConversionCharInternal::i): case static_cast<uint8_t>(FormatConversionCharInternal::i):
case static_cast<uint8_t>(FormatConversionCharInternal::v):
as_digits.PrintAsDec(v); as_digits.PrintAsDec(v);
break; break;
......
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