Skip to content

Commit

Permalink
Make primitiveStringHash slightly more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Nov 4, 2024
1 parent 4e1c15e commit 159e66d
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ protected static final long doNativeObject(@SuppressWarnings("unused") final Obj

private abstract static class AbstractPrimStringHashNode extends AbstractPrimitiveNode {
protected static final long calculateHash(final long initialHash, final byte[] bytes) {
long hash = initialHash & PrimHashMultiplyNode.HASH_MULTIPLY_MASK;
// Using int here is sufficient and slightly more efficient
int hash = (int) initialHash & PrimHashMultiplyNode.HASH_MULTIPLY_MASK;
final int length = bytes.length;
for (int i = 0; i < length; i++) {
hash = (hash + (UnsafeUtils.getByte(bytes, i) & 0xff)) * PrimHashMultiplyNode.HASH_MULTIPLY_CONSTANT & PrimHashMultiplyNode.HASH_MULTIPLY_MASK;
Expand Down

0 comments on commit 159e66d

Please sign in to comment.