From 7a877b585762f35df3ea46362ac2e499b5249b09 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 24 Jun 2017 19:42:11 -0400 Subject: [PATCH] use bitshifting for magic perf boost --- src/parse/utils/hash.ts | 2 +- src/shared/transitions.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parse/utils/hash.ts b/src/parse/utils/hash.ts index 8f2221ee49..4c6f9f14fe 100644 --- a/src/parse/utils/hash.ts +++ b/src/parse/utils/hash.ts @@ -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; } diff --git a/src/shared/transitions.js b/src/shared/transitions.js index f374ba52e4..df788bd888 100644 --- a/src/shared/transitions.js +++ b/src/shared/transitions.js @@ -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; }