-
Notifications
You must be signed in to change notification settings - Fork 5.1k
filterchain: use span to avoid construct vector #7523
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
Conversation
Signed-off-by: Yuchen Dai <silentdai@gmail.com>
Signed-off-by: Yuchen Dai <silentdai@gmail.com>
const std::string& transport_protocol, const std::vector<std::string>& application_protocols, | ||
const std::vector<std::string>& destination_ips, | ||
const absl::Span<const std::string* const> server_names, const std::string& transport_protocol, | ||
const absl::Span<const std::string* const> application_protocols, |
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.
Is there a particular reason why you've chosen to use std::string*
over something like std::reference_wrapper
? I assume it's not possible to put a const reference in the Span?
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 only reason is that const absl::Span<const std::string* const>
can be converted from const ::google::protobuf::RepeatedPtrField<::std::string>
at no cost. Let me see if span<std::reference_wrapper>
works
Below is the signature of protobuf generated function signature.
const ::google::protobuf::RepeatedPtrField<::std::string>&
FilterChainMatch::application_protocols() const
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.
A reference wrapper is basically a very thinly wrapped pointer, with the logic required to copy it (the pointer, not the object). It should be basically equivalent to the pointer case in terms of actual generated code. If it doesn't work right no worries, but there is some small benefit of reference_wrapper in conveying that the reference cannot be nullable and is not owned.
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.
Thanks! I am writing a small test cases to see if protobuf::RepeatedPtrField converts to Span<reference_wrapper>. Will post the code here. As long as it works I agree reference_wrapper is the preference
Sorry Combinations of Span< [const, nonconst] std::reference_wrapper<[const, nonconst] std::string> > is not convertible from RepeatedPtrField. I prefer land this PR first and explore in the future.
|
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.
SGTM, thanks for looking into it.
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.
Thanks!
Signed-off-by: Yuchen Dai silentdai@gmail.com
Description:
Clean up the TODO
The read-only Protobuf::RepeatedField can be viewed as span in listener/filterchain
Risk Level: LOW. It's internal implementation detail of filter chain.
Testing:
Existing test.
Filterchain benchmark test doesn't complain in trivial case. But I didn't extend the test to embrace huge server names and protocol set.