diff --git a/spectator-api/src/main/java/com/netflix/spectator/impl/Hash64.java b/spectator-api/src/main/java/com/netflix/spectator/impl/Hash64.java index fe0020e12..cf2efd512 100644 --- a/spectator-api/src/main/java/com/netflix/spectator/impl/Hash64.java +++ b/spectator-api/src/main/java/com/netflix/spectator/impl/Hash64.java @@ -141,10 +141,14 @@ public Hash64 updateString(CharSequence str) { /** Update the hash with the specified byte value. */ public Hash64 updateByte(byte value) { checkSpace(Byte.SIZE); + updateByteImpl(value); + return this; + } + + private void updateByteImpl(byte value) { final long v = ((long) value & 0xFFL) << bitPos; stripe[stripePos] |= v; bitPos += Byte.SIZE; - return this; } /** Update the hash with the specified byte values. */ @@ -156,17 +160,25 @@ public Hash64 updateBytes(byte[] values, int offset, int length) { // Complete current stripe for (int i = offset; i < s; ++i) { - updateByte(values[i]); + updateByteImpl(values[i]); } + if (++stripePos == stripe.length) { + processStripe(); + } + bitPos = 0; // Write long values for (int i = s; i < e; i += Long.BYTES) { - updateLong(UnsafeUtils.getLong(values, i)); + stripe[stripePos] = UnsafeUtils.getLong(values, i); + if (++stripePos == stripe.length) { + processStripe(); + } } // Write remaining bytes + stripe[stripePos] = 0L; for (int i = e; i < offset + length; ++i) { - updateByte(values[i]); + updateByteImpl(values[i]); } } else { for (int i = offset; i < offset + length; ++i) {