MCPcopy Create free account
hub / github.com/RsyncProject/rsync / tr_static_init

Function tr_static_init

zlib/trees.c:231–311  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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