| 36 | namespace { |
| 37 | |
| 38 | absl::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 | |
| 71 | absl::StatusOr<Value> MapInsertMap( |
| 72 | const MapValue& map, const MapValue& value, |