MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / MapInsertKeyValue

Function MapInsertKeyValue

extensions/comprehensions_v2_functions.cc:38–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36namespace {
37
38absl::StatusOr<Value> MapInsertKeyValue(
39 const MapValue& map, const Value& key, const Value& value,
40 const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
41 google::protobuf::MessageFactory* absl_nonnull message_factory,
42 google::protobuf::Arena* absl_nonnull arena) {
43 if (auto mutable_map_value = common_internal::AsMutableMapValue(map);
44 mutable_map_value) {
45 // Fast path, runtime has given us a mutable map. We can mutate it directly
46 // and return it.
47 CEL_RETURN_IF_ERROR(mutable_map_value->Put(key, value))
48 .With(ErrorValueReturn());
49 return map;
50 }
51 // Slow path, we have to make a copy.
52 auto builder = NewMapValueBuilder(arena);
53 if (auto size = map.Size(); size.ok()) {
54 builder->Reserve(*size + 1);
55 } else {
56 size.IgnoreError();
57 }
58 CEL_RETURN_IF_ERROR(
59 map.ForEach(
60 [&builder](const Value& key,
61 const Value& value) -> absl::StatusOr<bool> {
62 CEL_RETURN_IF_ERROR(builder->Put(key, value));
63 return true;
64 },
65 descriptor_pool, message_factory, arena))
66 .With(ErrorValueReturn());
67 CEL_RETURN_IF_ERROR(builder->Put(key, value)).With(ErrorValueReturn());
68 return std::move(*builder).Build();
69}
70
71absl::StatusOr<Value> MapInsertMap(
72 const MapValue& map, const MapValue& value,

Callers

nothing calls this directly

Calls 8

ErrorValueReturnClass · 0.85
WithMethod · 0.80
PutMethod · 0.45
SizeMethod · 0.45
okMethod · 0.45
ReserveMethod · 0.45
ForEachMethod · 0.45
BuildMethod · 0.45

Tested by

no test coverage detected