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

@georgthegreat georgthegreat commented Jun 8, 2021

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

@georgthegreat georgthegreat Jun 8, 2021

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 added release notes: yes Include this PR description in the next release c++ kokoro:run labels Jun 9, 2021
@acozzette acozzette merged commit 2bff7d1 into protocolbuffers:master Jun 9, 2021
52 of 54 checks passed
@georgthegreat georgthegreat deleted the patch-2 branch Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ cla: yes release notes: yes Include this PR description in the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants