From 88ef44bb8e27c14d43c66410bce0da93a04258ea Mon Sep 17 00:00:00 2001 From: Justin King Date: Fri, 16 Oct 2026 10:44:23 -0700 Subject: [PATCH] Remove `std::shared_ptr` implementation in `FunctionDescriptor`. PiperOrigin-RevId: 1000955452 --- common/function_descriptor.cc | 11 ++----- common/function_descriptor.h | 55 ++++++++++++++++------------------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/common/function_descriptor.cc b/common/function_descriptor.cc index be32e8616..779fe939b 100644 --- a/common/function_descriptor.cc +++ b/common/function_descriptor.cc @@ -45,17 +45,12 @@ bool FunctionDescriptor::ShapeMatches(bool receiver_style, } bool FunctionDescriptor::operator==(const FunctionDescriptor& other) const { - return impl_.get() == other.impl_.get() || - (name() == other.name() && - receiver_style() == other.receiver_style() && - types().size() == other.types().size() && - std::equal(types().begin(), types().end(), other.types().begin())); + return name() == other.name() && receiver_style() == other.receiver_style() && + types().size() == other.types().size() && + std::equal(types().begin(), types().end(), other.types().begin()); } bool FunctionDescriptor::operator<(const FunctionDescriptor& other) const { - if (impl_.get() == other.impl_.get()) { - return false; - } if (name() < other.name()) { return true; } diff --git a/common/function_descriptor.h b/common/function_descriptor.h index 75c61e13a..1c97bdcca 100644 --- a/common/function_descriptor.h +++ b/common/function_descriptor.h @@ -15,7 +15,6 @@ #ifndef THIRD_PARTY_CEL_CPP_COMMON_FUNCTION_DESCRIPTOR_H_ #define THIRD_PARTY_CEL_CPP_COMMON_FUNCTION_DESCRIPTOR_H_ -#include #include #include #include @@ -45,41 +44,48 @@ struct FunctionDescriptorOptions { // overloads. class FunctionDescriptor final { public: + FunctionDescriptor(const FunctionDescriptor&) = default; + FunctionDescriptor(FunctionDescriptor&&) = default; + FunctionDescriptor& operator=(const FunctionDescriptor&) = default; + FunctionDescriptor& operator=(FunctionDescriptor&&) = default; + FunctionDescriptor(absl::string_view name, bool receiver_style, std::vector types, bool is_strict) - : impl_(std::make_shared( - name, std::move(types), receiver_style, - FunctionDescriptorOptions{is_strict, - /*is_contextual=*/false})) {} + : FunctionDescriptor(name, receiver_style, std::move(types), + FunctionDescriptorOptions{is_strict, + /*is_contextual=*/false}) { + } FunctionDescriptor(absl::string_view name, bool receiver_style, std::vector types, bool is_strict, bool is_contextual) - : impl_(std::make_shared( - name, std::move(types), receiver_style, - FunctionDescriptorOptions{is_strict, is_contextual})) {} + : FunctionDescriptor( + name, receiver_style, std::move(types), + FunctionDescriptorOptions{is_strict, is_contextual}) {} FunctionDescriptor(absl::string_view name, bool is_receiver_style, std::vector types, FunctionDescriptorOptions options = {}) - : impl_(std::make_shared(name, std::move(types), is_receiver_style, - options)) {} + : name_(name), + types_(std::move(types)), + is_receiver_style_(is_receiver_style), + options_(std::move(options)) {} // Function name. - const std::string& name() const { return impl_->name; } + const std::string& name() const { return name_; } // Whether function is receiver style i.e. true means arg0.name(args[1:]...). - bool receiver_style() const { return impl_->is_receiver_style; } + bool receiver_style() const { return is_receiver_style_; } // The argument types the function accepts. // // TODO(uncreated-issue/17): make this kinds - const std::vector& types() const { return impl_->types; } + const std::vector& types() const { return types_; } // if true (strict, default), error or unknown arguments are propagated // instead of calling the function. if false (non-strict), the function may // receive error or unknown values as arguments. - bool is_strict() const { return impl_->options.is_strict; } + bool is_strict() const { return options_.is_strict; } // Whether the function is contextual (impure). // @@ -87,7 +93,7 @@ class FunctionDescriptor final { // the CEL expression evaluation or have visible side effects. This breaks // some of the assumptions of CEL. This flag is used as a hint to the planner // that some optimizations are not safe or not effective. - bool is_contextual() const { return impl_->options.is_contextual; } + bool is_contextual() const { return options_.is_contextual; } // Helper for matching a descriptor. This tests that the shape is the same -- // |other| accepts the same number and types of arguments and is the same call @@ -102,21 +108,10 @@ class FunctionDescriptor final { bool operator<(const FunctionDescriptor& other) const; private: - struct Impl final { - Impl(absl::string_view name, std::vector types, - bool is_receiver_style, FunctionDescriptorOptions options) - : name(name), - types(std::move(types)), - is_receiver_style(is_receiver_style), - options(options) {} - - std::string name; - std::vector types; - bool is_receiver_style; - FunctionDescriptorOptions options; - }; - - std::shared_ptr impl_; + std::string name_; + std::vector types_; + bool is_receiver_style_; + FunctionDescriptorOptions options_; }; } // namespace cel