Skip to content

Commit

Permalink
API: add hashcode cache in StructType (#11764)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzx140 authored Jan 17, 2025
1 parent f895b33 commit bed7c33
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 @@ -729,6 +729,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 @@ -830,7 +833,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 bed7c33

Please sign in to comment.