diff --git a/common/src/main/java/io/netty/util/ByteString.java b/common/src/main/java/io/netty/util/ByteString.java index 258dcca610..6a2250ceec 100644 --- a/common/src/main/java/io/netty/util/ByteString.java +++ b/common/src/main/java/io/netty/util/ByteString.java @@ -393,15 +393,15 @@ public class ByteString { @Override public int hashCode() { - if (hash != 0) { - return hash; + int h = hash; + if (h == 0) { + for (int i = 0; i < value.length; ++i) { + h = h * HASH_CODE_PRIME ^ value[i] & HASH_CODE_PRIME; + } + + hash = h; } - - for (int i = 0; i < value.length; ++i) { - hash = hash * HASH_CODE_PRIME ^ value[i] & HASH_CODE_PRIME; - } - - return hash; + return h; } /**