mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-04 10:50:59 +01:00
slightly optimized adler with forced casts
This commit is contained in:
parent
8a49fcd212
commit
ccf2586dba
1 changed files with 9 additions and 6 deletions
|
@ -5,24 +5,27 @@
|
|||
// Small size is preferable.
|
||||
|
||||
function adler32(adler, buf, len, pos) {
|
||||
var s1 = adler & 0xffff
|
||||
, s2 = (adler >>> 16) & 0xffff
|
||||
var s1 = (adler & 0xffff) |0
|
||||
, s2 = ((adler >>> 16) & 0xffff) |0
|
||||
, n = 0;
|
||||
|
||||
while (len !== 0) {
|
||||
n = len > 5552 ? 5552 : len;
|
||||
// Set limit ~ twice less than 5552, to keep
|
||||
// s2 in 31-bits, because we force signed ints.
|
||||
// in other case %= will fail.
|
||||
n = len > 2000 ? 2000 : len;
|
||||
len -= n;
|
||||
|
||||
do {
|
||||
s1 += buf[pos++];
|
||||
s2 += s1;
|
||||
s1 = (s1 + buf[pos++]) |0;
|
||||
s2 = (s2 + s1) |0;
|
||||
} while (--n);
|
||||
|
||||
s1 %= 65521;
|
||||
s2 %= 65521;
|
||||
}
|
||||
|
||||
return (s1 | (s2 << 16));
|
||||
return (s1 | (s2 << 16)) |0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue