Browse Source

WebUI: revise hash function

In benchmark, using `Math.imul()` is about ~20% faster than floating
point multiplication.

PR #15475.
adaptive-webui-19844
Chocobo1 3 years ago committed by GitHub
parent
commit
97a8d865dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/webui/www/private/scripts/client.js

9
src/webui/www/private/scripts/client.js

@ -88,11 +88,12 @@ const loadSelectedTracker = function() { @@ -88,11 +88,12 @@ const loadSelectedTracker = function() {
loadSelectedTracker();
function genHash(string) {
// origins:
// https://stackoverflow.com/a/8831937
// https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0
let hash = 0;
for (let i = 0; i < string.length; ++i) {
const c = string.charCodeAt(i);
hash = (c + hash * 31) | 0;
}
for (let i = 0; i < string.length; ++i)
hash = ((Math.imul(hash, 31) + string.charCodeAt(i)) | 0);
return hash;
}

Loading…
Cancel
Save