Skip to content

Commit 6201bb6

Browse files
committed
Runtime: fix caml_hash so that it can be optimized by Google Chrome
The JavaScript engine does not like integer multiplication by a 32-bit unsigned integer, so explicitly convert the constants to 32-bit signed integers.
1 parent 1b8a128 commit 6201bb6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

runtime/stdlib.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,18 +610,18 @@ function () {
610610
var HASH_QUEUE_SIZE = 256;
611611
function ROTL32(x,n) { return ((x << n) | (x >>> (32-n))); }
612612
function MIX(h,d) {
613-
d = caml_mul(d, 0xcc9e2d51);
613+
d = caml_mul(d, 0xcc9e2d51|0);
614614
d = ROTL32(d, 15);
615615
d = caml_mul(d, 0x1b873593);
616616
h ^= d;
617617
h = ROTL32(h, 13);
618-
return ((((h * 5)|0) + 0xe6546b64)|0);
618+
return (((h + (h << 2))|0) + (0xe6546b64|0))|0;
619619
}
620620
function FINAL_MIX(h) {
621621
h ^= h >>> 16;
622-
h = caml_mul (h, 0x85ebca6b);
622+
h = caml_mul (h, 0x85ebca6b|0);
623623
h ^= h >>> 13;
624-
h = caml_mul (h, 0xc2b2ae35);
624+
h = caml_mul (h, 0xc2b2ae35|0);
625625
h ^= h >>> 16;
626626
return h;
627627
}

0 commit comments

Comments
 (0)