Skip to content

Commit 3393960

Browse files
committed
core: Opaque: Cache hashCode value
We may frequently compare Opaques via HashMap. Cache the #hashCode computation once computed. Related: #149 Signed-off-by: Christian Kohlschütter <[email protected]>
1 parent 490b26e commit 3393960

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

core/src/main/java/org/dcache/nfs/util/Opaque.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ default void putBytes(ByteBuffer buf) {
134134
final class OpaqueImpl implements Opaque {
135135
private final byte[] _opaque;
136136
private String base64 = null;
137+
private int hashCode;
137138

138139
private OpaqueImpl(byte[] opaque) {
139140
_opaque = opaque;
@@ -159,7 +160,10 @@ public void putBytes(ByteBuffer buf) {
159160

160161
@Override
161162
public int hashCode() {
162-
return Arrays.hashCode(_opaque);
163+
if (hashCode == 0) {
164+
hashCode = Arrays.hashCode(_opaque);
165+
}
166+
return hashCode;
163167
}
164168

165169
@Override

0 commit comments

Comments
 (0)