Skip to content

Commit

Permalink
improved putByte and putBytes implementations for Wyhash
Browse files Browse the repository at this point in the history
  • Loading branch information
oertl committed Jul 31, 2024
1 parent e1d52cd commit 106a92e
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/main/java/com/dynatrace/hash4j/hashing/AbstractWyhashFinal.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,13 @@ public HashStream64 copy() {

@Override
public HashStream64 putByte(byte v) {
buffer[offset] = v;
offset += 1;
byteCount += 1;
if (offset > 48) {
if (offset >= 48) {
offset -= 48;
processBuffer();
buffer[0] = buffer[48];
}
buffer[offset] = v;
offset += 1;
byteCount += 1;
return this;
}

Expand Down Expand Up @@ -353,23 +352,24 @@ public HashStream64 putBytes(byte[] b, int off, int len) {
if (len > x) {
System.arraycopy(b, off, buffer, offset, x);
processBuffer();
int lenOrig = len;
len -= x;
off += x;
while (len > 48) {
long b0 = getLong(b, off);
long b1 = getLong(b, off + 8);
long b2 = getLong(b, off + 16);
long b3 = getLong(b, off + 24);
long b4 = getLong(b, off + 32);
long b5 = getLong(b, off + 40);
processBuffer(b0, b1, b2, b3, b4, b5);
off += 48;
len -= 48;
}
int y = 16 - len;
if (lenOrig > 48 && y > 0) {
System.arraycopy(b, off - y, buffer, 32 + len, y);
if (len > 48) {
do {
long b0 = getLong(b, off);
long b1 = getLong(b, off + 8);
long b2 = getLong(b, off + 16);
long b3 = getLong(b, off + 24);
long b4 = getLong(b, off + 32);
long b5 = getLong(b, off + 40);
processBuffer(b0, b1, b2, b3, b4, b5);
off += 48;
len -= 48;
} while (len > 48);
if (len < 16) {
int y = 16 - len;
System.arraycopy(b, off - y, buffer, 32 + len, y);
}
}
offset = 0;
}
Expand Down

0 comments on commit 106a92e

Please sign in to comment.