-
Notifications
You must be signed in to change notification settings - Fork 103
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
improve stringbuilder::output #1730
base: main
Are you sure you want to change the base?
improve stringbuilder::output #1730
Conversation
Pull Request Test Coverage Report for Build 5532Details
💛 - Coveralls |
The improvement does not look obvious to me. Can you explain it? |
pub impl Show for StringBuilder with output(self, logger) { | ||
logger.write_string( | ||
self.data.unsafe_to_bytes().to_unchecked_string(offset=0, length=self.len), |
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.
to_unchecked_string
just simply copy bytes into string
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.
So basically you want avoid the extra copy here. My suggestion is that we should change the semantics of to_uncheck_string
since Bytes has become immutable. Then we can still enjoy the batch processing in write_string
.
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.
When using to_uncheck_string
with backends that require extra copies, such as the js backend and wasm-gc backend with the js-string-builtin
option turned on, use this implementation
for i = 0; i < self.len; i = i + 2 { | ||
let low = self.data[i].to_int() | ||
let high = self.data[i + 1].to_int() | ||
let code_unit = (high << 8) | low |> Char::from_int |
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 code_unit
is the same as String::op_get
's result
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.
convert two bytes to code_unit, like convert char*
into uint16_t*
then use pointer read data.
No description provided.