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:
parent
982133d9b6
commit
97a8d865dc
@ -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…
Reference in New Issue
Block a user