mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-04 10:50:59 +01:00
Move hasher to separate function
This commit is contained in:
parent
5638105893
commit
677ba487ed
1 changed files with 15 additions and 8 deletions
|
@ -96,6 +96,13 @@ const zero = (buf) => {
|
|||
};
|
||||
|
||||
|
||||
/* eslint-disable new-cap */
|
||||
let HASH_ZLIB = (s, prev, data) => ((prev << s.hash_shift) ^ data) & s.hash_mask;
|
||||
// This hash causes less collisions, https://github.com/nodeca/pako/issues/135
|
||||
// But breaks binary compatibility
|
||||
//let HASH_FAST = (s, prev, data) => ((prev << 8) + (prev >> 8) + (data << 4)) & s.hash_mask;
|
||||
let HASH = HASH_ZLIB;
|
||||
|
||||
/* =========================================================================
|
||||
* Flush as much pending output as possible. All deflate() output goes
|
||||
* through this function so some applications may wish to modify it
|
||||
|
@ -395,13 +402,13 @@ const fill_window = (s) => {
|
|||
s.ins_h = s.window[str];
|
||||
|
||||
/* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
|
||||
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask;
|
||||
s.ins_h = HASH(s, s.ins_h, s.window[str + 1]);
|
||||
//#if MIN_MATCH != 3
|
||||
// Call update_hash() MIN_MATCH-3 more times
|
||||
//#endif
|
||||
while (s.insert) {
|
||||
/* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
|
||||
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
|
||||
s.ins_h = HASH(s, s.ins_h, s.window[str + MIN_MATCH - 1]);
|
||||
|
||||
s.prev[str & s.w_mask] = s.head[s.ins_h];
|
||||
s.head[s.ins_h] = str;
|
||||
|
@ -591,7 +598,7 @@ const deflate_fast = (s, flush) => {
|
|||
hash_head = 0/*NIL*/;
|
||||
if (s.lookahead >= MIN_MATCH) {
|
||||
/*** INSERT_STRING(s, s.strstart, hash_head); ***/
|
||||
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
||||
s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
|
||||
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
||||
s.head[s.ins_h] = s.strstart;
|
||||
/***/
|
||||
|
@ -625,7 +632,7 @@ const deflate_fast = (s, flush) => {
|
|||
do {
|
||||
s.strstart++;
|
||||
/*** INSERT_STRING(s, s.strstart, hash_head); ***/
|
||||
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
||||
s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
|
||||
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
||||
s.head[s.ins_h] = s.strstart;
|
||||
/***/
|
||||
|
@ -640,7 +647,7 @@ const deflate_fast = (s, flush) => {
|
|||
s.match_length = 0;
|
||||
s.ins_h = s.window[s.strstart];
|
||||
/* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
|
||||
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask;
|
||||
s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + 1]);
|
||||
|
||||
//#if MIN_MATCH != 3
|
||||
// Call UPDATE_HASH() MIN_MATCH-3 more times
|
||||
|
@ -721,7 +728,7 @@ const deflate_slow = (s, flush) => {
|
|||
hash_head = 0/*NIL*/;
|
||||
if (s.lookahead >= MIN_MATCH) {
|
||||
/*** INSERT_STRING(s, s.strstart, hash_head); ***/
|
||||
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
||||
s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
|
||||
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
||||
s.head[s.ins_h] = s.strstart;
|
||||
/***/
|
||||
|
@ -773,7 +780,7 @@ const deflate_slow = (s, flush) => {
|
|||
do {
|
||||
if (++s.strstart <= max_insert) {
|
||||
/*** INSERT_STRING(s, s.strstart, hash_head); ***/
|
||||
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
||||
s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
|
||||
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
||||
s.head[s.ins_h] = s.strstart;
|
||||
/***/
|
||||
|
@ -1798,7 +1805,7 @@ const deflateSetDictionary = (strm, dictionary) => {
|
|||
let n = s.lookahead - (MIN_MATCH - 1);
|
||||
do {
|
||||
/* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
|
||||
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
|
||||
s.ins_h = HASH(s, s.ins_h, s.window[str + MIN_MATCH - 1]);
|
||||
|
||||
s.prev[str & s.w_mask] = s.head[s.ins_h];
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue