mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-12 15:57:57 +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:
parent
982133d9b6
commit
97a8d865dc
@ -88,11 +88,12 @@ const loadSelectedTracker = function() {
|
|||||||
loadSelectedTracker();
|
loadSelectedTracker();
|
||||||
|
|
||||||
function genHash(string) {
|
function genHash(string) {
|
||||||
|
// origins:
|
||||||
|
// https://stackoverflow.com/a/8831937
|
||||||
|
// https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0
|
||||||
let hash = 0;
|
let hash = 0;
|
||||||
for (let i = 0; i < string.length; ++i) {
|
for (let i = 0; i < string.length; ++i)
|
||||||
const c = string.charCodeAt(i);
|
hash = ((Math.imul(hash, 31) + string.charCodeAt(i)) | 0);
|
||||||
hash = (c + hash * 31) | 0;
|
|
||||||
}
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user