From 0d5098fdc00d17a4ba1ee43f26abf129f9a4cb70 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 9 Apr 2022 02:24:59 +0200 Subject: [PATCH] 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. --- AK/PrintfImplementation.h | 11 +++-------- 1 file 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 @@ -210,12 +210,6 @@ ALWAYS_INLINE int print_double(PutChFunc putch, CharType*& bufptr, double number return length; } -template -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 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) { @@ -307,8 +301,9 @@ ALWAYS_INLINE int print_string(PutChFunc putch, CharType*& bufptr, T str, size_t } template -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()(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()(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()(ap), state.always_sign, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); }