Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions common/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -13,8 +14,8 @@ namespace expr {
/** A CEL Error. */
class Error {
public:
using ErrorData = std::unordered_set<google::rpc::Status, internal::Hasher,
internal::DefaultProtoEqual>;
using ErrorData = absl::node_hash_set<google::rpc::Status, internal::Hasher,
internal::DefaultProtoEqual>;

explicit Error(const google::rpc::Status& error);
explicit Error(absl::Span<const google::rpc::Status* const> errors);
Expand Down
8 changes: 2 additions & 6 deletions common/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,8 @@ class Type final {
inline EnumType enum_type() const { return absl::get<EnumType>(data_); }
inline ObjectType object_type() const { return absl::get<ObjectType>(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_); }
Expand Down
3 changes: 3 additions & 0 deletions internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down Expand Up @@ -191,6 +192,7 @@ cc_library(
":status_util",
"//common:macros",
"//common:value",
"@com_google_absl//absl/container:node_hash_map",
],
)

Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion internal/handle_test.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "internal/handle.h"

#include "gtest/gtest.h"
#include "absl/container/node_hash_set.h"

namespace google {
namespace api {
Expand Down Expand Up @@ -41,7 +42,7 @@ TEST(Handle, Operators) {
}

TEST(Handle, Hash) {
std::unordered_set<IntHandle, IntHandle::Hasher> handles;
absl::node_hash_set<IntHandle, IntHandle::Hasher> handles;
handles.emplace(1);
handles.insert(IntHandle(1));
handles.emplace(2);
Expand Down
5 changes: 3 additions & 2 deletions internal/map_impl.h
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -12,7 +13,7 @@ namespace internal {
/** A simple Value -> Value map implementation. */
class MapImpl final : public Map {
public:
explicit MapImpl(std::unordered_map<Value, Value>&& value)
explicit MapImpl(absl::node_hash_map<Value, Value>&& value)
: value_(std::move(value)) {}

inline std::size_t size() const override { return value_.size(); }
Expand All @@ -27,7 +28,7 @@ class MapImpl final : public Map {
Value GetImpl(const Value& key) const override;

private:
std::unordered_map<Value, Value> value_;
absl::node_hash_map<Value, Value> value_;
};

template <Value::Kind KeyKind, Value::Kind ValueKind, typename T,
Expand Down
2 changes: 1 addition & 1 deletion internal/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ using is_numeric = or_t<is_int<T>, is_uint<T>, is_float<T>>;

// 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 <typename T, typename = specialize>
struct is_container : public std::false_type {};
template <typename T>
Expand Down
3 changes: 3 additions & 0 deletions protoutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand All @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions protoutil/converters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -107,7 +108,7 @@ class Struct final : public Map {

expr::Value BuildMapFor(const google::protobuf::Struct* struct_value,
ParentRef parent) {
std::unordered_map<expr::Value, expr::Value> result;
absl::node_hash_map<expr::Value, expr::Value> result;
for (const auto& field : struct_value->fields()) {
result.emplace(Value::ForString(field.first, parent),
ValueFor(&field.second, parent));
Expand All @@ -118,7 +119,7 @@ expr::Value BuildMapFor(const google::protobuf::Struct* struct_value,
}

expr::Value BuildMapFrom(google::protobuf::Struct&& struct_value) {
std::unordered_map<expr::Value, expr::Value> result;
absl::node_hash_map<expr::Value, expr::Value> result;
for (auto& fields : *struct_value.mutable_fields()) {
result.emplace(Value::FromString(fields.first),
ValueFrom(std::move(fields.second)));
Expand All @@ -127,7 +128,7 @@ expr::Value BuildMapFrom(google::protobuf::Struct&& struct_value) {
}

expr::Value BuildMapFrom(const google::protobuf::Struct& struct_value) {
std::unordered_map<expr::Value, expr::Value> result;
absl::node_hash_map<expr::Value, expr::Value> result;
for (const auto& fields : struct_value.fields()) {
result.emplace(Value::FromString(fields.first), ValueFrom(fields.second));
}
Expand Down
3 changes: 2 additions & 1 deletion protoutil/type_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<expr::Value, expr::Value> result;
absl::node_hash_map<expr::Value, expr::Value> 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);
Expand Down
5 changes: 3 additions & 2 deletions protoutil/type_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <memory>

#include "absl/container/node_hash_map.h"
#include "common/parent_ref.h"
#include "common/type.h"
#include "common/value.h"
Expand Down Expand Up @@ -192,8 +193,8 @@ class TypeRegistry {
std::function<Value(EnumType, int32_t)> from_ctor;
};

std::unordered_map<ObjectType, ObjectRegistryEntry> object_registry_;
std::unordered_map<EnumType, EnumRegistryEntry> enum_registry_;
absl::node_hash_map<ObjectType, ObjectRegistryEntry> object_registry_;
absl::node_hash_map<EnumType, EnumRegistryEntry> enum_registry_;

Value ValueFromUnregistered(std::unique_ptr<google::protobuf::Message> value) const;
Value ValueForUnregistered(const google::protobuf::Message* value,
Expand Down
1 change: 1 addition & 0 deletions v1beta1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions v1beta1/converters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -205,7 +206,7 @@ using ListValueOwned = ListValue<internal::OwnedPtr>;

expr::Value BuildMapFor(const v1beta1::MapValue* map_value, ParentRef parent,
const TypeRegistry* registry) {
std::unordered_map<expr::Value, expr::Value> result;
absl::node_hash_map<expr::Value, expr::Value> result;
for (const auto& entry : map_value->entries()) {
result.emplace(ValueFor(&entry.key(), parent, registry),
ValueFor(&entry.value(), parent, registry));
Expand All @@ -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<expr::Value, expr::Value> result;
absl::node_hash_map<expr::Value, expr::Value> result;
for (v1beta1::MapValue::Entry& entry : *map_value.mutable_entries()) {
result.emplace(
ValueFrom(absl::WrapUnique(entry.release_key()), registry),
Expand All @@ -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<expr::Value, expr::Value> result;
absl::node_hash_map<expr::Value, expr::Value> result;
for (auto& entry : map_value.entries()) {
result.emplace(ValueFrom(entry.key(), registry),
ValueFrom(entry.value(), registry));
Expand Down