The functions converting integers into decimal, hexadecimal, and octal,
are all very similar. This patch moves to a combined converter to save
code size.
Details
Details
- Reviewers
sivachandra lntue - Commits
- rG3510082a1c56: [libc] move to combined integer converter
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/src/stdio/printf_core/int_converter.h | ||
---|---|---|
71–85 | A way to avoid this ugliness would be to move this over to an inline function like this: cpp:optional<cpp::StringView> int_to_str(char conv_name) { if (to_lower(conv_name) == 'x') { return IntegerToString<uintmax_t, 16>::convert( num, bufref, is_lower(to_conv.conv_name)); } else if (conv_name == 'o') { return IntegerToString<uintmax_t, 8>::convert(num, bufref, true); } else { return IntegerToString<uintmax_t, 10>::convert(num, bufref, true); } } And then use it as: auto str = int_to_string(to_conv.conv_name); if (!str) return INT_CONVERSION_ERROR; Also, feel free to add operator-> to cpp:optional so that you can call str->size() and str->data(). |
libc/src/stdio/printf_core/int_converter.h | ||
---|---|---|
70 | Nit: just do if (!str) |
Nit: just do if (!str)