use bitshifting for magic perf boost

pull/670/head
Rich Harris 8 years ago
parent 71f1ac91ba
commit 7a877b5857

@ -3,6 +3,6 @@ export default function hash(str: string): number {
let hash = 5381;
let i = str.length;
while (i--) hash = (hash * 33) ^ str.charCodeAt(i);
while (i--) hash = ((hash << 5) + hash) ^ str.charCodeAt(i);
return hash >>> 0;
}

@ -27,7 +27,7 @@ export function hash(str) {
var hash = 5381;
var i = str.length;
while (i--) hash = (hash * 33) ^ str.charCodeAt(i);
while (i--) hash = ((hash << 5) + hash) ^ str.charCodeAt(i);
return hash >>> 0;
}

Loading…
Cancel
Save