-
Notifications
You must be signed in to change notification settings - Fork 30k
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
repl: use String#repeat instead of Array#join #3900
Conversation
LGTM, evidence of said perf would be nice of course. |
In the common case here: This is testing:
String#repeat 14.5 ns/op |
LGTM. The speedup is nice. Not sure how important it is in the REPL. |
The advantage is the speedup in showing the prompt IMO |
I don't think anyone will perceive < 1us :-) It's still nice to know for more performance critical places. |
yea, true |
It seems that the only place where this pattern emerged is in repl.js, unless my grep is not revealing enough.
|
var levelInd = new Array(this.lines.level.length).join('..'); | ||
const len = this.lines.level.length | ||
? this.lines.level.length - 1 | ||
: 0; |
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 could fit on a single line.
LGTM with style nit. By the way: https://jsperf.com/string-repeat-native-vs-array-join-vs-loop |
2fd7627
to
6845a40
Compare
Fixed the nit |
self.lines.push(new Array(self.lines.level.length).join(' ') + cmd); | ||
const len = self.lines.level.length | ||
? self.lines.level.length - 1 | ||
: 0; |
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.
Please this one too :)
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.
ahh missed that one. Fixed
6845a40
to
c8ab7e1
Compare
CI is happy, let's land it! |
k, landing now |
String#repeat is quite a bit faster than new Array().join(). PR-URL: nodejs#3900 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
c8ab7e1
to
50125e2
Compare
Landed in 50125e2. Thanks! |
String#repeat is quite a bit faster than new Array().join(). PR-URL: nodejs#3900 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
String#repeat is quite a bit faster than new Array().join(). PR-URL: nodejs#3900 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
String#repeat is quite a bit faster than new Array().join(). PR-URL: #3900 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
String#repeat is quite a bit faster than new Array().join(). PR-URL: #3900 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
String#repeat is quite a bit faster than new Array().join(). PR-URL: nodejs#3900 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
String#repeat is quite a bit faster than new Array().join().