Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions common/values/parsed_map_field_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ bool ValueToProtoMapKey(const Value& key,
}
case google::protobuf::FieldDescriptor::CPPTYPE_STRING: {
if (auto string_key = key.AsString(); string_key) {
proto_key_scratch = string_key->NativeString();
proto_key->SetStringValue(proto_key_scratch);
// `google::protobuf::MapKey` does not own the string, which may be stored inline
// in `key` or in `proto_key_scratch`; `key` must not be moved.
proto_key->SetStringValue(string_key->ToStringView(&proto_key_scratch));
return true;
}
return false;
Expand Down
5 changes: 3 additions & 2 deletions common/values/struct_value_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,9 @@ absl::StatusOr<absl::optional<ErrorValue>> ProtoStringMapKeyFromValueConverter(
const Value& value, google::protobuf::MapKey& key, std::string& key_string,
google::protobuf::Arena* absl_nonnull arena) {
if (auto string_value = value.AsString(); string_value) {
key_string = string_value->NativeString();
key.SetStringValue(key_string);
// `google::protobuf::MapKey` does not own the string, which may be stored inline in
// `value` or in `key_string`; `value` must not be moved.
key.SetStringValue(string_value->ToStringView(&key_string));
return std::nullopt;
}
return TypeConversionError(value.GetTypeName(), "string", arena);
Expand Down
4 changes: 1 addition & 3 deletions eval/public/containers/internal_field_backed_map_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ absl::StatusOr<bool> FieldBackedMapImpl::LookupMapValue(
return InvalidMapKeyType(key_desc_->cpp_type_name());
}

std::string map_key_string;
google::protobuf::MapKey proto_key;
switch (key_desc_->cpp_type()) {
case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: {
Expand All @@ -199,8 +198,7 @@ absl::StatusOr<bool> FieldBackedMapImpl::LookupMapValue(
case google::protobuf::FieldDescriptor::CPPTYPE_STRING: {
CelValue::StringHolder key_value;
key.GetValue(&key_value);
map_key_string.assign(key_value.value().data(), key_value.value().size());
proto_key.SetStringValue(map_key_string);
proto_key.SetStringValue(key_value.value());
} break;
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: {
uint64_t key_value;
Expand Down
4 changes: 2 additions & 2 deletions eval/public/structs/cel_proto_wrap_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class DynamicMap : public CelMap {
"Invalid map key type: '", CelValue::TypeName(key.type()), "'"));
}

return values_->fields().contains(std::string(str_key.value()));
return values_->fields().contains(str_key.value());
}

absl::optional<CelValue> operator[](CelValue key) const override;
Expand Down Expand Up @@ -692,7 +692,7 @@ absl::optional<CelValue> DynamicMap::operator[](CelValue key) const {
CelValue::TypeName(key.type()), "'")));
}

auto it = values_->fields().find(std::string(str_key.value()));
auto it = values_->fields().find(str_key.value());
if (it == values_->fields().end()) {
return std::nullopt;
}
Expand Down
4 changes: 1 addition & 3 deletions extensions/protobuf/internal/qualify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ absl::StatusOr<absl::optional<google::protobuf::MapValueConstRef>> LookupMapValu
key_desc->cpp_type_name());
}

std::string proto_key_string;
google::protobuf::MapKey proto_key;
switch (key_desc->cpp_type()) {
case google::protobuf::FieldDescriptor::CPPTYPE_BOOL:
Expand All @@ -122,8 +121,7 @@ absl::StatusOr<absl::optional<google::protobuf::MapValueConstRef>> LookupMapValu
proto_key.SetInt64Value(*key.GetInt64Key());
break;
case google::protobuf::FieldDescriptor::CPPTYPE_STRING: {
proto_key_string = std::string(*key.GetStringKey());
proto_key.SetStringValue(proto_key_string);
proto_key.SetStringValue(*key.GetStringKey());
} break;
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: {
uint64_t key_value = *key.GetUint64Key();
Expand Down
3 changes: 2 additions & 1 deletion extensions/select_optimization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ absl::StatusOr<Value> MapKeyFromQualifier(const AttributeQualifier& qual,
case Kind::kBool:
return cel::BoolValue(*qual.GetBoolKey());
case Kind::kString:
return StringValue::From(*qual.GetStringKey(), arena);
// Safe as `qual` is valid for the lifetime of the expression/program.
return StringValue::WrapUnsafe(*qual.GetStringKey());
default:
return runtime_internal::CreateNoMatchingOverloadError(
cel::builtin::kIndex);
Expand Down
Loading