Coverage Report

Created: 2025-11-07 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mupdf/thirdparty/brotli/c/enc/backward_references.c
Line
Count
Source
1
/* Copyright 2013 Google Inc. All Rights Reserved.
2
3
   Distributed under MIT license.
4
   See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
*/
6
7
/* Function to find backward reference copies. */
8
9
#include "backward_references.h"
10
11
#include <brotli/types.h>
12
13
#include "../common/constants.h"
14
#include "../common/dictionary.h"
15
#include "../common/platform.h"
16
#include "command.h"
17
#include "compound_dictionary.h"
18
#include "dictionary_hash.h"
19
#include "encoder_dict.h"
20
#include "memory.h"
21
#include "quality.h"
22
23
#if defined(__cplusplus) || defined(c_plusplus)
24
extern "C" {
25
#endif
26
27
static BROTLI_INLINE size_t ComputeDistanceCode(size_t distance,
28
                                                size_t max_distance,
29
0
                                                const int* dist_cache) {
30
0
  if (distance <= max_distance) {
31
0
    size_t distance_plus_3 = distance + 3;
32
0
    size_t offset0 = distance_plus_3 - (size_t)dist_cache[0];
33
0
    size_t offset1 = distance_plus_3 - (size_t)dist_cache[1];
34
0
    if (distance == (size_t)dist_cache[0]) {
35
0
      return 0;
36
0
    } else if (distance == (size_t)dist_cache[1]) {
37
0
      return 1;
38
0
    } else if (offset0 < 7) {
39
0
      return (0x9750468 >> (4 * offset0)) & 0xF;
40
0
    } else if (offset1 < 7) {
41
0
      return (0xFDB1ACE >> (4 * offset1)) & 0xF;
42
0
    } else if (distance == (size_t)dist_cache[2]) {
43
0
      return 2;
44
0
    } else if (distance == (size_t)dist_cache[3]) {
45
0
      return 3;
46
0
    }
47
0
  }
48
0
  return distance + BROTLI_NUM_DISTANCE_SHORT_CODES - 1;
49
0
}
50
51
0
#define EXPAND_CAT(a, b) CAT(a, b)
52
0
#define CAT(a, b) a ## b
53
0
#define FN(X) EXPAND_CAT(X, HASHER())
54
#define EXPORT_FN(X) EXPAND_CAT(X, EXPAND_CAT(PREFIX(), HASHER()))
55
56
#define PREFIX() N
57
0
#define ENABLE_COMPOUND_DICTIONARY 0
58
59
0
#define HASHER() H2
60
/* NOLINTNEXTLINE(build/include) */
61
#include "backward_references_inc.h"
62
#undef HASHER
63
64
0
#define HASHER() H3
65
/* NOLINTNEXTLINE(build/include) */
66
#include "backward_references_inc.h"
67
#undef HASHER
68
69
0
#define HASHER() H4
70
/* NOLINTNEXTLINE(build/include) */
71
#include "backward_references_inc.h"
72
#undef HASHER
73
74
0
#define HASHER() H5
75
/* NOLINTNEXTLINE(build/include) */
76
#include "backward_references_inc.h"
77
#undef HASHER
78
79
0
#define HASHER() H6
80
/* NOLINTNEXTLINE(build/include) */
81
#include "backward_references_inc.h"
82
#undef HASHER
83
84
0
#define HASHER() H40
85
/* NOLINTNEXTLINE(build/include) */
86
#include "backward_references_inc.h"
87
#undef HASHER
88
89
0
#define HASHER() H41
90
/* NOLINTNEXTLINE(build/include) */
91
#include "backward_references_inc.h"
92
#undef HASHER
93
94
0
#define HASHER() H42
95
/* NOLINTNEXTLINE(build/include) */
96
#include "backward_references_inc.h"
97
#undef HASHER
98
99
0
#define HASHER() H54
100
/* NOLINTNEXTLINE(build/include) */
101
#include "backward_references_inc.h"
102
#undef HASHER
103
104
0
#define HASHER() H35
105
/* NOLINTNEXTLINE(build/include) */
106
#include "backward_references_inc.h"
107
#undef HASHER
108
109
0
#define HASHER() H55
110
/* NOLINTNEXTLINE(build/include) */
111
#include "backward_references_inc.h"
112
#undef HASHER
113
114
0
#define HASHER() H65
115
/* NOLINTNEXTLINE(build/include) */
116
#include "backward_references_inc.h"
117
#undef HASHER
118
119
#if defined(BROTLI_MAX_SIMD_QUALITY)
120
0
#define HASHER() H58
121
/* NOLINTNEXTLINE(build/include) */
122
#include "backward_references_inc.h"
123
#undef HASHER
124
125
0
#define HASHER() H68
126
/* NOLINTNEXTLINE(build/include) */
127
#include "backward_references_inc.h"
128
#undef HASHER
129
#endif
130
131
#undef ENABLE_COMPOUND_DICTIONARY
132
#undef PREFIX
133
#define PREFIX() D
134
0
#define ENABLE_COMPOUND_DICTIONARY 1
135
136
0
#define HASHER() H5
137
/* NOLINTNEXTLINE(build/include) */
138
#include "backward_references_inc.h"
139
#undef HASHER
140
0
#define HASHER() H6
141
/* NOLINTNEXTLINE(build/include) */
142
#include "backward_references_inc.h"
143
#undef HASHER
144
0
#define HASHER() H40
145
/* NOLINTNEXTLINE(build/include) */
146
#include "backward_references_inc.h"
147
#undef HASHER
148
0
#define HASHER() H41
149
/* NOLINTNEXTLINE(build/include) */
150
#include "backward_references_inc.h"
151
#undef HASHER
152
0
#define HASHER() H42
153
/* NOLINTNEXTLINE(build/include) */
154
#include "backward_references_inc.h"
155
#undef HASHER
156
0
#define HASHER() H55
157
/* NOLINTNEXTLINE(build/include) */
158
#include "backward_references_inc.h"
159
#undef HASHER
160
0
#define HASHER() H65
161
/* NOLINTNEXTLINE(build/include) */
162
#include "backward_references_inc.h"
163
#undef HASHER
164
#if defined(BROTLI_MAX_SIMD_QUALITY)
165
0
#define HASHER() H58
166
/* NOLINTNEXTLINE(build/include) */
167
#include "backward_references_inc.h"
168
#undef HASHER
169
0
#define HASHER() H68
170
/* NOLINTNEXTLINE(build/include) */
171
#include "backward_references_inc.h"
172
#undef HASHER
173
#endif
174
175
#undef ENABLE_COMPOUND_DICTIONARY
176
#undef PREFIX
177
178
#undef EXPORT_FN
179
#undef FN
180
#undef CAT
181
#undef EXPAND_CAT
182
183
void BrotliCreateBackwardReferences(size_t num_bytes,
184
    size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
185
    ContextLut literal_context_lut, const BrotliEncoderParams* params,
186
    Hasher* hasher, int* dist_cache, size_t* last_insert_len,
187
0
    Command* commands, size_t* num_commands, size_t* num_literals) {
188
0
  if (params->dictionary.compound.num_chunks != 0) {
189
0
    switch (params->hasher.type) {
190
0
#define CASE_(N)                                                    \
191
0
      case N:                                                       \
192
0
        CreateBackwardReferencesDH ## N(num_bytes,                  \
193
0
            position, ringbuffer, ringbuffer_mask,                  \
194
0
            literal_context_lut, params, hasher, dist_cache,        \
195
0
            last_insert_len, commands, num_commands, num_literals); \
196
0
        return;
197
0
      CASE_(5)
198
0
      CASE_(6)
199
0
#if defined(BROTLI_MAX_SIMD_QUALITY)
200
0
      CASE_(58)
201
0
      CASE_(68)
202
0
#endif
203
0
      CASE_(40)
204
0
      CASE_(41)
205
0
      CASE_(42)
206
0
      CASE_(55)
207
0
      CASE_(65)
208
0
#undef CASE_
209
0
      default:
210
0
        BROTLI_DCHECK(false);
211
0
        break;
212
0
    }
213
0
  }
214
215
0
  switch (params->hasher.type) {
216
0
#define CASE_(N)                                                  \
217
0
    case N:                                                       \
218
0
      CreateBackwardReferencesNH ## N(num_bytes,                  \
219
0
          position, ringbuffer, ringbuffer_mask,                  \
220
0
          literal_context_lut, params, hasher, dist_cache,        \
221
0
          last_insert_len, commands, num_commands, num_literals); \
222
0
      return;
223
0
    FOR_GENERIC_HASHERS(CASE_)
224
0
#undef CASE_
225
0
    default:
226
0
      BROTLI_DCHECK(false);
227
0
      break;
228
0
  }
229
0
}
230
231
#if defined(__cplusplus) || defined(c_plusplus)
232
}  /* extern "C" */
233
#endif