Coverage Report

Created: 2026-11-23 06:53

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
3.04k
Z_INTERNAL block_state deflate_huff(deflate_state *s, int flush) {
17
3.04k
    unsigned char *window = s->window;
18
3.04k
    int bflush = 0;         /* set if current block must be flushed */
19
3.04k
    unsigned int lookahead = s->lookahead;
20
3.04k
    unsigned int strstart = s->strstart;
21
22
119M
    for (;;) {
23
        /* Make sure that we have a literal to write. */
24
119M
        if (UNLIKELY(lookahead == 0)) {
25
14.1k
            s->lookahead = lookahead;
26
14.1k
            s->strstart = strstart;
27
14.1k
            PREFIX(fill_window)(s);
28
14.1k
            lookahead = s->lookahead;
29
14.1k
            strstart = s->strstart;
30
14.1k
            if (UNLIKELY(lookahead == 0)) {
31
2.69k
                if (flush == Z_NO_FLUSH)
32
661
                    return need_more;
33
2.03k
                break;      /* flush the current block */
34
2.69k
            }
35
14.1k
        }
36
37
        /* Output a literal byte */
38
119M
        bflush = zng_tr_tally_lit(s, window[strstart]);
39
119M
        lookahead--;
40
119M
        strstart++;
41
119M
        if (bflush) {
42
25.3k
            s->lookahead = lookahead;
43
25.3k
            s->strstart = strstart;
44
25.3k
            FLUSH_BLOCK(s, window, 0);
45
25.0k
        }
46
119M
    }
47
2.03k
    s->lookahead = lookahead;
48
2.03k
    s->strstart = strstart;
49
2.03k
    s->insert = 0;
50
2.03k
    if (flush == Z_FINISH) {
51
2.03k
        FLUSH_BLOCK(s, window, 1);
52
1.95k
        return finish_done;
53
2.03k
    }
54
0
    if (s->sym_next)
55
0
        FLUSH_BLOCK(s, window, 0);
56
0
    return block_done;
57
0
}