From fbfa378e74e8f71809f4912d198a4f63c15433f0 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 9 Apr 2022 02:44:25 +0200 Subject: [PATCH] AK: Deduplicate formatting hexadecimal values Both calls essentially only differ in one boolean, which dictates whether to print the value in uppercase or lowercase. Move the long function call into a new function and pass in the "uppercase" boolean seperately to avoid having to write everything twice. --- AK/PrintfImplementation.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/AK/PrintfImplementation.h b/AK/PrintfImplementation.h index d201d01b79..b67cdeab6a 100644 --- a/AK/PrintfImplementation.h +++ b/AK/PrintfImplementation.h @@ -388,17 +388,19 @@ struct PrintfImpl { { return print_octal_number(m_putch, m_bufptr, NextArgument()(ap), state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); } - ALWAYS_INLINE int format_x(ModifierState const& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_unsigned_hex(ModifierState const& state, ArgumentListRefT ap, bool uppercase) const { if (state.long_qualifiers >= 2) - return print_hex(m_putch, m_bufptr, NextArgument()(ap), false, state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); - return print_hex(m_putch, m_bufptr, NextArgument()(ap), false, state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); + return print_hex(m_putch, m_bufptr, NextArgument()(ap), uppercase, state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); + return print_hex(m_putch, m_bufptr, NextArgument()(ap), uppercase, state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); + } + ALWAYS_INLINE int format_x(ModifierState const& state, ArgumentListRefT ap) const + { + return format_unsigned_hex(state, ap, false); } ALWAYS_INLINE int format_X(ModifierState const& state, ArgumentListRefT ap) const { - if (state.long_qualifiers >= 2) - return print_hex(m_putch, m_bufptr, NextArgument()(ap), true, state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); - return print_hex(m_putch, m_bufptr, NextArgument()(ap), true, state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); + return format_unsigned_hex(state, ap, true); } ALWAYS_INLINE int format_n(ModifierState const&, ArgumentListRefT ap) const {