-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
stream_info: Collapse constructors #10691
stream_info: Collapse constructors #10691
Conversation
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@@ -292,6 +286,16 @@ struct StreamInfoImpl : public StreamInfo { | |||
std::string route_name_; | |||
|
|||
private: | |||
StreamInfoImpl(absl::optional<Http::Protocol> protocol, TimeSource& time_source) |
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.
Do you need this intermediate constructor? Can the 2 arg constructor (with an optional protocol arg) call the private 3 arg one directly?
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.
If I understand the question correctly - I wanted to avoid changing the public API of the struct.
It's possible to collapse StreamInfoImpl(TimeSource& time_source)
and StreamInfoImpl(Http::Protocol protocol, TimeSource& time_source)
into StreamInfoImpl(TimeSource& time_source, absl::optional<Http::Protocol> protocol = absl::nullopt)
and fix all call sites if that's what you're asking. After that we have 2 public constructors with both of them calling into single private one.
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.
Another alternative is to just duplicate std::make_shared<FilterStateImpl>(FilterState::LifeSpan::FilterChain)
call in first two constructors, wdyt?
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.
Agree, not worth it to change callsites just to flip args and have the default. I was just suggesting making the public 2 arg constructor directly be StreamInfoImpl(absl::optional<Http::Protocol> protocol, TimeSource& time_source)
, since implicit conversion seems to work and you wouldn't need to change callsites to use absl::make_optional
for the protocol. But stylisticly it's seems clearer to be explicit when using optional.
Happy with the latter, that sounds like a reasonable balance of clarity and simplicity!
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.
Oh, I see. I don't have a strong preference, let me update the pr to change the signature.
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 for being unclear -- i think that your suggestion here
Another alternative is to just duplicate std::make_shared(FilterState::LifeSpan::FilterChain) call in first two constructors, wdyt?
Is most clear since I think most uses of optional are explicitly with make_optional
in the codebase. Sorry about that -- should be good to go after that!
…-constructor Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
…-constructor Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@asraa Friendly ping. |
…-constructor Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@asraa @mattklein123 PTAL or recommend a reviewer, this PR is awaiting a review for 10 days now. |
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.
LGTM! I'm really sorry for the delay, this fell off my radar. Feel free to bug me on slack!
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com> Signed-off-by: pengg <pengg@google.com>
Description: Reduce code duplication in StreamInfo by chained calls to other constructors
Risk Level: low (code restructure, no behavior changes)
Testing: n/a
Docs Changes: n/a
Release Notes: n/a