GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — url: use foreach-style C++ loop by tniessen · Pull Request #23138 · nodejs/node

Conversation

@tniessen

@tniessen tniessen commented Sep 28, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Change URL::parse to use a range-based for loop for better readability.

CI on commit before opening PR: https://ci.nodejs.org/job/node-test-commit/21840/

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@tniessen
url: use foreach-style C++ loop
bcad6b4
@nodejs-github-bot

nodejs-github-bot commented Sep 28, 2018

Copy link
Copy Markdown
Collaborator

@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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Sep 28, 2018
refack
refack approved these changes Sep 28, 2018
View reviewed changes
TimothyGu
TimothyGu approved these changes Sep 28, 2018
View reviewed changes
Comment thread src/node_url.h Outdated
std::string path() const {
std::string ret;
for (auto i = context_.path.begin(); i != context_.path.end(); i++) {
for (const auto& i : context_.path) {

@TimothyGu TimothyGu Sep 28, 2018

Copy link
Copy Markdown
Member

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 we replace auto with std::string?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@refack refack Sep 28, 2018

Copy link
Copy Markdown
Contributor

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.

I would ask not to.
As per the discussion in #23028

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
refack
refack reviewed Sep 28, 2018
View reviewed changes
Comment thread src/node_url.h Outdated
for (const auto& i : context_.path) {
ret += '/';
ret += *i;
ret += i;

@refack refack Sep 28, 2018

Copy link
Copy Markdown
Contributor

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@refack refack Sep 28, 2018

Copy link
Copy Markdown
Contributor

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@addaleax addaleax Sep 28, 2018

Copy link
Copy Markdown
Member

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tniessen tniessen Sep 28, 2018

Copy link
Copy Markdown
Member Author

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 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.

Uh oh!

There was an error while loading. Please reload this page.

refack reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
addaleax
addaleax approved these changes Sep 28, 2018
View reviewed changes
Comment thread src/node_url.h Outdated
for (const auto& i : context_.path) {
ret += '/';
ret += *i;
ret += i;

@addaleax addaleax Sep 28, 2018

Copy link
Copy Markdown
Member

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tniessen
tniessen force-pushed the url-use-foreach-loop branch from bcad6b4 to b3f40ee Compare September 28, 2018 09:37
@tniessen
fixup! url: use foreach-style C++ loop
2440d9c
@tniessen
tniessen force-pushed the url-use-foreach-loop branch from b3f40ee to 2440d9c Compare September 28, 2018 09:37
targos
targos reviewed Sep 28, 2018
View reviewed changes
Comment thread src/node_url.h Outdated
for (auto i = context_.path.begin(); i != context_.path.end(); i++) {
ret += '/';
ret += *i;
for (const std::string& i : context_.path) {

@targos targos Sep 28, 2018

Copy link
Copy Markdown
Member

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tniessen
fixup! url: use foreach-style C++ loop
b0eb933
cjihrig
cjihrig approved these changes Sep 28, 2018
View reviewed changes
refack
refack approved these changes Sep 28, 2018
View reviewed changes
joyeecheung
joyeecheung approved these changes Sep 28, 2018
View reviewed changes
jasnell
jasnell approved these changes Sep 28, 2018
View reviewed changes
@tniessen

tniessen commented Sep 29, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

CI: https://ci.nodejs.org/job/node-test-pull-request/17504/
Resumed in https://ci.nodejs.org/job/node-test-pull-request/17533/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thefourtheye
thefourtheye approved these changes Sep 29, 2018
View reviewed changes
@addaleax

addaleax commented Oct 1, 2018

Copy link
Copy Markdown
Member

Landed in 1d9ec04

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax addaleax closed this Oct 1, 2018
addaleax pushed a commit that referenced this pull request Oct 1, 2018
@tniessen @addaleax
url: use foreach-style C++ loop
1d9ec04
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]>
targos pushed a commit that referenced this pull request Oct 1, 2018
@tniessen @targos
url: use foreach-style C++ loop
24c3406
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]>
@joyeecheung joyeecheung mentioned this pull request Oct 2, 2018
CI failures: 20180927-20181002 nodejs/reliability#18
Closed
targos pushed a commit that referenced this pull request Oct 3, 2018
@tniessen @targos
url: use foreach-style C++ loop
d22ee2c
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]>
@targos targos mentioned this pull request Oct 7, 2018
Release proposal: v10.12.0 #23313
Merged
This was referenced Oct 10, 2018
2018-10-10 Version 10.12.0 (Current) @targos beevelop/docker-nodejs#225
Closed
2018-10-10 Version 10.12.0 (Current) @targos beevelop/docker-android-nodejs#239
Closed
2018-10-10 Version 10.12.0 (Current) @targos beevelop/docker-nodejs#226
Closed
2018-10-10 Version 10.12.0 (Current) @targos beevelop/docker-android-nodejs#240
Closed
This was referenced Oct 11, 2018
2018-10-10 Version 10.12.0 (Current) @targos beevelop/docker-nodejs#227
Closed
2018-10-10 Version 10.12.0 (Current) @targos beevelop/docker-android-nodejs#241
Closed
2018-10-10 Version 10.12.0 (Current) @targos beevelop/docker-android-nodejs#242
Closed
2018-10-10 Version 10.12.0 (Current) @targos beevelop/docker-nodejs#228
Closed
2018-10-10 Version 10.12.0 (Current) @targos beevelop/docker-android-nodejs#243
Closed
2018-10-10 Version 10.12.0 (Current) @targos beevelop/docker-nodejs#229
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jasnell jasnell jasnell approved these changes
@addaleax addaleax addaleax approved these changes
@cjihrig cjihrig cjihrig approved these changes
@joyeecheung joyeecheung joyeecheung approved these changes
+4 more reviewers
@targos targos targos left review comments
@refack refack refack approved these changes
@thefourtheye thefourtheye thefourtheye approved these changes
@TimothyGu TimothyGu TimothyGu approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. whatwg-url Issues and PRs related to the WHATWG URL implementation.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@tniessen @nodejs-github-bot @addaleax @refack @jasnell @thefourtheye @TimothyGu @targos @cjihrig @joyeecheung
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.