Coverage Report

Created: 2025-07-18 07:00

/src/zlib-ng/insert_string_tpl.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef INSERT_STRING_H_
2
#define INSERT_STRING_H_
3
4
/* insert_string_tpl.h -- Private insert_string functions shared with more than
5
 *                        one insert string implementation
6
 *
7
 * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
8
 *
9
 * Copyright (C) 2013 Intel Corporation. All rights reserved.
10
 * Authors:
11
 *  Wajdi Feghali   <wajdi.k.feghali@intel.com>
12
 *  Jim Guilford    <james.guilford@intel.com>
13
 *  Vinodh Gopal    <vinodh.gopal@intel.com>
14
 *  Erdinc Ozturk   <erdinc.ozturk@intel.com>
15
 *  Jim Kukunas     <james.t.kukunas@linux.intel.com>
16
 *
17
 * Portions are Copyright (C) 2016 12Sided Technology, LLC.
18
 * Author:
19
 *  Phil Vachon     <pvachon@12sidedtech.com>
20
 *
21
 * For conditions of distribution and use, see copyright notice in zlib.h
22
 *
23
 */
24
25
#include "zmemory.h"
26
27
#ifndef HASH_CALC_OFFSET
28
418M
#  define HASH_CALC_OFFSET 0
29
#endif
30
#ifndef HASH_CALC_MASK
31
673M
#  define HASH_CALC_MASK HASH_MASK
32
#endif
33
#ifndef HASH_CALC_READ
34
#  if BYTE_ORDER == LITTLE_ENDIAN
35
#    define HASH_CALC_READ \
36
673M
        val = zng_memread_4(strstart);
37
#  else
38
#    define HASH_CALC_READ \
39
        val = ZSWAP32(zng_memread_4(strstart));
40
#  endif
41
#endif
42
43
/* ===========================================================================
44
 * Update a hash value with the given input byte
45
 * IN  assertion: all calls to UPDATE_HASH are made with consecutive
46
 *    input characters, so that a running hash key can be computed from the
47
 *    previous key instead of complete recalculation each time.
48
 */
49
0
Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) {
50
0
    HASH_CALC(h, val);
51
0
    return h & HASH_CALC_MASK;
52
0
}
Unexecuted instantiation: update_hash
Unexecuted instantiation: update_hash_roll
53
54
/* ===========================================================================
55
 * Quick insert string str in the dictionary and set match_head to the previous head
56
 * of the hash chain (the most recent string with same hash key). Return
57
 * the previous length of the hash chain.
58
 */
59
403M
Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) {
60
403M
    Pos head;
61
403M
    uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
62
403M
    uint32_t val, hm;
63
64
403M
    HASH_CALC_VAR_INIT;
65
403M
    HASH_CALC_READ;
66
403M
    HASH_CALC(HASH_CALC_VAR, val);
67
403M
    HASH_CALC_VAR &= HASH_CALC_MASK;
68
403M
    hm = HASH_CALC_VAR;
69
70
403M
    head = s->head[hm];
71
403M
    if (LIKELY(head != str)) {
72
403M
        s->prev[str & s->w_mask] = head;
73
403M
        s->head[hm] = (Pos)str;
74
403M
    }
75
403M
    return head;
76
403M
}
quick_insert_string
Line
Count
Source
59
403M
Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) {
60
403M
    Pos head;
61
403M
    uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
62
403M
    uint32_t val, hm;
63
64
403M
    HASH_CALC_VAR_INIT;
65
403M
    HASH_CALC_READ;
66
403M
    HASH_CALC(HASH_CALC_VAR, val);
67
403M
    HASH_CALC_VAR &= HASH_CALC_MASK;
68
403M
    hm = HASH_CALC_VAR;
69
70
403M
    head = s->head[hm];
71
403M
    if (LIKELY(head != str)) {
72
403M
        s->prev[str & s->w_mask] = head;
73
403M
        s->head[hm] = (Pos)str;
74
403M
    }
75
403M
    return head;
76
403M
}
Unexecuted instantiation: quick_insert_string_roll
77
78
/* ===========================================================================
79
 * Insert string str in the dictionary and set match_head to the previous head
80
 * of the hash chain (the most recent string with same hash key). Return
81
 * the previous length of the hash chain.
82
 * IN  assertion: all calls to INSERT_STRING are made with consecutive
83
 *    input characters and the first STD_MIN_MATCH bytes of str are valid
84
 *    (except for the last STD_MIN_MATCH-1 bytes of the input file).
85
 */
86
15.2M
Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) {
87
15.2M
    uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
88
15.2M
    uint8_t *strend = strstart + count;
89
90
285M
    for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) {
91
270M
        uint32_t val, hm;
92
93
270M
        HASH_CALC_VAR_INIT;
94
270M
        HASH_CALC_READ;
95
270M
        HASH_CALC(HASH_CALC_VAR, val);
96
270M
        HASH_CALC_VAR &= HASH_CALC_MASK;
97
270M
        hm = HASH_CALC_VAR;
98
99
270M
        Pos head = s->head[hm];
100
270M
        if (LIKELY(head != idx)) {
101
270M
            s->prev[idx & s->w_mask] = head;
102
270M
            s->head[hm] = idx;
103
270M
        }
104
270M
    }
105
15.2M
}
insert_string
Line
Count
Source
86
15.2M
Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) {
87
15.2M
    uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
88
15.2M
    uint8_t *strend = strstart + count;
89
90
285M
    for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) {
91
270M
        uint32_t val, hm;
92
93
270M
        HASH_CALC_VAR_INIT;
94
270M
        HASH_CALC_READ;
95
270M
        HASH_CALC(HASH_CALC_VAR, val);
96
270M
        HASH_CALC_VAR &= HASH_CALC_MASK;
97
270M
        hm = HASH_CALC_VAR;
98
99
270M
        Pos head = s->head[hm];
100
270M
        if (LIKELY(head != idx)) {
101
270M
            s->prev[idx & s->w_mask] = head;
102
270M
            s->head[hm] = idx;
103
270M
        }
104
270M
    }
105
15.2M
}
Unexecuted instantiation: insert_string_roll
106
#endif