MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / tr_static_init

Function tr_static_init

zlib/trees.c:238–316  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

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