GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — url: use foreach-style C++ loop by tniessen · Pull Request #23138 · nodejs/node Conversation
|
|
@tniessen build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/1047/pipeline |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| std::string path() const { | ||
| std::string ret; | ||
| for (auto i = context_.path.begin(); i != context_.path.end(); i++) { | ||
| for (const auto& i : context_.path) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can we replace auto with std::string?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would ask not to.
As per the discussion in #23028
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| for (const auto& i : context_.path) { | ||
| ret += '/'; | ||
| ret += *i; | ||
| ret += i; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
There are two possible minor improvements.
One is to use stringstream
The other is to hint to the compiler the the / always goes with the next part:
ret += '/' + i;
YMMV
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Theoretically this should be the best solution, but I'm not sure I like it:
return std::accumulate(cbegin(_path), cend(_path), std::string(),
[](auto const& a, auto const& b) { return a + '/' + b; });
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I’d prefer std::accumulate over stringstream but otherwise the suggestions in these two comments seem fine (as does the current state of the PR)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The idea behind using a range-based for loop was to improve readability, and using accumulate for such a trivial thing seems like doing the opposite.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| for (const auto& i : context_.path) { | ||
| ret += '/'; | ||
| ret += *i; | ||
| ret += i; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I’d prefer std::accumulate over stringstream but otherwise the suggestions in these two comments seem fine (as does the current state of the PR)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
bcad6b4 to
b3f40ee
Compare
b3f40ee to
2440d9c
Compare
| for (auto i = context_.path.begin(); i != context_.path.end(); i++) { | ||
| ret += '/'; | ||
| ret += *i; | ||
| for (const std::string& i : context_.path) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename it to something like path_element?
To me, i means "index" and that's how it's always used in JS.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
CI: https://ci.nodejs.org/job/node-test-pull-request/17504/ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Landed in 1d9ec04 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
PR-URL: #23138 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
PR-URL: #23138 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
PR-URL: #23138 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.