diff options
author | Michael Jones <michaelrj@google.com> | 2023-07-11 15:06:08 -0700 |
---|---|---|
committer | Michael Jones <michaelrj@google.com> | 2023-07-18 16:30:57 -0700 |
commit | 4d4e18f4ac675bf60b06f6518e56145e18d28026 (patch) | |
tree | afd8da58628c698132acca36765d7f597aab0f2b /libc | |
parent | 2ff8094e328001b37eda8c71306c557b842955ae (diff) | |
download | llvm-4d4e18f4ac675bf60b06f6518e56145e18d28026.zip llvm-4d4e18f4ac675bf60b06f6518e56145e18d28026.tar.gz llvm-4d4e18f4ac675bf60b06f6518e56145e18d28026.tar.bz2 |
[libc][NFC] reuse variable in printf string conv
The amount of spaces to pad with is stored in the variable
padding_spaces, previously the actual write calls used the same formula
to calculate the value. This simplifies and clarifies the values by just
reusing the variable.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D155113
Diffstat (limited to 'libc')
-rw-r--r-- | libc/src/stdio/printf_core/char_converter.h | 4 | ||||
-rw-r--r-- | libc/src/stdio/printf_core/string_converter.h | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/libc/src/stdio/printf_core/char_converter.h b/libc/src/stdio/printf_core/char_converter.h index f75bc81..ffd2422 100644 --- a/libc/src/stdio/printf_core/char_converter.h +++ b/libc/src/stdio/printf_core/char_converter.h @@ -29,7 +29,7 @@ LIBC_INLINE int convert_char(Writer *writer, const FormatSection &to_conv) { // If the padding is on the left side, write the spaces first. if (padding_spaces > 0 && (to_conv.flags & FormatFlags::LEFT_JUSTIFIED) == 0) { - RET_IF_RESULT_NEGATIVE(writer->write(' ', to_conv.min_width - string_len)); + RET_IF_RESULT_NEGATIVE(writer->write(' ', padding_spaces)); } RET_IF_RESULT_NEGATIVE(writer->write(c)); @@ -37,7 +37,7 @@ LIBC_INLINE int convert_char(Writer *writer, const FormatSection &to_conv) { // If the padding is on the right side, write the spaces last. if (padding_spaces > 0 && (to_conv.flags & FormatFlags::LEFT_JUSTIFIED) != 0) { - RET_IF_RESULT_NEGATIVE(writer->write(' ', to_conv.min_width - string_len)); + RET_IF_RESULT_NEGATIVE(writer->write(' ', padding_spaces)); } return WRITE_OK; diff --git a/libc/src/stdio/printf_core/string_converter.h b/libc/src/stdio/printf_core/string_converter.h index 59e98e2..137bac6 100644 --- a/libc/src/stdio/printf_core/string_converter.h +++ b/libc/src/stdio/printf_core/string_converter.h @@ -39,7 +39,7 @@ LIBC_INLINE int convert_string(Writer *writer, const FormatSection &to_conv) { // If the padding is on the left side, write the spaces first. if (padding_spaces > 0 && (to_conv.flags & FormatFlags::LEFT_JUSTIFIED) == 0) { - RET_IF_RESULT_NEGATIVE(writer->write(' ', to_conv.min_width - string_len)); + RET_IF_RESULT_NEGATIVE(writer->write(' ', padding_spaces)); } RET_IF_RESULT_NEGATIVE(writer->write( @@ -48,7 +48,7 @@ LIBC_INLINE int convert_string(Writer *writer, const FormatSection &to_conv) { // If the padding is on the right side, write the spaces last. if (padding_spaces > 0 && (to_conv.flags & FormatFlags::LEFT_JUSTIFIED) != 0) { - RET_IF_RESULT_NEGATIVE(writer->write(' ', to_conv.min_width - string_len)); + RET_IF_RESULT_NEGATIVE(writer->write(' ', padding_spaces)); } return WRITE_OK; } |