Purpose of the C++ string views?

55 views
Skip to first unread message

Jeffrey Baker

unread,
May 21, 2024, 7:09:01 PMMay 21
to Protocol Buffers
I perused the source code of release 27 to conduct my periodic survey of whether we can alias strings yet or not. At work I maintain a private patch that adds aliased string parsing to the library, but I'd love to stop maintaining that. My understanding of the current state of affairs is that string_view setters and getters have been added for singular and repeated fields, but when setting the contents of the string_view argument are unconditionally copied into memory owned by a std::string. The string may or may not be on an arena, but the contents are likely to be allocated with global new, modulo the short string optimization. During parsing, the input is never aliased, regardless of the kParseWithAliasing parameter. Finally, it seems that Cord still only supports singular fields.

Given all that, I am left wondering what the purpose of the VIEW type is. If it currently has these properties, and given Hyrum's Law, should I assume that these behaviors will be perpetuated? That is, that C++ protobuf will never be able to parse a repeated bytes field with aliasing, if I understand correctly.
Reply all
Reply to author
Forward
0 new messages