Coverage Report

Created: 2026-09-01 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zlib-ng/deflate_huff.c
Line
Count
Source
1
/* deflate_huff.c -- compress data using huffman encoding only strategy
2
 *
3
 * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
4
 * For conditions of distribution and use, see copyright notice in zlib.h
5
 */
6
7
#include "zbuild.h"
8
#include "deflate.h"
9
#include "deflate_p.h"
10
#include "functable.h"
11
12
/* ===========================================================================
13
 * For Z_HUFFMAN_ONLY, do not look for matches.  Do not maintain a hash table.
14
 * (It will be regenerated if this run of deflate switches away from Huffman.)
15
 */
16
1.17k
Z_INTERNAL block_state deflate_huff(deflate_state *s, int flush) {
17
1.17k
    unsigned char *window = s->window;
18
1.17k
    int bflush = 0;         /* set if current block must be flushed */
19
1.17k
    unsigned int lookahead = s->lookahead;
20
1.17k
    unsigned int strstart = s->strstart;
21
22
5.31M
    for (;;) {
23
        /* Make sure that we have a literal to write. */
24
5.31M
        if (UNLIKELY(lookahead == 0)) {
25
7.80k
            s->lookahead = lookahead;
26
7.80k
            s->strstart = strstart;
27
7.80k
            PREFIX(fill_window)(s);
28
7.80k
            lookahead = s->lookahead;
29
7.80k
            strstart = s->strstart;
30
7.80k
            if (UNLIKELY(lookahead == 0)) {
31
1.17k
                if (flush == Z_NO_FLUSH)
32
0
                    return need_more;
33
1.17k
                break;      /* flush the current block */
34
1.17k
            }
35
7.80k
        }
36
37
        /* Output a literal byte */
38
5.31M
        bflush = zng_tr_tally_lit(s, window[strstart]);
39
5.31M
        lookahead--;
40
5.31M
        strstart++;
41
5.31M
        if (bflush) {
42
16.9k
            s->lookahead = lookahead;
43
16.9k
            s->strstart = strstart;
44
16.9k
            FLUSH_BLOCK(s, window, 0);
45
16.9k
        }
46
5.31M
    }
47
1.17k
    s->lookahead = lookahead;
48
1.17k
    s->strstart = strstart;
49
1.17k
    s->insert = 0;
50
1.17k
    if (flush == Z_FINISH) {
51
1.17k
        FLUSH_BLOCK(s, window, 1);
52
1.17k
        return finish_done;
53
1.17k
    }
54
0
    if (s->sym_next)
55
0
        FLUSH_BLOCK(s, window, 0);
56
0
    return block_done;
57
0
}