-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
strings, builtin: remove strings.Builder.clear()
, fix array.clear()
not working in the JS backend
#23992
strings, builtin: remove strings.Builder.clear()
, fix array.clear()
not working in the JS backend
#23992
Conversation
Connected to Huly®: V_0.6-22385 |
Seems there are some problems on the js backend 🤔 convert to draft for now |
b50df63
to
bf37b2d
Compare
bf37b2d
to
7916510
Compare
There seems to be no |
strings.Builder.clear()
strings.Builder.clear()
, fix array.clear()
not working in the JS backend
What was the initial motivation for this change? |
Initially it was a performance improvement to avoid reallocations when clearing string builders, and later I thought it would be more readable to use |
Thank you 🙇🏻 . |
With -prod, it is consistently faster:
Without -prod (with tcc), it is consistently a bit slower (~0.5%) on my machine, which I do not understand fully yet. |
In any case, the code is simpler now, so excellent work 🙇🏻♂️ . |
Currently,
strings.Builder
has a function namedclear()
which clears the content by reallocating the backing array.However, there is no need to reallocate the array. For example, in
str()
function, the backing array is simply trimmed to zero length.Also, the array type itself has a
clear()
function which does the same astrim(0)
. This PR reuses theclear()
function in thearray
by simply removing theclear()
function instrings.Builder
and replacingtrim(0)
withclear()
which does the same thing.This PR shouldn't break existing code