Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes character rendering by eliminating per-iteration String allocations and using direct char access for display.
- Introduce a
const char*pointer to buffer data and extract each character directly - Replace
String.substringandcanvas.printfcalls withcanvas.write(ch) - Remove temporary
Stringobjects in the print loop
Comments suppressed due to low confidence (3)
src/main.cpp:204
- Consider using
buffer.length()(orbuffer.size()) instead of the externallenvariable to ensure you iterate over the actual string length and avoid potential out-of-bounds access.
for (int i = 0; i < len; i++)
src/main.cpp:202
- [nitpick] The variable name
cstris ambiguous; consider renaming it to something more descriptive, likebufferCharsordataPtr, to clarify its purpose.
const char *cstr = buffer.c_str();
src/main.cpp:201
- [nitpick] The variable
countcould be renamed toprintedCountor similar to better convey that it tracks the number of characters printed.
int count = 0;
| // 1文字づつ表示 | ||
| String str = buffer.substring(i, i + 1); | ||
| char ch = cstr[i]; | ||
|
|
There was a problem hiding this comment.
[nitpick] Consider adding a comment to explain why spaces and question marks are skipped here, improving code readability for future maintainers.
Suggested change
| // Skip spaces and question marks to avoid unnecessary sound effects or visual updates. |
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the task_print function by replacing per-character String allocations with direct buffer access and a single-character write call to improve rendering speed.
- Introduces a
const char*pointer to the string data - Replaces
String.substringwith indexing into the C-string - Switches from
canvas.printftocanvas.writefor single-character output
Comments suppressed due to low confidence (3)
src/main.cpp:202
- [nitpick] The variable name
cstris generic; consider renaming tobuffer_cstrortextPtrto improve readability and clarify its relationship tobuffer.
const char *cstr = buffer.c_str();
src/main.cpp:206
- Indexing into a C-string may split multi-byte/UTF-8 characters, leading to rendering errors. Consider using a method that respects character boundaries (e.g.,
substring(i, i + 1)) or iterate with a Unicode-aware iterator.
char ch = cstr[i];
src/main.cpp:202
- The loop uses
lenbut it isn’t shown as being set tobuffer.length(). Ensurelenis defined assize_t len = buffer.length();after creatingbufferto avoid out-of-bounds access.
const char *cstr = buffer.c_str();
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StringobjectsTesting
git status --short