-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
test: use String.prototype.repeat() for clarity #5311
Conversation
@@ -19,7 +19,7 @@ var ucs2_control = 'a\u0000'; | |||
|
|||
// grow the strings to proper length | |||
while (ucs2_control.length <= EXTERN_APEX) { | |||
ucs2_control += ucs2_control; | |||
ucs2_control = ucs2_control.repeat(2); |
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.
How about skipping the while loop and doing
ucs2_control = ucs2_control.repeat(EXTERN_APEX / ucs2_control.length);
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.
That will loop until the string is just under length EXTERN_APEX but I think what we want is for it to loop until it exceeds EXTERN_APEX.
To fix that, you could simply add 1 to the number that results from the division. But by looping, I preserve the power of two length as well. That may not be significant, but I don't like to mess with crypto, so I did it this way so it was exactly the same.
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.
Fair enough.
LGTM. |
LGTM |
host += host; | ||
host += host; | ||
host += host; | ||
var host = '********'.repeat(32); |
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.
var host = '*'.repeat(256);
?
LGTM with a nit |
There are a few places where tests repeatedly concatenate strings to themselves in order to make them very long. Using `.repeat()` makes the code clearer. For example, before: for (var i = 0; i < 8; ++i) lots_of_headers += lots_of_headers; After: lots_of_headers = lots_of_headers.repeat(256); Using `.repeat()` makes it clear that the string will be repeated 256 times rather than 8 times. ("What?! That first one doesn't repeat 256 times! It only repeats 8... Oh, wait. Yes, I see your point now.")
c2d9dea
to
95cc99e
Compare
Applied nit from @jasnell, rebased against master, force pushed. |
LGTM! |
There are a few places where tests repeatedly concatenate strings to themselves in order to make them very long. Using `.repeat()` makes the code clearer. For example, before: for (var i = 0; i < 8; ++i) lots_of_headers += lots_of_headers; After: lots_of_headers = lots_of_headers.repeat(256); Using `.repeat()` makes it clear that the string will be repeated 256 times rather than 8 times. ("What?! That first one doesn't repeat 256 times! It only repeats 8... Oh, wait. Yes, I see your point now.") PR-URL: nodejs#5311 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Landed in 97f76f3 |
There are a few places where tests repeatedly concatenate strings to themselves in order to make them very long. Using `.repeat()` makes the code clearer. For example, before: for (var i = 0; i < 8; ++i) lots_of_headers += lots_of_headers; After: lots_of_headers = lots_of_headers.repeat(256); Using `.repeat()` makes it clear that the string will be repeated 256 times rather than 8 times. ("What?! That first one doesn't repeat 256 times! It only repeats 8... Oh, wait. Yes, I see your point now.") PR-URL: #5311 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
There are a few places where tests repeatedly concatenate strings to themselves in order to make them very long. Using `.repeat()` makes the code clearer. For example, before: for (var i = 0; i < 8; ++i) lots_of_headers += lots_of_headers; After: lots_of_headers = lots_of_headers.repeat(256); Using `.repeat()` makes it clear that the string will be repeated 256 times rather than 8 times. ("What?! That first one doesn't repeat 256 times! It only repeats 8... Oh, wait. Yes, I see your point now.") PR-URL: #5311 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
There are a few places where tests repeatedly concatenate strings to themselves in order to make them very long. Using `.repeat()` makes the code clearer. For example, before: for (var i = 0; i < 8; ++i) lots_of_headers += lots_of_headers; After: lots_of_headers = lots_of_headers.repeat(256); Using `.repeat()` makes it clear that the string will be repeated 256 times rather than 8 times. ("What?! That first one doesn't repeat 256 times! It only repeats 8... Oh, wait. Yes, I see your point now.") PR-URL: #5311 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
There are a few places where tests repeatedly concatenate strings to themselves in order to make them very long. Using `.repeat()` makes the code clearer. For example, before: for (var i = 0; i < 8; ++i) lots_of_headers += lots_of_headers; After: lots_of_headers = lots_of_headers.repeat(256); Using `.repeat()` makes it clear that the string will be repeated 256 times rather than 8 times. ("What?! That first one doesn't repeat 256 times! It only repeats 8... Oh, wait. Yes, I see your point now.") PR-URL: #5311 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
There are a few places where tests repeatedly concatenate strings to
themselves in order to make them very long. Using
.repeat()
makes thecode clearer.
For example, before:
After:
Using
.repeat()
makes it clear that the string will be repeated 256times rather than 8 times. ("What?! That first one doesn't repeat 256
times! It only repeats 8... Oh, wait. Yes, I see your point now.")