-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Refactor String#to_utf16 optimizing for ascii-only #8526
Refactor String#to_utf16 optimizing for ascii-only #8526
Conversation
Do you have any benchmarks for this? |
Benchmark for 6a36aad string length 2000:
string length 10:
|
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.
Looks great!
src/string/utf16.cr
Outdated
size = 0 | ||
if ascii_only? | ||
# size == bytesize, so each char fits in one UInt16 | ||
return to_slice.map &.to_u16 |
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.
Oh, actually, this is missing the trailing null. I totally forgot about that! Sorry, maybe the other way was fine, or we just need to copy the values but add a trailing null somehow.
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.
Also, are there specs for these cases? They should have failed with this.
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.
Oh, right. There should be a spec for that.
No description provided.