-
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
lib: remove duplicated code #19076
lib: remove duplicated code #19076
Conversation
lib/internal/url.js
Outdated
const firstEncodedParam = encodeStr(array[0], noEscape, paramHexTable); | ||
const firstEncodedValue = encodeStr(array[1], noEscape, paramHexTable); | ||
let output = | ||
`${firstEncodedParam}=${firstEncodedValue}`; |
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.
Why the line break here?
lib/querystring.js
Outdated
if (lastPos < str.length) | ||
return out + str.slice(lastPos); | ||
return out; | ||
return encodeStr(str, noEscape, hexTable, { |
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.
Did you benchmark this change?
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 change might have some negative effects on performance. Could you run a benchmark for this ?
lib/internal/url.js
Outdated
@@ -3,7 +3,8 @@ | |||
const util = require('util'); | |||
const { | |||
hexTable, | |||
isHexTable | |||
isHexTable, | |||
encodeStr, |
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.
Unexpected trailing comma. Remember to run lint before commit: make lint
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.
@starkwang I did it. And everything was ok:
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.
@starkwang we had this rule for trailing comma
'comma-dangle': ['error', 'only-multiline']
It allows using trailing comma. But maybe we should fix this rule. What do you think?
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 sorry, I misunderstood the meaning of 'only-multiline'
. Just ignore it.
@@ -36,7 +36,7 @@ const { | |||
URLSearchParams, | |||
domainToASCII, | |||
domainToUnicode, | |||
formatSymbol | |||
formatSymbol, |
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.
Unnecessary comma
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.
@starkwang I'll fix it
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.
Trailing commas are fine and if we didn't have so much code that lacked them, we would probably even have a lint rule to enforce them. Anything that cleans up git diffs in the long-term is a positive.
@mscdex @starkwang I'm running benchmarks now, so I'll attach the results as soon as possible |
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.
Code seems fine but this should have benchmark results.
@@ -36,7 +36,7 @@ const { | |||
URLSearchParams, | |||
domainToASCII, | |||
domainToUnicode, | |||
formatSymbol | |||
formatSymbol, |
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.
Trailing commas are fine and if we didn't have so much code that lacked them, we would probably even have a lint rule to enforce them. Anything that cleans up git diffs in the long-term is a positive.
lib/querystring.js
Outdated
if (lastPos < str.length) | ||
return out + str.slice(lastPos); | ||
return out; | ||
return encodeStr(str, noEscape, hexTable, { |
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.
Can you predeclare the error type somewhere at the top scope? There's no need to create this object on the run each time.
@mscdex @starkwang you were right about "querystring" module. There is performance reduction in this change:
I'll revert changes for "querystring" and run benchmarks for "url" |
d6f2dd1
to
43b60af
Compare
I reverted changes for "querystring" module and ran benchmarks for "url" module only. Results:
Looks like these changes make the code a little bit slower, what do you think about it? |
@daynin Do you have an opinion on whether this PR should land, given your benchmark results? If yes, this could land as it is, I think. |
@addaleax yeah, I think it should land if nobody has any objections |
PR-URL: #19076 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: #19076 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: #19076 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: #19076 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
url, querystring, internal/url, internal/querystring