The FormatSection and the writer functions both previously took a char*
and a length to represent a string. Now they use the StringView class to
represent that more succinctly. This change also required fixing
everywhere these were used, so it touches a lot of files.
Details
- Reviewers
sivachandra lntue - Commits
- rG096463d08eaa: [libc] move printf to use StringViews
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/src/stdio/printf_core/char_converter.h | ||
---|---|---|
35 | Here and elsewhere, instead of calling the StringView constructor explicitly, can you do {&c, string_len}? | |
libc/src/stdio/printf_core/file_writer.h | ||
34–39 | While we are at it, we should make these static methods of FileWriter and simplify the names to write_str and write_chars. | |
libc/src/stdio/printf_core/string_writer.h | ||
41 | Make these static methods of StringWriter. | |
libc/src/stdio/printf_core/writer.h | ||
51 | Something we should have done earlier is to name all of these methods as just write. So, I think we should have: int write(cpp::StringView); int write(char c, size_t count); int write(char c); I am suggesting a separate write(char) to avoid calling, for example, memcpy to write a single char to a string buffer. Likewise, the FileWriter can implement a char writer by calling putc_unlocked when it is available. More importantly though, you will avoid the ugliness of writer->write(StringView(&some_char, 1)) at many places in this change. | |
libc/test/src/stdio/printf_core/parser_test.cpp | ||
57 | Can you do: expected.raw_string = {str, 4}; |
A comment about inconsistent usage of a pattern but good to go otherwise.
libc/test/src/stdio/printf_core/string_writer_test.cpp | ||
---|---|---|
36 | Can we follow the pattern of {"abc", 3} here and elsewhere in the patch. |
Here and elsewhere, instead of calling the StringView constructor explicitly, can you do {&c, string_len}?