diff --git a/common/BUILD.bazel b/common/BUILD.bazel index faecb9bc5..4a17ef905 100644 --- a/common/BUILD.bazel +++ b/common/BUILD.bazel @@ -65,6 +65,7 @@ cc_library( "//internal:cel_printer", "//internal:hash_util", "//internal:proto_util", + "@com_google_absl//absl/container:node_hash_set", "@com_google_absl//absl/types:span", "@com_google_googleapis//:cc_rpc_code", "@com_google_googleapis//:cc_rpc_status", diff --git a/common/error.h b/common/error.h index c9992b3c8..871bb6ab4 100644 --- a/common/error.h +++ b/common/error.h @@ -2,6 +2,7 @@ #define THIRD_PARTY_CEL_CPP_COMMON_ERROR_H_ #include "google/rpc/status.pb.h" +#include "absl/container/node_hash_set.h" #include "absl/types/span.h" #include "internal/hash_util.h" #include "internal/proto_util.h" @@ -13,8 +14,8 @@ namespace expr { /** A CEL Error. */ class Error { public: - using ErrorData = std::unordered_set; + using ErrorData = absl::node_hash_set; explicit Error(const google::rpc::Status& error); explicit Error(absl::Span errors); diff --git a/common/type.h b/common/type.h index 57dcf9c95..654c15784 100644 --- a/common/type.h +++ b/common/type.h @@ -137,12 +137,8 @@ class Type final { inline EnumType enum_type() const { return absl::get(data_); } inline ObjectType object_type() const { return absl::get(data_); } - inline bool operator==(const Type& rhs) const { - return data_ == rhs.data_; - } - inline bool operator!=(const Type& rhs) const { - return data_ != rhs.data_; - } + inline bool operator==(const Type& rhs) const { return data_ == rhs.data_; } + inline bool operator!=(const Type& rhs) const { return data_ != rhs.data_; } /** The hash code for this value. */ inline std::size_t hash_code() const { return internal::Hash(data_); } diff --git a/internal/BUILD.bazel b/internal/BUILD.bazel index b2bae9e41..2b31813c3 100644 --- a/internal/BUILD.bazel +++ b/internal/BUILD.bazel @@ -46,6 +46,7 @@ cc_test( srcs = ["handle_test.cc"], deps = [ ":handle", + "@com_google_absl//absl/container:node_hash_set", "@com_google_googletest//:gtest_main", ], ) @@ -191,6 +192,7 @@ cc_library( ":status_util", "//common:macros", "//common:value", + "@com_google_absl//absl/container:node_hash_map", ], ) @@ -274,6 +276,7 @@ cc_library( ":port", ":specialize", "@com_github_gflags_gflags//:gflags", + "@com_google_absl//absl/container:node_hash_set", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", "@com_google_glog//:glog", diff --git a/internal/handle_test.cc b/internal/handle_test.cc index a408a604a..b0120f16a 100644 --- a/internal/handle_test.cc +++ b/internal/handle_test.cc @@ -1,6 +1,7 @@ #include "internal/handle.h" #include "gtest/gtest.h" +#include "absl/container/node_hash_set.h" namespace google { namespace api { @@ -41,7 +42,7 @@ TEST(Handle, Operators) { } TEST(Handle, Hash) { - std::unordered_set handles; + absl::node_hash_set handles; handles.emplace(1); handles.insert(IntHandle(1)); handles.emplace(2); diff --git a/internal/map_impl.h b/internal/map_impl.h index a84012a3c..31837177e 100644 --- a/internal/map_impl.h +++ b/internal/map_impl.h @@ -1,6 +1,7 @@ #ifndef THIRD_PARTY_CEL_CPP_INTERNAL_MAP_IMPL_H_ #define THIRD_PARTY_CEL_CPP_INTERNAL_MAP_IMPL_H_ +#include "absl/container/node_hash_map.h" #include "common/macros.h" #include "common/value.h" @@ -12,7 +13,7 @@ namespace internal { /** A simple Value -> Value map implementation. */ class MapImpl final : public Map { public: - explicit MapImpl(std::unordered_map&& value) + explicit MapImpl(absl::node_hash_map&& value) : value_(std::move(value)) {} inline std::size_t size() const override { return value_.size(); } @@ -27,7 +28,7 @@ class MapImpl final : public Map { Value GetImpl(const Value& key) const override; private: - std::unordered_map value_; + absl::node_hash_map value_; }; template , is_uint, is_float>; // Containers define a "value_type" and "iterator". // Note: The full spec can be found at -// http://en.cppreference.com/w/cpp/concept/Container +// https://en.cppreference.com/w/cpp/named_req/Container template struct is_container : public std::false_type {}; template diff --git a/protoutil/BUILD.bazel b/protoutil/BUILD.bazel index 21244e930..9789ad68e 100644 --- a/protoutil/BUILD.bazel +++ b/protoutil/BUILD.bazel @@ -21,6 +21,7 @@ cc_library( "//internal:cast", "//internal:map_impl", "//internal:proto_util", + "@com_google_absl//absl/container:node_hash_map", "@com_google_protobuf//:protobuf", ], ) @@ -33,6 +34,7 @@ cc_test( "//common:value", "//internal:ref_countable", "//testutil:util", + "@com_google_absl//absl/container:node_hash_map", "@com_google_googleapis//:cc_type_money", "@com_google_googletest//:gtest_main", "@com_google_protobuf//:protobuf", @@ -59,6 +61,7 @@ cc_library( "//internal:ref_countable", "//internal:status_util", "//internal:types", + "@com_google_absl//absl/container:node_hash_map", "@com_google_absl//absl/strings", "@com_google_absl//absl/types:span", "@com_google_protobuf//:protobuf", diff --git a/protoutil/converters.cc b/protoutil/converters.cc index 3d2e40613..c1d868fb5 100644 --- a/protoutil/converters.cc +++ b/protoutil/converters.cc @@ -5,6 +5,7 @@ #include "google/protobuf/descriptor.h" #include "google/protobuf/util/message_differencer.h" +#include "absl/container/node_hash_set.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "absl/types/span.h" @@ -107,7 +108,7 @@ class Struct final : public Map { expr::Value BuildMapFor(const google::protobuf::Struct* struct_value, ParentRef parent) { - std::unordered_map result; + absl::node_hash_map result; for (const auto& field : struct_value->fields()) { result.emplace(Value::ForString(field.first, parent), ValueFor(&field.second, parent)); @@ -118,7 +119,7 @@ expr::Value BuildMapFor(const google::protobuf::Struct* struct_value, } expr::Value BuildMapFrom(google::protobuf::Struct&& struct_value) { - std::unordered_map result; + absl::node_hash_map result; for (auto& fields : *struct_value.mutable_fields()) { result.emplace(Value::FromString(fields.first), ValueFrom(std::move(fields.second))); @@ -127,7 +128,7 @@ expr::Value BuildMapFrom(google::protobuf::Struct&& struct_value) { } expr::Value BuildMapFrom(const google::protobuf::Struct& struct_value) { - std::unordered_map result; + absl::node_hash_map result; for (const auto& fields : struct_value.fields()) { result.emplace(Value::FromString(fields.first), ValueFrom(fields.second)); } diff --git a/protoutil/type_registry.cc b/protoutil/type_registry.cc index daa824477..cc9379f17 100644 --- a/protoutil/type_registry.cc +++ b/protoutil/type_registry.cc @@ -2,6 +2,7 @@ #include "google/protobuf/reflection.h" #include "google/protobuf/util/message_differencer.h" +#include "absl/container/node_hash_map.h" #include "common/macros.h" #include "internal/map_impl.h" #include "internal/proto_util.h" @@ -207,7 +208,7 @@ class MessageObject final : public Object { const google::protobuf::Message* msg) const { // Proto maps are represented by a repeated message with two fields // (key and value) - std::unordered_map result; + absl::node_hash_map result; const google::protobuf::Reflection* refl = msg->GetReflection(); for (int index = 0; index < refl->FieldSize(*msg, field); ++index) { const auto& entry = refl->GetRepeatedMessage(*msg, field, index); diff --git a/protoutil/type_registry.h b/protoutil/type_registry.h index 372ae8979..461cd3e27 100644 --- a/protoutil/type_registry.h +++ b/protoutil/type_registry.h @@ -3,6 +3,7 @@ #include +#include "absl/container/node_hash_map.h" #include "common/parent_ref.h" #include "common/type.h" #include "common/value.h" @@ -192,8 +193,8 @@ class TypeRegistry { std::function from_ctor; }; - std::unordered_map object_registry_; - std::unordered_map enum_registry_; + absl::node_hash_map object_registry_; + absl::node_hash_map enum_registry_; Value ValueFromUnregistered(std::unique_ptr value) const; Value ValueForUnregistered(const google::protobuf::Message* value, diff --git a/v1beta1/BUILD.bazel b/v1beta1/BUILD.bazel index f2b0982ca..812abc86c 100644 --- a/v1beta1/BUILD.bazel +++ b/v1beta1/BUILD.bazel @@ -24,6 +24,7 @@ cc_library( "//internal:proto_util", "//internal:status_util", "//protoutil:type_registry", + "@com_google_absl//absl/container:node_hash_set", "@com_google_absl//absl/strings", "@com_google_googleapis//:cc_expr_v1beta1", "@com_google_googleapis//:cc_rpc_code", diff --git a/v1beta1/converters.cc b/v1beta1/converters.cc index 03aebab85..c7300885f 100644 --- a/v1beta1/converters.cc +++ b/v1beta1/converters.cc @@ -4,6 +4,7 @@ #include "google/protobuf/struct.pb.h" #include "google/protobuf/timestamp.pb.h" #include "google/rpc/code.pb.h" +#include "absl/container/node_hash_map.h" #include "absl/strings/str_cat.h" #include "common/converters.h" #include "common/macros.h" @@ -205,7 +206,7 @@ using ListValueOwned = ListValue; expr::Value BuildMapFor(const v1beta1::MapValue* map_value, ParentRef parent, const TypeRegistry* registry) { - std::unordered_map result; + absl::node_hash_map result; for (const auto& entry : map_value->entries()) { result.emplace(ValueFor(&entry.key(), parent, registry), ValueFor(&entry.value(), parent, registry)); @@ -217,7 +218,7 @@ expr::Value BuildMapFor(const v1beta1::MapValue* map_value, ParentRef parent, expr::Value BuildMapFrom(v1beta1::MapValue&& map_value, const TypeRegistry* registry) { - std::unordered_map result; + absl::node_hash_map result; for (v1beta1::MapValue::Entry& entry : *map_value.mutable_entries()) { result.emplace( ValueFrom(absl::WrapUnique(entry.release_key()), registry), @@ -228,7 +229,7 @@ expr::Value BuildMapFrom(v1beta1::MapValue&& map_value, expr::Value BuildMapFrom(const v1beta1::MapValue& map_value, const TypeRegistry* registry) { - std::unordered_map result; + absl::node_hash_map result; for (auto& entry : map_value.entries()) { result.emplace(ValueFrom(entry.key(), registry), ValueFrom(entry.value(), registry));