From 5be9a8de3f068c166a82e9a7bbf93e63b8494da5 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 21 Jun 2014 09:40:04 -0700 Subject: [PATCH] Reduce the number of integer types that need to be handled. --- format.cc | 26 +------------------------- format.h | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/format.cc b/format.cc index 5c30f9e5..9d99ea37 100644 --- a/format.cc +++ b/format.cc @@ -507,10 +507,6 @@ fmt::ULongLong fmt::BasicWriter::GetIntValue(const ArgInfo &arg) { return arg.int_value; case UINT: return arg.uint_value; - case LONG: - return arg.long_value; - case ULONG: - return arg.ulong_value; case LONG_LONG: return arg.long_long_value; case ULONG_LONG: @@ -556,7 +552,7 @@ void fmt::BasicWriter::FormatParser::CheckSign( report_error_(s, fmt::Format("format specifier '{}' requires numeric argument") << sign); } - if (arg.type == UINT || arg.type == ULONG || arg.type == ULONG_LONG) { + if (arg.type == UINT || arg.type == ULONG_LONG) { report_error_(s, fmt::Format("format specifier '{}' requires signed argument") << sign); } @@ -767,12 +763,6 @@ void fmt::BasicWriter::PrintfParser::Format( case UINT: writer.FormatInt(arg.uint_value, spec); break; - case LONG: - writer.FormatInt(arg.long_value, spec); - break; - case ULONG: - writer.FormatInt(arg.ulong_value, spec); - break; case LONG_LONG: writer.FormatInt(arg.long_long_value, spec); break; @@ -963,14 +953,6 @@ void fmt::BasicWriter::FormatParser::Format( case UINT: value = precision_arg.uint_value; break; - case LONG: - if (precision_arg.long_value < 0) - report_error_(s, "negative precision in format"); - value = precision_arg.long_value; - break; - case ULONG: - value = precision_arg.ulong_value; - break; case LONG_LONG: if (precision_arg.long_long_value < 0) report_error_(s, "negative precision in format"); @@ -1014,12 +996,6 @@ void fmt::BasicWriter::FormatParser::Format( case UINT: writer.FormatInt(arg.uint_value, spec); break; - case LONG: - writer.FormatInt(arg.long_value, spec); - break; - case ULONG: - writer.FormatInt(arg.ulong_value, spec); - break; case LONG_LONG: writer.FormatInt(arg.long_long_value, spec); break; diff --git a/format.h b/format.h index 34511e83..37f6980d 100644 --- a/format.h +++ b/format.h @@ -891,11 +891,10 @@ class BasicWriter { void operator<<(typename internal::CharTraits::UnsupportedStrType); enum Type { - // Numeric types should go first. - INT, UINT, LONG, ULONG, LONG_LONG, ULONG_LONG, - LAST_INTEGER_TYPE = ULONG_LONG, - DOUBLE, LONG_DOUBLE, - LAST_NUMERIC_TYPE = LONG_DOUBLE, + // Integer types should go first, + INT, UINT, LONG_LONG, ULONG_LONG, LAST_INTEGER_TYPE = ULONG_LONG, + // followed by floating-point types. + DOUBLE, LONG_DOUBLE, LAST_NUMERIC_TYPE = LONG_DOUBLE, CHAR, STRING, WSTRING, POINTER, CUSTOM }; @@ -920,8 +919,6 @@ class BasicWriter { int int_value; unsigned uint_value; double double_value; - long long_value; - unsigned long ulong_value; LongLong long_long_value; ULongLong ulong_long_value; long double long_double_value; @@ -962,8 +959,24 @@ class BasicWriter { BasicArg(unsigned short value) { type = UINT; this->int_value = value; } BasicArg(int value) { type = INT; this->int_value = value; } BasicArg(unsigned value) { type = UINT; this->uint_value = value; } - BasicArg(long value) { type = LONG; this->long_value = value; } - BasicArg(unsigned long value) { type = ULONG; this->ulong_value = value; } + BasicArg(long value) { + if (sizeof(long) == sizeof(int)) { + type = INT; + this->int_value = static_cast(value); + } else { + type = LONG_LONG; + this->long_long_value = value; + } + } + BasicArg(unsigned long value) { + if (sizeof(unsigned long) == sizeof(unsigned)) { + type = UINT; + this->uint_value = static_cast(value); + } else { + type = ULONG_LONG; + this->ulong_long_value = value; + } + } BasicArg(LongLong value) { type = LONG_LONG; this->long_long_value = value;