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

Make StringPiece constructible from std::string_view #8707

Merged
merged 2 commits into from
Jun 9, 2021

Conversation

georgthegreat
Copy link
Contributor

This improves interop with certain string-like data structures, allowing to save extra allocation.

This improves interop with certain string-like data structures, allowing to save extra allocation.
@google-cla google-cla bot added the cla: yes label Jun 8, 2021
@@ -214,6 +214,13 @@ class PROTOBUF_EXPORT StringPiece {
: ptr_(str.data()), length_(0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to fix this one by replacing const string& with std::string_view, but certain cases were broken.

I. e. HasSuffixString(const string&, const string&) stops working as it requires 2 implicit ctors (and the standard only allows one).

This could be simplified with C++20 starts_with / ends_with, but this is a long story.

@acozzette acozzette merged commit 2bff7d1 into protocolbuffers:master Jun 9, 2021
@georgthegreat georgthegreat deleted the patch-2 branch June 10, 2021 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants