Skip to content

Make StringPiece constructible from std::string_view#8707

Merged
acozzette merged 2 commits intoprotocolbuffers:masterfrom
georgthegreat:patch-2
Jun 9, 2021
Merged

Make StringPiece constructible from std::string_view#8707
acozzette merged 2 commits intoprotocolbuffers:masterfrom
georgthegreat:patch-2

Conversation

@georgthegreat
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/google/protobuf/stubs/stringpiece.h
@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