-
Notifications
You must be signed in to change notification settings - Fork 3
Optimize character rendering #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]; | ||
|
|
Copilot
AI
May 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider adding a comment to explain why spaces and question marks are skipped here, improving code readability for future maintainers.
| // Skip spaces and question marks to avoid unnecessary sound effects or visual updates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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();
Summary
StringobjectsTesting
git status --short