Skip to content

Commit

Permalink
improved putByte and putChar implementations for FarmHash
Browse files Browse the repository at this point in the history
  • Loading branch information
oertl committed Jul 31, 2024
1 parent d081a42 commit a235a8a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/com/dynatrace/hash4j/hashing/AbstractFarmHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down

0 comments on commit a235a8a

Please sign in to comment.