1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 23:37:59 +00:00

WebUI: revise hash function

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

PR #15475.
This commit is contained in:
Chocobo1 2021-09-27 13:54:28 +08:00 committed by GitHub
parent 982133d9b6
commit 97a8d865dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}