… | |
… | |
70 | u8 *op = (u8 *)out_data; |
70 | u8 *op = (u8 *)out_data; |
71 | const u8 *in_end = ip + in_len; |
71 | const u8 *in_end = ip + in_len; |
72 | u8 *out_end = op + out_len; |
72 | u8 *out_end = op + out_len; |
73 | |
73 | |
74 | const u8 *first [1 << (6+8)]; /* most recent occurance of a match */ |
74 | const u8 *first [1 << (6+8)]; /* most recent occurance of a match */ |
75 | u16 prev [MAX_OFF]; /* how many bytes to go backwards for te next match */ |
75 | u16 prev [MAX_OFF]; /* how many bytes to go backwards for the next match */ |
76 | |
76 | |
77 | int lit; |
77 | int lit; |
78 | |
78 | |
79 | if (!in_len || !out_len) |
79 | if (!in_len || !out_len) |
80 | return 0; |
80 | return 0; |
… | |
… | |
86 | while (ip < in_end - 2) |
86 | while (ip < in_end - 2) |
87 | { |
87 | { |
88 | int best_l = 0; |
88 | int best_l = 0; |
89 | const u8 *best_p; |
89 | const u8 *best_p; |
90 | int e = (in_end - ip < MAX_REF ? in_end - ip : MAX_REF) - 1; |
90 | int e = (in_end - ip < MAX_REF ? in_end - ip : MAX_REF) - 1; |
91 | unsigned int res = ((unsigned int)ip) & (MAX_OFF - 1); |
91 | unsigned int res = ((unsigned long)ip) & (MAX_OFF - 1); |
92 | u16 hash = HASH (ip); |
92 | u16 hash = HASH (ip); |
93 | u16 diff; |
93 | u16 diff; |
94 | const u8 *b = ip < (u8 *)in_data + MAX_OFF ? in_data : ip - MAX_OFF; |
94 | const u8 *b = ip < (u8 *)in_data + MAX_OFF ? in_data : ip - MAX_OFF; |
95 | const u8 *p = first [hash]; |
95 | const u8 *p = first [hash]; |
96 | prev [res] = ip - p; /* update ptr to previous hash match */ |
96 | prev [res] = ip - p; /* update ptr to previous hash match */ |
… | |
… | |
113 | best_p = p; |
113 | best_p = p; |
114 | best_l = l; |
114 | best_l = l; |
115 | } |
115 | } |
116 | } |
116 | } |
117 | |
117 | |
118 | diff = prev [((unsigned int)p) & (MAX_OFF - 1)]; |
118 | diff = prev [((unsigned long)p) & (MAX_OFF - 1)]; |
119 | p = diff ? p - diff : 0; |
119 | p = diff ? p - diff : 0; |
120 | } |
120 | } |
121 | |
121 | |
122 | if (best_l) |
122 | if (best_l) |
123 | { |
123 | { |
… | |
… | |
157 | |
157 | |
158 | //printf (" fill %p for %d\n", ip, len);//D |
158 | //printf (" fill %p for %d\n", ip, len);//D |
159 | do |
159 | do |
160 | { |
160 | { |
161 | u16 hash = HASH (ip); |
161 | u16 hash = HASH (ip); |
162 | res = ((unsigned int)ip) & (MAX_OFF - 1); |
162 | res = ((unsigned long)ip) & (MAX_OFF - 1); |
163 | |
163 | |
164 | p = first [hash]; |
164 | p = first [hash]; |
165 | prev [res] = ip - p; /* update ptr to previous hash match */ |
165 | prev [res] = ip - p; /* update ptr to previous hash match */ |
166 | first [hash] = ip; /* first hash match is here */ |
166 | first [hash] = ip; /* first hash match is here */ |
167 | |
167 | |