From a235a8a19683452f754ce9b04acb0bcdd4841fdc Mon Sep 17 00:00:00 2001 From: Otmar Ertl Date: Wed, 31 Jul 2024 09:36:36 +0200 Subject: [PATCH] improved putByte and putChar implementations for FarmHash --- .../hash4j/hashing/AbstractFarmHash.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/dynatrace/hash4j/hashing/AbstractFarmHash.java b/src/main/java/com/dynatrace/hash4j/hashing/AbstractFarmHash.java index b384061b..c5d9d564 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/AbstractFarmHash.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/AbstractFarmHash.java @@ -272,12 +272,11 @@ private void processBuffer() { @Override public final HashStream64 putByte(byte v) { - buffer[bufferCount] = v; if (bufferCount >= 72) { processBuffer(); bufferCount = 8; - buffer[8] = v; } + buffer[bufferCount] = v; bufferCount += 1; return this; } @@ -294,6 +293,18 @@ public final HashStream64 putShort(short v) { return this; } + @Override + public final HashStream64 putChar(char v) { + setChar(buffer, bufferCount, v); + if (bufferCount >= 71) { + processBuffer(); + bufferCount -= 64; + setChar(buffer, bufferCount, v); + } + bufferCount += 2; + return this; + } + @Override public final HashStream64 putInt(int v) { setInt(buffer, bufferCount, v);