Repository navigation
Eliminate temporary std::string copies in CEL protobuf map and Struct lookups. - #2327
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_994548694
branch
2 times, most recently
from
October 6, 2026 22:04
ee02b96 to
50a59f1
Compare
…uct` lookups. Previously, looking up or checking presence of a string key in a protobuf map or `google.protobuf.Struct` allocated or constructed a temporary `std::string` via `StringValue::NativeString()` (or `std::string(str_key.value())`) before populating a `google::protobuf::MapKey`, even when the key was already backed by a contiguous `absl::string_view` and only a stack scratch buffer was needed for fragmented cord-backed strings. This change uses `StringValue::ToStringView(&scratch)` (and direct `absl::string_view` in `DynamicMap` and `LookupMapValue`) before calling `MapKey::SetStringValue`, avoiding heap allocations and redundant copies for string-keyed map and `google.protobuf.Struct` field accesses across: - `ParsedMapFieldValue::Find` and `ParsedMapFieldValue::Has` - `ProtoStringMapKeyFromValueConverter` - `FieldBackedMapImpl::LookupMapValue` - `DynamicMap::Has` and `DynamicMap::operator[]` (`cel_proto_wrap_util.cc`) - `MapKeyFromQualifier` and `ProtoQualifyState::ApplySelectQualifiers` PiperOrigin-RevId: 994679246
copybara-service
Bot
force-pushed
the
test_994548694
branch
from
October 6, 2026 22:54
50a59f1 to
57533e2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Eliminate temporary
std::stringcopies in CEL protobuf map andStructlookups.Previously, looking up or checking presence of a string key in a protobuf map or
google.protobuf.Structallocated or constructed a temporarystd::stringviaStringValue::NativeString()(orstd::string(str_key.value())) before populating agoogle::protobuf::MapKey, even when the key was already backed by a contiguousabsl::string_viewand only a stack scratch buffer was needed for fragmented cord-backed strings.This change uses
StringValue::ToStringView(&scratch)(and directabsl::string_viewinDynamicMapandLookupMapValue) before callingMapKey::SetStringValue, avoiding heap allocations and redundant copies for string-keyed map andgoogle.protobuf.Structfield accesses across:ParsedMapFieldValue::FindandParsedMapFieldValue::HasProtoStringMapKeyFromValueConverterFieldBackedMapImpl::LookupMapValueDynamicMap::HasandDynamicMap::operator[](cel_proto_wrap_util.cc)MapKeyFromQualifierandProtoQualifyState::ApplySelectQualifiers