MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / tr_static_init

Function tr_static_init

extlibs/minizip/src/trees.c:233–313  ·  view source on GitHub ↗

=========================================================================== * Initialize the various 'constant' tables. */

Source from the content-addressed store, hash-verified

231 * Initialize the various 'constant' tables.
232 */
233local void tr_static_init()
234{
235#if defined(GEN_TREES_H) || !defined(STDC)
236 static int static_init_done = 0;
237 int n; /* iterates over tree elements */
238 int bits; /* bit counter */
239 int length; /* length value */
240 int code; /* code value */
241 int dist; /* distance index */
242 ush bl_count[MAX_BITS+1];
243 /* number of codes at each bit length for an optimal tree */
244
245 if (static_init_done) return;
246
247 /* For some embedded targets, global variables are not initialized: */
248#ifdef NO_INIT_GLOBAL_POINTERS
249 static_l_desc.static_tree = static_ltree;
250 static_l_desc.extra_bits = extra_lbits;
251 static_d_desc.static_tree = static_dtree;
252 static_d_desc.extra_bits = extra_dbits;
253 static_bl_desc.extra_bits = extra_blbits;
254#endif
255
256 /* Initialize the mapping length (0..255) -> length code (0..28) */
257 length = 0;
258 for (code = 0; code < LENGTH_CODES-1; code++) {
259 base_length[code] = length;
260 for (n = 0; n < (1<<extra_lbits[code]); n++) {
261 _length_code[length++] = (uch)code;
262 }
263 }
264 Assert (length == 256, "tr_static_init: length != 256");
265 /* Note that the length 255 (match length 258) can be represented
266 * in two different ways: code 284 + 5 bits or code 285, so we
267 * overwrite length_code[255] to use the best encoding:
268 */
269 _length_code[length-1] = (uch)code;
270
271 /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
272 dist = 0;
273 for (code = 0 ; code < 16; code++) {
274 base_dist[code] = dist;
275 for (n = 0; n < (1<<extra_dbits[code]); n++) {
276 _dist_code[dist++] = (uch)code;
277 }
278 }
279 Assert (dist == 256, "tr_static_init: dist != 256");
280 dist >>= 7; /* from now on, all distances are divided by 128 */
281 for ( ; code < D_CODES; code++) {
282 base_dist[code] = dist << 7;
283 for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
284 _dist_code[256 + dist++] = (uch)code;
285 }
286 }
287 Assert (dist == 256, "tr_static_init: 256+dist != 512");
288
289 /* Construct the codes of the static literal tree */
290 for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;

Callers 1

_tr_initFunction · 0.85

Calls 3

gen_codesFunction · 0.85
bi_reverseFunction · 0.85
gen_trees_headerFunction · 0.85

Tested by

no test coverage detected