Uh oh!
There was an error while loading. Please reload this page.
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.
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.
Ideally this parameter should be an
const ada::url&. It doesn't make sense to pass anada::resultin when we always expect it to be filled with the "valid" value.In fact the call sites should probably change from this:
to
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.
out.value()returns a copy. The current implementation looks unsafe, butCHECK(out)ensures that it is not. I tried to avoid returning a copy. @lemire wrote about this on Ada's discussion board: ada-url/ada#200There 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 think you misunderstood ada-url/ada#200.
out.value()(and equivalently*out) does not return a copy by itself. It returns a reference, so if you put it into aconst ada::url&then no copies are made.On the other hand,
ada::url url = *out, which would make a copy. That's not what I'm suggesting here.Alternatively, you can also do
ada::result out = ada::parse(input.ToStringView()); CHECK(out); ada::url url = std::move(*out);which is written under the "performance tip". It would also avoid a copy.
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.
It is likely that the current code is safe and efficient. I think we are discussing 'coding style' which is subjective.
I don't personally find the
url->...annoying.I am slightly triggered by the
(*argv)[..]however. :-)What about using a reference to an array instead?
(The ampersand would be dropped from the calling site.)
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.
It's a style guide thing: pointers for things that are mutated, const references otherwise.
With mutable references it's sometimes ambiguous to a reader if code operates on the original or on a copy. With pointers, no such ambiguity exists.