diff options
author | Tim Schumacher <timschumi@gmx.de> | 2022-04-09 02:24:59 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-04-14 03:12:56 +0430 |
commit | 0d5098fdc00d17a4ba1ee43f26abf129f9a4cb70 (patch) | |
tree | 34cbb5dfc5d136924d706d7503a7f93490d202d6 /AK | |
parent | 399202f1d32c84985f3a42d8f44eb192ce17ad67 (diff) | |
download | serenity-0d5098fdc00d17a4ba1ee43f26abf129f9a4cb70.zip |
AK: Merge print_i64 into print_signed_number
Those functions only differ by the input type of `number`. No other
wrapper does this, as they rely on adjusting the type of the argument on
the caller side instead.
Avoid specializing too much by just doing the same for signed numbers.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/PrintfImplementation.h | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/AK/PrintfImplementation.h b/AK/PrintfImplementation.h index eb344c5eb8..d201d01b79 100644 --- a/AK/PrintfImplementation.h +++ b/AK/PrintfImplementation.h @@ -211,12 +211,6 @@ ALWAYS_INLINE int print_double(PutChFunc putch, CharType*& bufptr, double number } template<typename PutChFunc, typename CharType> -ALWAYS_INLINE int print_i64(PutChFunc putch, CharType*& bufptr, i64 number, bool always_sign, bool left_pad, bool zero_pad, u32 field_width, bool has_precision, u32 precision) -{ - return print_decimal(putch, bufptr, (number < 0) ? 0 - number : number, number < 0, always_sign, left_pad, zero_pad, field_width, has_precision, precision); -} - -template<typename PutChFunc, typename CharType> ALWAYS_INLINE int print_octal_number(PutChFunc putch, CharType*& bufptr, u64 number, bool alternate_form, bool left_pad, bool zero_pad, u32 field_width, bool has_precision, u32 precision) { u32 divisor = 134217728; @@ -307,8 +301,9 @@ ALWAYS_INLINE int print_string(PutChFunc putch, CharType*& bufptr, T str, size_t } template<typename PutChFunc, typename CharType> -ALWAYS_INLINE int print_signed_number(PutChFunc putch, CharType*& bufptr, int number, bool always_sign, bool left_pad, bool zero_pad, u32 field_width, bool has_precision, u32 precision) +ALWAYS_INLINE int print_signed_number(PutChFunc putch, CharType*& bufptr, i64 number, bool always_sign, bool left_pad, bool zero_pad, u32 field_width, bool has_precision, u32 precision) { + // FIXME: `0 - number` overflows if we are trying to negate the smallest possible value. return print_decimal(putch, bufptr, (number < 0) ? 0 - number : number, number < 0, always_sign, left_pad, zero_pad, field_width, has_precision, precision); } @@ -359,7 +354,7 @@ struct PrintfImpl { ALWAYS_INLINE int format_d(ModifierState const& state, ArgumentListRefT ap) const { if (state.long_qualifiers >= 2) - return print_i64(m_putch, m_bufptr, NextArgument<i64>()(ap), state.always_sign, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); + return print_signed_number(m_putch, m_bufptr, NextArgument<i64>()(ap), state.always_sign, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); return print_signed_number(m_putch, m_bufptr, NextArgument<int>()(ap), state.always_sign, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); } |