Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
src: prefer C++ empty() in boolean expressions#34432
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
gengjiawen commented Jul 20, 2020
Maybe also add |
src/node_url.cc Outdated
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.
Wildly inefficient way of removing empty prefixes... (n reallocations + n*m copies when 1 + m suffices)
| while (url->path.size() > 1 && url->path[0].empty()){ | |
| url->path.erase(url->path.begin()); | |
| } | |
| auto begin = url->path.begin(); | |
| auto end = url->path.end(); | |
| auto from = begin; | |
| auto to = begin; | |
| while (to != end && to->empty()) ++to; | |
| if (to == end && from == begin && from != to) ++from; | |
| url->path.erase(from, to); // 1 + m |
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.
@bnoordhuis In your suggestion, the from == begin part is always true, unless i’m missing something?
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.
Sorry, yeah. It was intended as a kind of self-documentation about the preconditions but I guess it's confusing more than anything else. if (to == end && from != end) ++from; is probably a clearer way of writing 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.
As this is not directly related to the other changes in this PR, this could be done in a separate commit/PR.
devsnek left a comment
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.
the future is now
gengjiawen commented Jul 20, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Failed test case in macOS. is this a flaky test ? cc @Trott Path: parallel/test-macos-app-sandbox--- stderr ---assert.js:103 throw new AssertionError(obj); ^AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:1 !== 0 at Object.<anonymous> (/Users/runner/work/node/node/test/parallel/test-macos-app-sandbox.js:41:8) at Module._compile (internal/modules/cjs/loader.js:1252:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1273:10) at Module.load (internal/modules/cjs/loader.js:1101:32) at Function.Module._load (internal/modules/cjs/loader.js:966:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) at internal/main/run_main_module.js:17:47{ generatedMessage: true, code: 'ERR_ASSERTION', actual: 1, expected: 0, operator: 'strictEqual'} |
Uh oh!
There was an error while loading. Please reload this page.
36b41e6 to 11d860cComparenodejs-github-bot commented Aug 10, 2020
jasnell commented Aug 11, 2020
Landed in 1be7bbd |
PR-URL: #34432 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
PR-URL: #34432 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
PR-URL: #34432 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
PR-URL: #34432 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
PR-URL: #34432 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
This changes occurrences of
length()andsize()toempty()where it makes the code simpler.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes