Skip to content
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

Merged
merged 7 commits into from
Apr 21, 2020

Conversation

euroelessar
Copy link
Contributor

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

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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!

Copy link
Contributor Author

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.

Copy link
Contributor

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!

@asraa asraa self-assigned this Apr 8, 2020
Ruslan Nigmatullin added 4 commits April 8, 2020 17:15
…-constructor

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
CR
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
…-constructor

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@euroelessar
Copy link
Contributor Author

@asraa Friendly ping.

Ruslan Nigmatullin added 2 commits April 18, 2020 15:42
…-constructor

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
fmt
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@euroelessar
Copy link
Contributor Author

@asraa @mattklein123 PTAL or recommend a reviewer, this PR is awaiting a review for 10 days now.

Copy link
Contributor

@asraa asraa left a 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!

@mattklein123 mattklein123 merged commit 9a283d0 into envoyproxy:master Apr 21, 2020
penguingao pushed a commit to penguingao/envoy that referenced this pull request Apr 22, 2020
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: pengg <pengg@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants