@ -181,16 +181,19 @@ char* FastIntToBuffer(int_type i, char* buffer) {
// TODO(jorg): This signed-ness check is used because it works correctly
// TODO(jorg): This signed-ness check is used because it works correctly
// with enums, and it also serves to check that int_type is not a pointer.
// with enums, and it also serves to check that int_type is not a pointer.
// If one day something like std::is_signed<enum E> works, switch to it.
// If one day something like std::is_signed<enum E> works, switch to it.
if ( static_cast < int_type > ( 1 ) - 2 < 0 ) { // Signed
// These conditions are constexpr bools to suppress MSVC warning C4127.
if ( sizeof ( i ) > 32 / 8 ) { // 33-bit to 64-bit
constexpr bool kIsSigned = static_cast < int_type > ( 1 ) - 2 < 0 ;
constexpr bool kUse64Bit = sizeof ( i ) > 32 / 8 ;
if ( kIsSigned ) {
if ( kUse64Bit ) {
return FastIntToBuffer ( static_cast < int64_t > ( i ) , buffer ) ;
return FastIntToBuffer ( static_cast < int64_t > ( i ) , buffer ) ;
} else { // 32-bit or less
} else {
return FastIntToBuffer ( static_cast < int32_t > ( i ) , buffer ) ;
return FastIntToBuffer ( static_cast < int32_t > ( i ) , buffer ) ;
}
}
} else { // Unsigned
} else {
if ( sizeof ( i ) > 32 / 8 ) { // 33-bit to 64-bit
if ( kUse64Bit ) {
return FastIntToBuffer ( static_cast < uint64_t > ( i ) , buffer ) ;
return FastIntToBuffer ( static_cast < uint64_t > ( i ) , buffer ) ;
} else { // 32-bit or less
} else {
return FastIntToBuffer ( static_cast < uint32_t > ( i ) , buffer ) ;
return FastIntToBuffer ( static_cast < uint32_t > ( i ) , buffer ) ;
}
}
}
}
@ -209,22 +212,25 @@ ABSL_MUST_USE_RESULT bool safe_strtoi_base(absl::string_view s, int_type* out,
// TODO(jorg): This signed-ness check is used because it works correctly
// TODO(jorg): This signed-ness check is used because it works correctly
// with enums, and it also serves to check that int_type is not a pointer.
// with enums, and it also serves to check that int_type is not a pointer.
// If one day something like std::is_signed<enum E> works, switch to it.
// If one day something like std::is_signed<enum E> works, switch to it.
if ( static_cast < int_type > ( 1 ) - 2 < 0 ) { // Signed
// These conditions are constexpr bools to suppress MSVC warning C4127.
if ( sizeof ( * out ) = = 64 / 8 ) { // 64-bit
constexpr bool kIsSigned = static_cast < int_type > ( 1 ) - 2 < 0 ;
constexpr bool kUse64Bit = sizeof ( * out ) = = 64 / 8 ;
if ( kIsSigned ) {
if ( kUse64Bit ) {
int64_t val ;
int64_t val ;
parsed = numbers_internal : : safe_strto64_base ( s , & val , base ) ;
parsed = numbers_internal : : safe_strto64_base ( s , & val , base ) ;
* out = static_cast < int_type > ( val ) ;
* out = static_cast < int_type > ( val ) ;
} else { // 32-bit
} else {
int32_t val ;
int32_t val ;
parsed = numbers_internal : : safe_strto32_base ( s , & val , base ) ;
parsed = numbers_internal : : safe_strto32_base ( s , & val , base ) ;
* out = static_cast < int_type > ( val ) ;
* out = static_cast < int_type > ( val ) ;
}
}
} else { // Unsigned
} else {
if ( sizeof ( * out ) = = 64 / 8 ) { // 64-bit
if ( kUse64Bit ) {
uint64_t val ;
uint64_t val ;
parsed = numbers_internal : : safe_strtou64_base ( s , & val , base ) ;
parsed = numbers_internal : : safe_strtou64_base ( s , & val , base ) ;
* out = static_cast < int_type > ( val ) ;
* out = static_cast < int_type > ( val ) ;
} else { // 32-bit
} else {
uint32_t val ;
uint32_t val ;
parsed = numbers_internal : : safe_strtou32_base ( s , & val , base ) ;
parsed = numbers_internal : : safe_strtou32_base ( s , & val , base ) ;
* out = static_cast < int_type > ( val ) ;
* out = static_cast < int_type > ( val ) ;