-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Optimize String::chr
to avoid calling strlen
. Use String::chr
instead of String(&chr, 1)
where appropriate.
#100314
Conversation
ea52c54
to
8ea5f58
Compare
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.
Small one, but avoiding a useless function call is good.
8ea5f58
to
8cc53c5
Compare
…nstead of `String(&chr, 1)` where appropriate.
8cc53c5
to
2aeca3e
Compare
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.
Prerequisite to #104049, and makes complete sense in isolation.
Thanks! |
char32_t c[2] = { p_char, 0 }; | ||
return String(c); |
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.
This seems to be equivalent to
string.parse_utf32(Span<char32_t>(&p_char, 1));
rather than
string.parse_utf32(p_char);
Use 0
as the end mark.
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.
Not exactly. The old implementation would have converted a NUL
char to a zero-size string, while the new one will complain about it. This is also true for the string.parse_utf32(Span<char32_t>(&p_char, 1));
version.
This is a small refactor to get rid of 3 uses of
String(ptr, len)
(which I'm planning to delete entirely, because it's inefficient). I also makeString::chr
inlineable because the function is trivial, and having it in thecpp
file is unnecessary.It's technically a tiny improvement too since the resulting code is faster and can be better optimized by the compiler. But it should be considered a refactor.