MCPcopy Create free account
hub / github.com/F-Stack/f-stack / tr_static_init

Function tr_static_init

freebsd/contrib/zlib/trees.c:232–312  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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