Skip to content

Commit 2f62c33

Browse files
jckingcopybara-github
authored andcommitted
Remove ability to modify EnumType equality and hashing
PiperOrigin-RevId: 586003649
1 parent d65ec54 commit 2f62c33

3 files changed

Lines changed: 4 additions & 27 deletions

File tree

common/types/enum_type.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ class BasicEnumType final : public EnumTypeInterface {
8181
private:
8282
friend class BasicEnumTypeValueIterator;
8383

84-
bool Equals(const EnumTypeInterface&) const override { return true; }
85-
86-
void HashValue(absl::HashState) const override {}
87-
8884
absl::StatusOr<absl::optional<EnumTypeValueId>> FindIdByName(
8985
absl::string_view name) const override {
9086
if (auto it = values_by_name_.find(name); it != values_by_name_.end()) {

common/types/enum_type.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
#include "absl/base/attributes.h"
3131
#include "absl/base/nullability.h"
32-
#include "absl/hash/hash.h"
3332
#include "absl/log/absl_check.h"
3433
#include "absl/meta/type_traits.h"
3534
#include "absl/status/statusor.h"
@@ -160,16 +159,6 @@ class EnumTypeInterface : public TypeInterface,
160159
private:
161160
friend class EnumType;
162161
friend class EnumTypeView;
163-
friend bool operator==(const EnumType& lhs, const EnumType& rhs);
164-
template <typename H>
165-
friend H AbslHashValue(H state, const EnumType& type);
166-
friend bool operator==(EnumTypeView lhs, EnumTypeView rhs);
167-
template <typename H>
168-
friend H AbslHashValue(H state, EnumTypeView type);
169-
170-
virtual bool Equals(const EnumTypeInterface& other) const = 0;
171-
172-
virtual void HashValue(absl::HashState state) const = 0;
173162

174163
virtual absl::StatusOr<absl::optional<EnumTypeValueId>> FindIdByName(
175164
absl::string_view name) const ABSL_ATTRIBUTE_LIFETIME_BOUND = 0;
@@ -248,14 +237,12 @@ class EnumType {
248237
}
249238

250239
friend bool operator==(const EnumType& lhs, const EnumType& rhs) {
251-
return lhs.name() == rhs.name() && lhs.interface_->Equals(*rhs.interface_);
240+
return lhs.name() == rhs.name();
252241
}
253242

254243
template <typename H>
255244
friend H AbslHashValue(H state, const EnumType& type) {
256-
state = H::combine(std::move(state), type.kind(), type.name());
257-
type.interface_->HashValue(absl::HashState::Create(&state));
258-
return std::move(state);
245+
return H::combine(std::move(state), type.kind(), type.name());
259246
}
260247

261248
private:
@@ -453,14 +440,12 @@ class EnumTypeView {
453440
}
454441

455442
friend bool operator==(EnumTypeView lhs, EnumTypeView rhs) {
456-
return lhs.name() == rhs.name() && lhs.interface_->Equals(*rhs.interface_);
443+
return lhs.name() == rhs.name();
457444
}
458445

459446
template <typename H>
460447
friend H AbslHashValue(H state, EnumTypeView type) {
461-
state = H::combine(std::move(state), type.kind(), type.name());
462-
type.interface_->HashValue(absl::HashState::Create(&state));
463-
return std::move(state);
448+
return H::combine(std::move(state), type.kind(), type.name());
464449
}
465450

466451
private:

common/types/enum_type_test.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ class CustomEnumTypeInterface final
7474
private:
7575
friend class CustomEnumTypeValueIterator;
7676

77-
bool Equals(const EnumTypeInterface&) const override { return true; }
78-
79-
void HashValue(absl::HashState) const override {}
80-
8177
absl::StatusOr<absl::optional<EnumTypeValueId>> FindIdByName(
8278
absl::string_view name) const override {
8379
if (name == "FOO") {

0 commit comments

Comments
 (0)