Skip to content

Commit

Permalink
API: add hashcode cache in StructType
Browse files Browse the repository at this point in the history
  • Loading branch information
wzx140 committed Dec 12, 2024
1 parent ff81344 commit f25c89b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/src/main/java/org/apache/iceberg/types/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ public int hashCode() {

public static class StructType extends NestedType {
private static final Joiner FIELD_SEP = Joiner.on(", ");
private static final int NO_HASHCODE = Integer.MIN_VALUE;

private transient int hashCode = NO_HASHCODE;

public static StructType of(NestedField... fields) {
return of(Arrays.asList(fields));
Expand Down Expand Up @@ -824,7 +827,10 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(NestedField.class, Arrays.hashCode(fields));
if (hashCode == NO_HASHCODE) {
hashCode = Objects.hash(NestedField.class, Arrays.hashCode(fields));
}
return hashCode;
}

private List<NestedField> lazyFieldList() {
Expand Down

0 comments on commit f25c89b

Please sign in to comment.