[libc-commits] [PATCH] D155113: [libc][NFC] reuse variable in printf string conv
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Wed Jul 12 13:14:40 PDT 2023
michaelrj created this revision.
michaelrj added reviewers: sivachandra, lntue.
Herald added projects: libc-project, All.
Herald added a subscriber: libc-commits.
michaelrj requested review of this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155113
Files:
libc/src/stdio/printf_core/char_converter.h
libc/src/stdio/printf_core/string_converter.h
Index: libc/src/stdio/printf_core/string_converter.h
===================================================================
--- libc/src/stdio/printf_core/string_converter.h
+++ libc/src/stdio/printf_core/string_converter.h
@@ -39,7 +39,7 @@
// 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 @@
// 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;
}
Index: libc/src/stdio/printf_core/char_converter.h
===================================================================
--- libc/src/stdio/printf_core/char_converter.h
+++ libc/src/stdio/printf_core/char_converter.h
@@ -29,7 +29,7 @@
// 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 @@
// 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155113.539701.patch
Type: text/x-patch
Size: 1871 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230712/71119574/attachment.bin>
More information about the libc-commits
mailing list