MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / tr_static_init

Function tr_static_init

ZLib/trees.c:234–314  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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