url: fix setting url.search to the empty string#11105
url: fix setting url.search to the empty string#11105TimothyGu wants to merge 3 commits intonodejs:masterfrom
url.search to the empty string#11105Conversation
Fixes: nodejs#11101 Fixes: 98bb65f "url: improving URLSearchParams"
lib/internal/url.js
Outdated
| ctx.query = null; | ||
| ctx.flags &= ~binding.URL_FLAGS_HAS_QUERY; | ||
| this[searchParams][searchParams] = {}; | ||
| this[searchParams][searchParams] = []; |
There was a problem hiding this comment.
Another way to do it is to not return here, create an else branch to wrap the stuff below and leave the initialization to initSearchParams(this[searchParams], search) later. That way URL doesn't need to know about the data sturcture of URLSearchParams
There was a problem hiding this comment.
@joyeecheung, done, PTAL.
This does bring a drop to performance when !search. To counter this problem I added a few conditions to avoid parsing as much as possible.
After those changes, when alternative is changed to '', there is a 2.8% drop in performance; but when it is '?' there is a 400% increase, as measured by
node benchmark/compare.js --new ./after --old ./orig \
--set n=1e5 --set prop=search --set 'url=http://example.com/' \
--filter properties urlThat's pretty good IMO.
|
Will this make it to a 7.5.1 or will it have to wait for 7.6? |
|
Unsure. It depends on when 7.5.1 goes out. This won't land until Friday following our typical 48 hour cycle |
lib/internal/url.js
Outdated
| @@ -614,6 +611,10 @@ function update(url, params) { | |||
| // Reused by the URL parse function invoked by | |||
| // the href setter, and the URLSearchParams constructor | |||
There was a problem hiding this comment.
We can probably just get rid of the comment now, or mention search in it.
|
Landed in 0792d45. |
PR-URL: nodejs#11105 Fixes: nodejs#11101 Fixes: 98bb65f "url: improving URLSearchParams" Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: nodejs#11105 Fixes: nodejs#11101 Fixes: 98bb65f "url: improving URLSearchParams" Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: nodejs#11105 Fixes: nodejs#11101 Fixes: 98bb65f "url: improving URLSearchParams" Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Fixes: #11101
Fixes: 98bb65f "url: improving URLSearchParams"
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
url