diff --git a/eval/public/cel_value_clone.cc b/eval/public/cel_value_clone.cc index 8a07033df..18c3cc422 100644 --- a/eval/public/cel_value_clone.cc +++ b/eval/public/cel_value_clone.cc @@ -163,4 +163,10 @@ absl::StatusOr CelValueClone(google::protobuf::Arena* arena, CelValue return in.Visit>(CloneVisitor{.arena = arena}); } +absl::StatusOr CelMapClone(google::protobuf::Arena* arena, + const CelMap* in) { + CEL_ASSIGN_OR_RETURN(CelValue out, CloneVisitor{.arena = arena}(in)); + return out.MapOrDie(); // Crash OK +} + } // namespace google::api::expr::runtime diff --git a/eval/public/cel_value_clone.h b/eval/public/cel_value_clone.h index 2ffe47894..cd98b0849 100644 --- a/eval/public/cel_value_clone.h +++ b/eval/public/cel_value_clone.h @@ -35,6 +35,12 @@ inline absl::StatusOr CelValueClone(google::protobuf::Arena* arena, return CelValueClone(arena, *in); } +// Clones (deep copy) a CelMap such that the resulting CelMap has a lifetime +// tied to the given arena. The container implementations for the output are not +// guaranteed to be the same as the input. +absl::StatusOr CelMapClone(google::protobuf::Arena* arena, + const CelMap* in); + } // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_VALUE_CLONE_H_