Skip to content

cleanup: expose address string_view accessor#7732

Merged
mattklein123 merged 2 commits intoenvoyproxy:masterfrom
kyessenov:use_string_view
Jul 26, 2019
Merged

cleanup: expose address string_view accessor#7732
mattklein123 merged 2 commits intoenvoyproxy:masterfrom
kyessenov:use_string_view

Conversation

@kyessenov
Copy link
Copy Markdown
Contributor

@kyessenov kyessenov commented Jul 26, 2019

Signed-off-by: Kuat Yessenov kuat@google.com
Description: expose address instance string_view accessor. It already owns the string, so we can avoid the copy.
Risk Level: low
Testing: unit tests
Docs Changes:
Release Notes:

Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
Copy link
Copy Markdown
Member

@dio dio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dio dio requested review from mattklein123 and removed request for mattklein123 July 26, 2019 06:27
Copy link
Copy Markdown
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't copy already by returning const std::string&, and it converts to absl::string_view implicitly without copy anyway, what does this solve?

@kyessenov
Copy link
Copy Markdown
Contributor Author

kyessenov commented Jul 26, 2019

The problem it's trying to solve is to make it explicit :) I'd like the final string view to point to the memory allocated inside the IP address instance. If a string is copied (due to a compiler optimization off, someone changing the interface from reference to value), then the final string view points to a copy, which has a distinct life time than the IP address (it might be block-bound).

Copy link
Copy Markdown
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimally you would go back and remove the asString() function, though that would be a huge change.

@mattklein123 mattklein123 merged commit fb7e74e into envoyproxy:master Jul 26, 2019
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.

4 participants