Skip to content

Commit 9c008f1

Browse files
committed
Speedup equals
1 parent a152b4e commit 9c008f1

File tree

11 files changed

+75
-49
lines changed

11 files changed

+75
-49
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Attribute.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@ public int hashCode() {
118118

119119
@Override
120120
public boolean equals(Object obj) {
121-
if (super.equals(obj)) {
122-
Attribute other = (Attribute) obj;
123-
return Objects.equals(nullability, other.nullability);
121+
if (this == obj) {
122+
return true;
124123
}
125-
126-
return false;
124+
if (obj == null || getClass() != obj.getClass() || super.equals(obj) == false) {
125+
return false;
126+
}
127+
Attribute other = (Attribute) obj;
128+
return Objects.equals(nullability, other.nullability);
127129
}
128130

129131
@Override

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/EmptyAttribute.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ public boolean equals(Object obj) {
6969
if (this == obj) {
7070
return true;
7171
}
72-
7372
if (obj == null || getClass() != obj.getClass()) {
7473
return false;
7574
}
76-
7775
return true;
7876
}
7977
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/EntryExpression.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public boolean equals(Object obj) {
9999
if (obj == null || getClass() != obj.getClass()) {
100100
return false;
101101
}
102-
103102
EntryExpression other = (EntryExpression) obj;
104103
return Objects.equals(key, other.key) && Objects.equals(value, other.value);
105104
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/FieldAttribute.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,20 @@ public Attribute withDataType(DataType type) {
223223
}
224224

225225
@Override
226-
public int hashCode() {
227-
return Objects.hash(super.hashCode(), parentName, field);
226+
public boolean equals(Object o) {
227+
if (this == o) {
228+
return true;
229+
}
230+
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
231+
return false;
232+
}
233+
FieldAttribute that = (FieldAttribute) o;
234+
return Objects.equals(parentName, that.parentName) && Objects.equals(field, that.field);
228235
}
229236

230237
@Override
231-
public boolean equals(Object obj) {
232-
return super.equals(obj)
233-
&& Objects.equals(parentName, ((FieldAttribute) obj).parentName)
234-
&& Objects.equals(field, ((FieldAttribute) obj).field);
238+
public int hashCode() {
239+
return Objects.hash(super.hashCode(), parentName, field);
235240
}
236241

237242
@Override

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/MetadataAttribute.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,15 @@ public static boolean isSupported(String name) {
173173
}
174174

175175
@Override
176-
public boolean equals(Object obj) {
177-
if (false == super.equals(obj)) {
176+
public boolean equals(Object o) {
177+
if (this == o) {
178+
return true;
179+
}
180+
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
178181
return false;
179182
}
180-
MetadataAttribute other = (MetadataAttribute) obj;
181-
return searchable == other.searchable;
183+
MetadataAttribute that = (MetadataAttribute) o;
184+
return searchable == that.searchable;
182185
}
183186

184187
@Override

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/NamedExpression.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ public boolean equals(Object obj) {
6969
if (obj == null || getClass() != obj.getClass()) {
7070
return false;
7171
}
72-
7372
NamedExpression other = (NamedExpression) obj;
74-
return Objects.equals(synthetic, other.synthetic)
73+
return synthetic == other.synthetic
7574
/*
7675
* It is important that the line below be `name`
7776
* and not `name()` because subclasses might override

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypedAttribute.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,19 @@ public DataType dataType() {
3434
}
3535

3636
@Override
37-
public int hashCode() {
38-
return Objects.hash(super.hashCode(), dataType);
37+
public boolean equals(Object o) {
38+
if (this == o) {
39+
return true;
40+
}
41+
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
42+
return false;
43+
}
44+
TypedAttribute that = (TypedAttribute) o;
45+
return dataType == that.dataType;
3946
}
4047

4148
@Override
42-
public boolean equals(Object obj) {
43-
return super.equals(obj) && Objects.equals(dataType, ((TypedAttribute) obj).dataType);
49+
public int hashCode() {
50+
return Objects.hash(super.hashCode(), dataType);
4451
}
4552
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/UnresolvedAttribute.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,21 @@ public static String errorMessage(String name, List<String> potentialMatches) {
119119
}
120120

121121
@Override
122-
public int hashCode() {
123-
return Objects.hash(super.hashCode(), resolutionMetadata, unresolvedMsg);
122+
public boolean equals(Object o) {
123+
if (this == o) {
124+
return true;
125+
}
126+
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
127+
return false;
128+
}
129+
UnresolvedAttribute that = (UnresolvedAttribute) o;
130+
return customMessage == that.customMessage
131+
&& Objects.equals(unresolvedMsg, that.unresolvedMsg)
132+
&& Objects.equals(resolutionMetadata, that.resolutionMetadata);
124133
}
125134

126135
@Override
127-
public boolean equals(Object obj) {
128-
if (super.equals(obj)) {
129-
UnresolvedAttribute ua = (UnresolvedAttribute) obj;
130-
return Objects.equals(resolutionMetadata, ua.resolutionMetadata) && Objects.equals(unresolvedMsg, ua.unresolvedMsg);
131-
}
132-
return false;
136+
public int hashCode() {
137+
return Objects.hash(super.hashCode(), resolutionMetadata, unresolvedMsg);
133138
}
134139
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/UnresolvedStar.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ public boolean equals(Object obj) {
7070
* to ignore it in equals for the transform
7171
* tests to pass.
7272
*/
73+
if (this == obj) {
74+
return true;
75+
}
7376
if (obj == null || obj.getClass() != getClass()) {
7477
return false;
7578
}
76-
7779
UnresolvedStar other = (UnresolvedStar) obj;
7880
return Objects.equals(qualifier, other.qualifier);
7981
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/UnresolvedNamePattern.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,20 @@ public Nullability nullable() {
9898
}
9999

100100
@Override
101-
public int hashCode() {
102-
return Objects.hash(super.hashCode(), pattern);
101+
public boolean equals(Object o) {
102+
if (this == o) {
103+
return true;
104+
}
105+
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
106+
return false;
107+
}
108+
UnresolvedNamePattern that = (UnresolvedNamePattern) o;
109+
return Objects.equals(pattern, that.pattern);
103110
}
104111

105112
@Override
106-
public boolean equals(Object obj) {
107-
if (super.equals(obj)) {
108-
UnresolvedNamePattern ua = (UnresolvedNamePattern) obj;
109-
return Objects.equals(pattern, ua.pattern);
110-
}
111-
return false;
113+
public int hashCode() {
114+
return Objects.hash(super.hashCode(), pattern);
112115
}
113116

114117
@Override

0 commit comments

Comments
 (0)