Coverage Report

Created: 2025-07-12 06:36

/src/rust-brotli/src/enc/metablock.rs
Line
Count
Source (jump to first uncovered line)
1
use core;
2
use core::cmp::{max, min};
3
4
use super::super::alloc;
5
use super::super::alloc::{Allocator, SliceWrapper, SliceWrapperMut};
6
use super::backward_references::BrotliEncoderParams;
7
use super::bit_cost::{BitsEntropy, BrotliPopulationCost};
8
use super::block_split::BlockSplit;
9
use super::block_splitter::BrotliSplitBlock;
10
use super::brotli_bit_stream::MetaBlockSplit;
11
use super::cluster::BrotliClusterHistograms;
12
use super::combined_alloc::BrotliAlloc;
13
use super::command::{BrotliDistanceParams, Command, PrefixEncodeCopyDistance};
14
use super::constants::BROTLI_MAX_NPOSTFIX;
15
use super::encode::{
16
    BROTLI_DISTANCE_ALPHABET_SIZE, BROTLI_LARGE_MAX_DISTANCE_BITS, BROTLI_MAX_ALLOWED_DISTANCE,
17
    BROTLI_MAX_DISTANCE_BITS,
18
};
19
use super::entropy_encode::BrotliOptimizeHuffmanCountsForRle;
20
use super::histogram::{
21
    BrotliBuildHistogramsWithContext, ClearHistograms, Context, ContextType, CostAccessors,
22
    HistogramAddHistogram, HistogramAddItem, HistogramClear, HistogramCommand, HistogramDistance,
23
    HistogramLiteral,
24
};
25
use crate::enc::combined_alloc::{alloc_default, allocate};
26
use crate::enc::floatX;
27
28
173k
pub fn BrotliInitDistanceParams(params: &mut BrotliEncoderParams, npostfix: u32, ndirect: u32) {
29
173k
    let dist_params = &mut params.dist;
30
173k
    let mut alphabet_size;
31
173k
    let mut max_distance;
32
173k
33
173k
    dist_params.distance_postfix_bits = npostfix;
34
173k
    dist_params.num_direct_distance_codes = ndirect;
35
173k
36
173k
    alphabet_size = BROTLI_DISTANCE_ALPHABET_SIZE(npostfix, ndirect, BROTLI_MAX_DISTANCE_BITS);
37
173k
    max_distance =
38
173k
        ndirect + (1u32 << (BROTLI_MAX_DISTANCE_BITS + npostfix + 2)) - (1u32 << (npostfix + 2));
39
173k
40
173k
    if (params.large_window) {
41
0
        let bound: [u32; BROTLI_MAX_NPOSTFIX + 1] = [0, 4, 12, 28];
42
0
        let postfix = 1u32 << npostfix;
43
0
        alphabet_size =
44
0
            BROTLI_DISTANCE_ALPHABET_SIZE(npostfix, ndirect, BROTLI_LARGE_MAX_DISTANCE_BITS);
45
0
        /* The maximum distance is set so that no distance symbol used can encode
46
0
        a distance larger than BROTLI_MAX_ALLOWED_DISTANCE with all
47
0
        its extra bits set. */
48
0
        if (ndirect < bound[npostfix as usize]) {
49
0
            max_distance =
50
0
                BROTLI_MAX_ALLOWED_DISTANCE as u32 - (bound[npostfix as usize] - ndirect);
51
0
        } else if (ndirect >= bound[npostfix as usize] + postfix) {
52
0
            max_distance = (3u32 << 29) - 4 + (ndirect - bound[npostfix as usize]);
53
0
        } else {
54
0
            max_distance = BROTLI_MAX_ALLOWED_DISTANCE as u32;
55
0
        }
56
173k
    }
57
58
173k
    dist_params.alphabet_size = alphabet_size;
59
173k
    dist_params.max_distance = max_distance as usize;
60
173k
}
61
62
6.68k
fn RecomputeDistancePrefixes(
63
6.68k
    cmds: &mut [Command],
64
6.68k
    num_commands: usize,
65
6.68k
    orig_params: &BrotliDistanceParams,
66
6.68k
    new_params: &BrotliDistanceParams,
67
6.68k
) {
68
6.68k
    if orig_params.distance_postfix_bits == new_params.distance_postfix_bits
69
2.58k
        && orig_params.num_direct_distance_codes == new_params.num_direct_distance_codes
70
    {
71
837
        return;
72
5.85k
    }
73
74
3.66M
    for cmd in cmds.split_at_mut(num_commands).0.iter_mut() {
75
3.66M
        if (cmd.copy_len() != 0 && cmd.cmd_prefix_ >= 128) {
76
2.21M
            let ret = cmd.restore_distance_code(orig_params);
77
2.21M
            PrefixEncodeCopyDistance(
78
2.21M
                ret as usize,
79
2.21M
                new_params.num_direct_distance_codes as usize,
80
2.21M
                new_params.distance_postfix_bits as u64,
81
2.21M
                &mut cmd.dist_prefix_,
82
2.21M
                &mut cmd.dist_extra_,
83
2.21M
            );
84
2.21M
        }
85
    }
86
6.68k
}
87
88
159k
fn ComputeDistanceCost(
89
159k
    cmds: &[Command],
90
159k
    num_commands: usize,
91
159k
    orig_params: &BrotliDistanceParams,
92
159k
    new_params: &BrotliDistanceParams,
93
159k
    scratch: &mut <HistogramDistance as CostAccessors>::i32vec,
94
159k
    cost: &mut f64,
95
159k
) -> bool {
96
159k
    let mut equal_params = false;
97
159k
    let mut dist_prefix: u16 = 0;
98
159k
    let mut dist_extra: u32 = 0;
99
159k
    let mut extra_bits: f64 = 0.0;
100
159k
    let mut histo = HistogramDistance::default();
101
159k
102
159k
    if (orig_params.distance_postfix_bits == new_params.distance_postfix_bits
103
64.4k
        && orig_params.num_direct_distance_codes == new_params.num_direct_distance_codes)
104
6.68k
    {
105
6.68k
        equal_params = true;
106
153k
    }
107
47.8M
    for cmd in cmds.split_at(num_commands).0 {
108
47.8M
        if cmd.copy_len() != 0 && cmd.cmd_prefix_ >= 128 {
109
26.9M
            if equal_params {
110
2.56M
                dist_prefix = cmd.dist_prefix_;
111
2.56M
            } else {
112
24.3M
                let distance = cmd.restore_distance_code(orig_params);
113
24.3M
                if distance > new_params.max_distance as u32 {
114
0
                    return false;
115
24.3M
                }
116
24.3M
                PrefixEncodeCopyDistance(
117
24.3M
                    distance as usize,
118
24.3M
                    new_params.num_direct_distance_codes as usize,
119
24.3M
                    new_params.distance_postfix_bits as u64,
120
24.3M
                    &mut dist_prefix,
121
24.3M
                    &mut dist_extra,
122
24.3M
                );
123
            }
124
26.9M
            HistogramAddItem(&mut histo, (dist_prefix & 0x03ff) as usize);
125
26.9M
            extra_bits += (dist_prefix >> 10) as f64;
126
20.9M
        }
127
    }
128
129
159k
    *cost = BrotliPopulationCost(&histo, scratch) as f64 + extra_bits;
130
159k
    true
131
159k
}
132
133
6.68k
pub fn BrotliBuildMetaBlock<Alloc: BrotliAlloc>(
134
6.68k
    alloc: &mut Alloc,
135
6.68k
    ringbuffer: &[u8],
136
6.68k
    pos: usize,
137
6.68k
    mask: usize,
138
6.68k
    params: &mut BrotliEncoderParams,
139
6.68k
    prev_byte: u8,
140
6.68k
    prev_byte2: u8,
141
6.68k
    cmds: &mut [Command],
142
6.68k
    num_commands: usize,
143
6.68k
    literal_context_mode: ContextType,
144
6.68k
    lit_scratch_space: &mut <HistogramLiteral as CostAccessors>::i32vec,
145
6.68k
    cmd_scratch_space: &mut <HistogramCommand as CostAccessors>::i32vec,
146
6.68k
    dst_scratch_space: &mut <HistogramDistance as CostAccessors>::i32vec,
147
6.68k
    mb: &mut MetaBlockSplit<Alloc>,
148
6.68k
) {
149
    static kMaxNumberOfHistograms: usize = 256usize;
150
    let mut distance_histograms: <Alloc as Allocator<HistogramDistance>>::AllocatedMemory;
151
    let mut literal_histograms: <Alloc as Allocator<HistogramLiteral>>::AllocatedMemory;
152
6.68k
    let mut literal_context_modes = alloc_default::<ContextType, Alloc>();
153
6.68k
154
6.68k
    let mut i: usize;
155
6.68k
    let mut literal_context_multiplier: usize = 1;
156
6.68k
    let mut ndirect_msb: u32 = 0;
157
6.68k
    let mut check_orig = true;
158
6.68k
    if !params.avoid_distance_prefix_search {
159
6.68k
        let mut best_dist_cost: f64 = 1e99;
160
6.68k
        let orig_params = params.clone();
161
6.68k
        let mut new_params = params.clone();
162
163
26.7k
        for npostfix in 0..(BROTLI_MAX_NPOSTFIX + 1) {
164
171k
            while ndirect_msb < 16 {
165
159k
                let ndirect = ndirect_msb << npostfix;
166
159k
167
159k
                let mut dist_cost: f64 = 0.0;
168
159k
                BrotliInitDistanceParams(&mut new_params, npostfix as u32, ndirect);
169
159k
                if npostfix as u32 == orig_params.dist.distance_postfix_bits
170
64.4k
                    && ndirect == orig_params.dist.num_direct_distance_codes
171
6.68k
                {
172
6.68k
                    check_orig = false;
173
153k
                }
174
159k
                let skip: bool = !ComputeDistanceCost(
175
159k
                    cmds,
176
159k
                    num_commands,
177
159k
                    &orig_params.dist,
178
159k
                    &new_params.dist,
179
159k
                    dst_scratch_space,
180
159k
                    &mut dist_cost,
181
159k
                );
182
159k
                if skip || (dist_cost > best_dist_cost) {
183
14.7k
                    break;
184
145k
                }
185
145k
                best_dist_cost = dist_cost;
186
145k
                params.dist = new_params.dist;
187
145k
                ndirect_msb += 1;
188
            }
189
26.7k
            ndirect_msb = ndirect_msb.saturating_sub(1);
190
26.7k
            ndirect_msb /= 2;
191
        }
192
6.68k
        if check_orig {
193
0
            let mut dist_cost: f64 = 0.0;
194
0
            ComputeDistanceCost(
195
0
                cmds,
196
0
                num_commands,
197
0
                &orig_params.dist,
198
0
                &orig_params.dist,
199
0
                dst_scratch_space,
200
0
                &mut dist_cost,
201
0
            );
202
0
            if dist_cost < best_dist_cost {
203
0
                // best_dist_cost = dist_cost; unused
204
0
                params.dist = orig_params.dist;
205
0
            }
206
6.68k
        }
207
6.68k
        RecomputeDistancePrefixes(cmds, num_commands, &orig_params.dist, &params.dist);
208
0
    }
209
6.68k
    BrotliSplitBlock(
210
6.68k
        alloc,
211
6.68k
        cmds,
212
6.68k
        num_commands,
213
6.68k
        ringbuffer,
214
6.68k
        pos,
215
6.68k
        mask,
216
6.68k
        params,
217
6.68k
        lit_scratch_space,
218
6.68k
        cmd_scratch_space,
219
6.68k
        dst_scratch_space,
220
6.68k
        &mut mb.literal_split,
221
6.68k
        &mut mb.command_split,
222
6.68k
        &mut mb.distance_split,
223
6.68k
    );
224
6.68k
    if params.disable_literal_context_modeling == 0 {
225
6.68k
        literal_context_multiplier = (1i32 << 6) as usize;
226
6.68k
        literal_context_modes = allocate::<ContextType, _>(alloc, mb.literal_split.num_types);
227
18.4k
        for item in literal_context_modes.slice_mut().iter_mut() {
228
18.4k
            *item = literal_context_mode;
229
18.4k
        }
230
0
    }
231
6.68k
    let literal_histograms_size: usize = mb
232
6.68k
        .literal_split
233
6.68k
        .num_types
234
6.68k
        .wrapping_mul(literal_context_multiplier);
235
6.68k
    literal_histograms = allocate::<HistogramLiteral, _>(alloc, literal_histograms_size);
236
6.68k
    let distance_histograms_size: usize = mb.distance_split.num_types << 2;
237
6.68k
    distance_histograms = allocate::<HistogramDistance, _>(alloc, distance_histograms_size);
238
6.68k
    mb.command_histograms_size = mb.command_split.num_types;
239
6.68k
    mb.command_histograms = allocate::<HistogramCommand, _>(alloc, mb.command_histograms_size);
240
6.68k
    BrotliBuildHistogramsWithContext(
241
6.68k
        cmds,
242
6.68k
        num_commands,
243
6.68k
        &mut mb.literal_split,
244
6.68k
        &mut mb.command_split,
245
6.68k
        &mut mb.distance_split,
246
6.68k
        ringbuffer,
247
6.68k
        pos,
248
6.68k
        mask,
249
6.68k
        prev_byte,
250
6.68k
        prev_byte2,
251
6.68k
        literal_context_modes.slice(),
252
6.68k
        literal_histograms.slice_mut(),
253
6.68k
        mb.command_histograms.slice_mut(),
254
6.68k
        distance_histograms.slice_mut(),
255
6.68k
    );
256
6.68k
    <Alloc as Allocator<ContextType>>::free_cell(alloc, literal_context_modes);
257
6.68k
    mb.literal_context_map_size = mb.literal_split.num_types << 6;
258
6.68k
    mb.literal_context_map = allocate::<u32, _>(alloc, mb.literal_context_map_size);
259
6.68k
    mb.literal_histograms_size = mb.literal_context_map_size;
260
6.68k
    mb.literal_histograms = allocate::<HistogramLiteral, _>(alloc, mb.literal_histograms_size);
261
6.68k
    BrotliClusterHistograms(
262
6.68k
        alloc,
263
6.68k
        literal_histograms.slice(),
264
6.68k
        literal_histograms_size,
265
6.68k
        kMaxNumberOfHistograms,
266
6.68k
        lit_scratch_space,
267
6.68k
        mb.literal_histograms.slice_mut(),
268
6.68k
        &mut mb.literal_histograms_size,
269
6.68k
        mb.literal_context_map.slice_mut(),
270
6.68k
    );
271
6.68k
    <Alloc as Allocator<HistogramLiteral>>::free_cell(alloc, literal_histograms);
272
6.68k
    if params.disable_literal_context_modeling != 0 {
273
0
        i = mb.literal_split.num_types;
274
0
        while i != 0usize {
275
0
            let mut j: usize = 0usize;
276
0
            i = i.wrapping_sub(1);
277
0
            while j < (1i32 << 6) as usize {
278
0
                {
279
0
                    let val = mb.literal_context_map.slice()[i];
280
0
                    mb.literal_context_map.slice_mut()[(i << 6).wrapping_add(j)] = val;
281
0
                }
282
0
                j = j.wrapping_add(1);
283
0
            }
284
        }
285
6.68k
    }
286
6.68k
    mb.distance_context_map_size = mb.distance_split.num_types << 2;
287
6.68k
    mb.distance_context_map = allocate::<u32, _>(alloc, mb.distance_context_map_size);
288
6.68k
    mb.distance_histograms_size = mb.distance_context_map_size;
289
6.68k
    mb.distance_histograms = allocate::<HistogramDistance, _>(alloc, mb.distance_histograms_size);
290
6.68k
    BrotliClusterHistograms(
291
6.68k
        alloc,
292
6.68k
        distance_histograms.slice(),
293
6.68k
        mb.distance_context_map_size,
294
6.68k
        kMaxNumberOfHistograms,
295
6.68k
        dst_scratch_space,
296
6.68k
        mb.distance_histograms.slice_mut(),
297
6.68k
        &mut mb.distance_histograms_size,
298
6.68k
        mb.distance_context_map.slice_mut(),
299
6.68k
    );
300
6.68k
    <Alloc as Allocator<HistogramDistance>>::free_cell(alloc, distance_histograms);
301
6.68k
}
brotli::enc::metablock::BrotliBuildMetaBlock::<alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
133
6.68k
pub fn BrotliBuildMetaBlock<Alloc: BrotliAlloc>(
134
6.68k
    alloc: &mut Alloc,
135
6.68k
    ringbuffer: &[u8],
136
6.68k
    pos: usize,
137
6.68k
    mask: usize,
138
6.68k
    params: &mut BrotliEncoderParams,
139
6.68k
    prev_byte: u8,
140
6.68k
    prev_byte2: u8,
141
6.68k
    cmds: &mut [Command],
142
6.68k
    num_commands: usize,
143
6.68k
    literal_context_mode: ContextType,
144
6.68k
    lit_scratch_space: &mut <HistogramLiteral as CostAccessors>::i32vec,
145
6.68k
    cmd_scratch_space: &mut <HistogramCommand as CostAccessors>::i32vec,
146
6.68k
    dst_scratch_space: &mut <HistogramDistance as CostAccessors>::i32vec,
147
6.68k
    mb: &mut MetaBlockSplit<Alloc>,
148
6.68k
) {
149
    static kMaxNumberOfHistograms: usize = 256usize;
150
    let mut distance_histograms: <Alloc as Allocator<HistogramDistance>>::AllocatedMemory;
151
    let mut literal_histograms: <Alloc as Allocator<HistogramLiteral>>::AllocatedMemory;
152
6.68k
    let mut literal_context_modes = alloc_default::<ContextType, Alloc>();
153
6.68k
154
6.68k
    let mut i: usize;
155
6.68k
    let mut literal_context_multiplier: usize = 1;
156
6.68k
    let mut ndirect_msb: u32 = 0;
157
6.68k
    let mut check_orig = true;
158
6.68k
    if !params.avoid_distance_prefix_search {
159
6.68k
        let mut best_dist_cost: f64 = 1e99;
160
6.68k
        let orig_params = params.clone();
161
6.68k
        let mut new_params = params.clone();
162
163
26.7k
        for npostfix in 0..(BROTLI_MAX_NPOSTFIX + 1) {
164
171k
            while ndirect_msb < 16 {
165
159k
                let ndirect = ndirect_msb << npostfix;
166
159k
167
159k
                let mut dist_cost: f64 = 0.0;
168
159k
                BrotliInitDistanceParams(&mut new_params, npostfix as u32, ndirect);
169
159k
                if npostfix as u32 == orig_params.dist.distance_postfix_bits
170
64.4k
                    && ndirect == orig_params.dist.num_direct_distance_codes
171
6.68k
                {
172
6.68k
                    check_orig = false;
173
153k
                }
174
159k
                let skip: bool = !ComputeDistanceCost(
175
159k
                    cmds,
176
159k
                    num_commands,
177
159k
                    &orig_params.dist,
178
159k
                    &new_params.dist,
179
159k
                    dst_scratch_space,
180
159k
                    &mut dist_cost,
181
159k
                );
182
159k
                if skip || (dist_cost > best_dist_cost) {
183
14.7k
                    break;
184
145k
                }
185
145k
                best_dist_cost = dist_cost;
186
145k
                params.dist = new_params.dist;
187
145k
                ndirect_msb += 1;
188
            }
189
26.7k
            ndirect_msb = ndirect_msb.saturating_sub(1);
190
26.7k
            ndirect_msb /= 2;
191
        }
192
6.68k
        if check_orig {
193
0
            let mut dist_cost: f64 = 0.0;
194
0
            ComputeDistanceCost(
195
0
                cmds,
196
0
                num_commands,
197
0
                &orig_params.dist,
198
0
                &orig_params.dist,
199
0
                dst_scratch_space,
200
0
                &mut dist_cost,
201
0
            );
202
0
            if dist_cost < best_dist_cost {
203
0
                // best_dist_cost = dist_cost; unused
204
0
                params.dist = orig_params.dist;
205
0
            }
206
6.68k
        }
207
6.68k
        RecomputeDistancePrefixes(cmds, num_commands, &orig_params.dist, &params.dist);
208
0
    }
209
6.68k
    BrotliSplitBlock(
210
6.68k
        alloc,
211
6.68k
        cmds,
212
6.68k
        num_commands,
213
6.68k
        ringbuffer,
214
6.68k
        pos,
215
6.68k
        mask,
216
6.68k
        params,
217
6.68k
        lit_scratch_space,
218
6.68k
        cmd_scratch_space,
219
6.68k
        dst_scratch_space,
220
6.68k
        &mut mb.literal_split,
221
6.68k
        &mut mb.command_split,
222
6.68k
        &mut mb.distance_split,
223
6.68k
    );
224
6.68k
    if params.disable_literal_context_modeling == 0 {
225
6.68k
        literal_context_multiplier = (1i32 << 6) as usize;
226
6.68k
        literal_context_modes = allocate::<ContextType, _>(alloc, mb.literal_split.num_types);
227
18.4k
        for item in literal_context_modes.slice_mut().iter_mut() {
228
18.4k
            *item = literal_context_mode;
229
18.4k
        }
230
0
    }
231
6.68k
    let literal_histograms_size: usize = mb
232
6.68k
        .literal_split
233
6.68k
        .num_types
234
6.68k
        .wrapping_mul(literal_context_multiplier);
235
6.68k
    literal_histograms = allocate::<HistogramLiteral, _>(alloc, literal_histograms_size);
236
6.68k
    let distance_histograms_size: usize = mb.distance_split.num_types << 2;
237
6.68k
    distance_histograms = allocate::<HistogramDistance, _>(alloc, distance_histograms_size);
238
6.68k
    mb.command_histograms_size = mb.command_split.num_types;
239
6.68k
    mb.command_histograms = allocate::<HistogramCommand, _>(alloc, mb.command_histograms_size);
240
6.68k
    BrotliBuildHistogramsWithContext(
241
6.68k
        cmds,
242
6.68k
        num_commands,
243
6.68k
        &mut mb.literal_split,
244
6.68k
        &mut mb.command_split,
245
6.68k
        &mut mb.distance_split,
246
6.68k
        ringbuffer,
247
6.68k
        pos,
248
6.68k
        mask,
249
6.68k
        prev_byte,
250
6.68k
        prev_byte2,
251
6.68k
        literal_context_modes.slice(),
252
6.68k
        literal_histograms.slice_mut(),
253
6.68k
        mb.command_histograms.slice_mut(),
254
6.68k
        distance_histograms.slice_mut(),
255
6.68k
    );
256
6.68k
    <Alloc as Allocator<ContextType>>::free_cell(alloc, literal_context_modes);
257
6.68k
    mb.literal_context_map_size = mb.literal_split.num_types << 6;
258
6.68k
    mb.literal_context_map = allocate::<u32, _>(alloc, mb.literal_context_map_size);
259
6.68k
    mb.literal_histograms_size = mb.literal_context_map_size;
260
6.68k
    mb.literal_histograms = allocate::<HistogramLiteral, _>(alloc, mb.literal_histograms_size);
261
6.68k
    BrotliClusterHistograms(
262
6.68k
        alloc,
263
6.68k
        literal_histograms.slice(),
264
6.68k
        literal_histograms_size,
265
6.68k
        kMaxNumberOfHistograms,
266
6.68k
        lit_scratch_space,
267
6.68k
        mb.literal_histograms.slice_mut(),
268
6.68k
        &mut mb.literal_histograms_size,
269
6.68k
        mb.literal_context_map.slice_mut(),
270
6.68k
    );
271
6.68k
    <Alloc as Allocator<HistogramLiteral>>::free_cell(alloc, literal_histograms);
272
6.68k
    if params.disable_literal_context_modeling != 0 {
273
0
        i = mb.literal_split.num_types;
274
0
        while i != 0usize {
275
0
            let mut j: usize = 0usize;
276
0
            i = i.wrapping_sub(1);
277
0
            while j < (1i32 << 6) as usize {
278
0
                {
279
0
                    let val = mb.literal_context_map.slice()[i];
280
0
                    mb.literal_context_map.slice_mut()[(i << 6).wrapping_add(j)] = val;
281
0
                }
282
0
                j = j.wrapping_add(1);
283
0
            }
284
        }
285
6.68k
    }
286
6.68k
    mb.distance_context_map_size = mb.distance_split.num_types << 2;
287
6.68k
    mb.distance_context_map = allocate::<u32, _>(alloc, mb.distance_context_map_size);
288
6.68k
    mb.distance_histograms_size = mb.distance_context_map_size;
289
6.68k
    mb.distance_histograms = allocate::<HistogramDistance, _>(alloc, mb.distance_histograms_size);
290
6.68k
    BrotliClusterHistograms(
291
6.68k
        alloc,
292
6.68k
        distance_histograms.slice(),
293
6.68k
        mb.distance_context_map_size,
294
6.68k
        kMaxNumberOfHistograms,
295
6.68k
        dst_scratch_space,
296
6.68k
        mb.distance_histograms.slice_mut(),
297
6.68k
        &mut mb.distance_histograms_size,
298
6.68k
        mb.distance_context_map.slice_mut(),
299
6.68k
    );
300
6.68k
    <Alloc as Allocator<HistogramDistance>>::free_cell(alloc, distance_histograms);
301
6.68k
}
Unexecuted instantiation: brotli::enc::metablock::BrotliBuildMetaBlock::<_>
302
303
/*
304
pub struct BlockSplitter<'a, HistogramType:SliceWrapper<u32>+SliceWrapperMut<u32> +CostAccessors,
305
                         AllocU8:alloc::Allocator<u8>+'a,
306
                         AllocU32:alloc::Allocator<u32>+'a,
307
                         AllocHT:alloc::Allocator<HistogramType>+'a > {
308
                         */
309
pub struct BlockSplitter {
310
    pub alphabet_size_: usize,
311
    pub min_block_size_: usize,
312
    pub split_threshold_: floatX,
313
    pub num_blocks_: usize,
314
    //  pub split_: &'a mut BlockSplit<AllocU8, AllocU32>,
315
    //  pub histograms_: AllocHT::AllocatedMemory, // FIXME: pull this one out at the end
316
    //  pub histograms_size_: &'a mut usize, // FIXME: pull this one out at the end
317
    pub target_block_size_: usize,
318
    pub block_size_: usize,
319
    pub curr_histogram_ix_: usize,
320
    pub last_histogram_ix_: [usize; 2],
321
    pub last_entropy_: [floatX; 2],
322
    pub merge_last_count_: usize,
323
}
324
325
pub struct ContextBlockSplitter {
326
    pub alphabet_size_: usize,
327
    pub num_contexts_: usize,
328
    pub max_block_types_: usize,
329
    pub min_block_size_: usize,
330
    pub split_threshold_: floatX,
331
    pub num_blocks_: usize,
332
    //  pub split_: &'a mut BlockSplit<AllocU8, AllocU32>,
333
    //  pub histograms_: AllocHL::AllocatedMemory,
334
    //  pub histograms_size_: &'a mut usize, // FIXME: pull this one out at the end
335
    pub target_block_size_: usize,
336
    pub block_size_: usize,
337
    pub curr_histogram_ix_: usize,
338
    pub last_histogram_ix_: [usize; 2],
339
    pub last_entropy_: [floatX; 2 * BROTLI_MAX_STATIC_CONTEXTS],
340
    pub merge_last_count_: usize,
341
}
342
343
enum LitBlocks {
344
    plain(BlockSplitter),      //<'a, HistogramLiteral, AllocU8, AllocU32, AllocHL>,
345
    ctx(ContextBlockSplitter), //<'a, AllocU8, AllocU32, AllocHL>,
346
}
347
348
/*
349
350
pub struct BlockSplitterCommand {
351
  pub alphabet_size_: usize,
352
  pub min_block_size_: usize,
353
  pub split_threshold_: floatX,
354
  pub num_blocks_: usize,
355
  pub split_: *mut BlockSplit,
356
  pub histograms_: *mut HistogramCommand,
357
  pub histograms_size_: *mut usize,
358
  pub target_block_size_: usize,
359
  pub block_size_: usize,
360
  pub curr_histogram_ix_: usize,
361
  pub last_histogram_ix_: [usize; 2],
362
  pub last_entropy_: [floatX; 2],
363
  pub merge_last_count_: usize,
364
}
365
366
367
368
pub struct BlockSplitterDistance {
369
  pub alphabet_size_: usize,
370
  pub min_block_size_: usize,
371
  pub split_threshold_: floatX,
372
  pub num_blocks_: usize,
373
  pub split_: *mut BlockSplit,
374
  pub histograms_: *mut HistogramDistance,
375
  pub histograms_size_: *mut usize,
376
  pub target_block_size_: usize,
377
  pub block_size_: usize,
378
  pub curr_histogram_ix_: usize,
379
  pub last_histogram_ix_: [usize; 2],
380
  pub last_entropy_: [floatX; 2],
381
  pub merge_last_count_: usize,
382
}
383
*/
384
385
13.7k
fn InitBlockSplitter<
386
13.7k
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors,
387
13.7k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32> + alloc::Allocator<HistogramType>,
388
13.7k
>(
389
13.7k
    alloc: &mut Alloc,
390
13.7k
    alphabet_size: usize,
391
13.7k
    min_block_size: usize,
392
13.7k
    split_threshold: floatX,
393
13.7k
    num_symbols: usize,
394
13.7k
    split: &mut BlockSplit<Alloc>,
395
13.7k
    histograms: &mut <Alloc as Allocator<HistogramType>>::AllocatedMemory,
396
13.7k
    histograms_size: &mut usize,
397
13.7k
) -> BlockSplitter {
398
13.7k
    let max_num_blocks: usize = num_symbols.wrapping_div(min_block_size).wrapping_add(1);
399
13.7k
    let max_num_types: usize = min(max_num_blocks, (256i32 + 1i32) as usize);
400
13.7k
    let mut xself = BlockSplitter {
401
13.7k
        last_entropy_: [0.0; 2],
402
13.7k
        alphabet_size_: alphabet_size,
403
13.7k
        min_block_size_: min_block_size,
404
13.7k
        split_threshold_: split_threshold,
405
13.7k
        num_blocks_: 0usize,
406
13.7k
        //xself.split_ : split,
407
13.7k
        //xself.histograms_size_ : histograms_size,
408
13.7k
        target_block_size_: min_block_size,
409
13.7k
        block_size_: 0usize,
410
13.7k
        curr_histogram_ix_: 0usize,
411
13.7k
        merge_last_count_: 0usize,
412
13.7k
        last_histogram_ix_: [0; 2],
413
13.7k
    };
414
13.7k
    {
415
13.7k
        if split.types.slice().len() < max_num_blocks {
416
13.7k
            let mut _new_size: usize = if split.types.slice().is_empty() {
417
13.7k
                max_num_blocks
418
            } else {
419
0
                split.types.slice().len()
420
            };
421
            let mut new_array: <Alloc as Allocator<u8>>::AllocatedMemory;
422
13.7k
            while _new_size < max_num_blocks {
423
0
                _new_size = _new_size.wrapping_mul(2);
424
0
            }
425
13.7k
            new_array = allocate::<u8, _>(alloc, _new_size);
426
13.7k
            if (!split.types.slice().is_empty()) {
427
0
                new_array.slice_mut()[..split.types.slice().len()]
428
0
                    .clone_from_slice(split.types.slice());
429
13.7k
            }
430
13.7k
            <Alloc as Allocator<u8>>::free_cell(
431
13.7k
                alloc,
432
13.7k
                core::mem::replace(&mut split.types, new_array),
433
13.7k
            );
434
0
        }
435
    }
436
    {
437
13.7k
        if split.lengths.slice().len() < max_num_blocks {
438
13.7k
            let mut _new_size: usize = if split.lengths.slice().is_empty() {
439
13.7k
                max_num_blocks
440
            } else {
441
0
                split.lengths.slice().len()
442
            };
443
13.7k
            while _new_size < max_num_blocks {
444
0
                _new_size = _new_size.wrapping_mul(2);
445
0
            }
446
13.7k
            let mut new_array = allocate::<u32, _>(alloc, _new_size);
447
13.7k
            new_array.slice_mut()[..split.lengths.slice().len()]
448
13.7k
                .clone_from_slice(split.lengths.slice());
449
13.7k
            <Alloc as Allocator<u32>>::free_cell(
450
13.7k
                alloc,
451
13.7k
                core::mem::replace(&mut split.lengths, new_array),
452
13.7k
            );
453
0
        }
454
    }
455
13.7k
    split.num_blocks = max_num_blocks;
456
13.7k
    *histograms_size = max_num_types;
457
13.7k
    let hlocal = allocate::<HistogramType, _>(alloc, *histograms_size);
458
13.7k
    <Alloc as Allocator<HistogramType>>::free_cell(
459
13.7k
        alloc,
460
13.7k
        core::mem::replace(&mut *histograms, hlocal),
461
13.7k
    );
462
13.7k
    HistogramClear(&mut histograms.slice_mut()[0]);
463
13.7k
    xself.last_histogram_ix_[0] = 0;
464
13.7k
    xself.last_histogram_ix_[1] = 0;
465
13.7k
    xself
466
13.7k
}
brotli::enc::metablock::InitBlockSplitter::<brotli::enc::histogram::HistogramCommand, alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
385
4.87k
fn InitBlockSplitter<
386
4.87k
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors,
387
4.87k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32> + alloc::Allocator<HistogramType>,
388
4.87k
>(
389
4.87k
    alloc: &mut Alloc,
390
4.87k
    alphabet_size: usize,
391
4.87k
    min_block_size: usize,
392
4.87k
    split_threshold: floatX,
393
4.87k
    num_symbols: usize,
394
4.87k
    split: &mut BlockSplit<Alloc>,
395
4.87k
    histograms: &mut <Alloc as Allocator<HistogramType>>::AllocatedMemory,
396
4.87k
    histograms_size: &mut usize,
397
4.87k
) -> BlockSplitter {
398
4.87k
    let max_num_blocks: usize = num_symbols.wrapping_div(min_block_size).wrapping_add(1);
399
4.87k
    let max_num_types: usize = min(max_num_blocks, (256i32 + 1i32) as usize);
400
4.87k
    let mut xself = BlockSplitter {
401
4.87k
        last_entropy_: [0.0; 2],
402
4.87k
        alphabet_size_: alphabet_size,
403
4.87k
        min_block_size_: min_block_size,
404
4.87k
        split_threshold_: split_threshold,
405
4.87k
        num_blocks_: 0usize,
406
4.87k
        //xself.split_ : split,
407
4.87k
        //xself.histograms_size_ : histograms_size,
408
4.87k
        target_block_size_: min_block_size,
409
4.87k
        block_size_: 0usize,
410
4.87k
        curr_histogram_ix_: 0usize,
411
4.87k
        merge_last_count_: 0usize,
412
4.87k
        last_histogram_ix_: [0; 2],
413
4.87k
    };
414
4.87k
    {
415
4.87k
        if split.types.slice().len() < max_num_blocks {
416
4.87k
            let mut _new_size: usize = if split.types.slice().is_empty() {
417
4.87k
                max_num_blocks
418
            } else {
419
0
                split.types.slice().len()
420
            };
421
            let mut new_array: <Alloc as Allocator<u8>>::AllocatedMemory;
422
4.87k
            while _new_size < max_num_blocks {
423
0
                _new_size = _new_size.wrapping_mul(2);
424
0
            }
425
4.87k
            new_array = allocate::<u8, _>(alloc, _new_size);
426
4.87k
            if (!split.types.slice().is_empty()) {
427
0
                new_array.slice_mut()[..split.types.slice().len()]
428
0
                    .clone_from_slice(split.types.slice());
429
4.87k
            }
430
4.87k
            <Alloc as Allocator<u8>>::free_cell(
431
4.87k
                alloc,
432
4.87k
                core::mem::replace(&mut split.types, new_array),
433
4.87k
            );
434
0
        }
435
    }
436
    {
437
4.87k
        if split.lengths.slice().len() < max_num_blocks {
438
4.87k
            let mut _new_size: usize = if split.lengths.slice().is_empty() {
439
4.87k
                max_num_blocks
440
            } else {
441
0
                split.lengths.slice().len()
442
            };
443
4.87k
            while _new_size < max_num_blocks {
444
0
                _new_size = _new_size.wrapping_mul(2);
445
0
            }
446
4.87k
            let mut new_array = allocate::<u32, _>(alloc, _new_size);
447
4.87k
            new_array.slice_mut()[..split.lengths.slice().len()]
448
4.87k
                .clone_from_slice(split.lengths.slice());
449
4.87k
            <Alloc as Allocator<u32>>::free_cell(
450
4.87k
                alloc,
451
4.87k
                core::mem::replace(&mut split.lengths, new_array),
452
4.87k
            );
453
0
        }
454
    }
455
4.87k
    split.num_blocks = max_num_blocks;
456
4.87k
    *histograms_size = max_num_types;
457
4.87k
    let hlocal = allocate::<HistogramType, _>(alloc, *histograms_size);
458
4.87k
    <Alloc as Allocator<HistogramType>>::free_cell(
459
4.87k
        alloc,
460
4.87k
        core::mem::replace(&mut *histograms, hlocal),
461
4.87k
    );
462
4.87k
    HistogramClear(&mut histograms.slice_mut()[0]);
463
4.87k
    xself.last_histogram_ix_[0] = 0;
464
4.87k
    xself.last_histogram_ix_[1] = 0;
465
4.87k
    xself
466
4.87k
}
brotli::enc::metablock::InitBlockSplitter::<brotli::enc::histogram::HistogramLiteral, alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
385
3.97k
fn InitBlockSplitter<
386
3.97k
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors,
387
3.97k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32> + alloc::Allocator<HistogramType>,
388
3.97k
>(
389
3.97k
    alloc: &mut Alloc,
390
3.97k
    alphabet_size: usize,
391
3.97k
    min_block_size: usize,
392
3.97k
    split_threshold: floatX,
393
3.97k
    num_symbols: usize,
394
3.97k
    split: &mut BlockSplit<Alloc>,
395
3.97k
    histograms: &mut <Alloc as Allocator<HistogramType>>::AllocatedMemory,
396
3.97k
    histograms_size: &mut usize,
397
3.97k
) -> BlockSplitter {
398
3.97k
    let max_num_blocks: usize = num_symbols.wrapping_div(min_block_size).wrapping_add(1);
399
3.97k
    let max_num_types: usize = min(max_num_blocks, (256i32 + 1i32) as usize);
400
3.97k
    let mut xself = BlockSplitter {
401
3.97k
        last_entropy_: [0.0; 2],
402
3.97k
        alphabet_size_: alphabet_size,
403
3.97k
        min_block_size_: min_block_size,
404
3.97k
        split_threshold_: split_threshold,
405
3.97k
        num_blocks_: 0usize,
406
3.97k
        //xself.split_ : split,
407
3.97k
        //xself.histograms_size_ : histograms_size,
408
3.97k
        target_block_size_: min_block_size,
409
3.97k
        block_size_: 0usize,
410
3.97k
        curr_histogram_ix_: 0usize,
411
3.97k
        merge_last_count_: 0usize,
412
3.97k
        last_histogram_ix_: [0; 2],
413
3.97k
    };
414
3.97k
    {
415
3.97k
        if split.types.slice().len() < max_num_blocks {
416
3.97k
            let mut _new_size: usize = if split.types.slice().is_empty() {
417
3.97k
                max_num_blocks
418
            } else {
419
0
                split.types.slice().len()
420
            };
421
            let mut new_array: <Alloc as Allocator<u8>>::AllocatedMemory;
422
3.97k
            while _new_size < max_num_blocks {
423
0
                _new_size = _new_size.wrapping_mul(2);
424
0
            }
425
3.97k
            new_array = allocate::<u8, _>(alloc, _new_size);
426
3.97k
            if (!split.types.slice().is_empty()) {
427
0
                new_array.slice_mut()[..split.types.slice().len()]
428
0
                    .clone_from_slice(split.types.slice());
429
3.97k
            }
430
3.97k
            <Alloc as Allocator<u8>>::free_cell(
431
3.97k
                alloc,
432
3.97k
                core::mem::replace(&mut split.types, new_array),
433
3.97k
            );
434
0
        }
435
    }
436
    {
437
3.97k
        if split.lengths.slice().len() < max_num_blocks {
438
3.97k
            let mut _new_size: usize = if split.lengths.slice().is_empty() {
439
3.97k
                max_num_blocks
440
            } else {
441
0
                split.lengths.slice().len()
442
            };
443
3.97k
            while _new_size < max_num_blocks {
444
0
                _new_size = _new_size.wrapping_mul(2);
445
0
            }
446
3.97k
            let mut new_array = allocate::<u32, _>(alloc, _new_size);
447
3.97k
            new_array.slice_mut()[..split.lengths.slice().len()]
448
3.97k
                .clone_from_slice(split.lengths.slice());
449
3.97k
            <Alloc as Allocator<u32>>::free_cell(
450
3.97k
                alloc,
451
3.97k
                core::mem::replace(&mut split.lengths, new_array),
452
3.97k
            );
453
0
        }
454
    }
455
3.97k
    split.num_blocks = max_num_blocks;
456
3.97k
    *histograms_size = max_num_types;
457
3.97k
    let hlocal = allocate::<HistogramType, _>(alloc, *histograms_size);
458
3.97k
    <Alloc as Allocator<HistogramType>>::free_cell(
459
3.97k
        alloc,
460
3.97k
        core::mem::replace(&mut *histograms, hlocal),
461
3.97k
    );
462
3.97k
    HistogramClear(&mut histograms.slice_mut()[0]);
463
3.97k
    xself.last_histogram_ix_[0] = 0;
464
3.97k
    xself.last_histogram_ix_[1] = 0;
465
3.97k
    xself
466
3.97k
}
brotli::enc::metablock::InitBlockSplitter::<brotli::enc::histogram::HistogramDistance, alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
385
4.87k
fn InitBlockSplitter<
386
4.87k
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors,
387
4.87k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32> + alloc::Allocator<HistogramType>,
388
4.87k
>(
389
4.87k
    alloc: &mut Alloc,
390
4.87k
    alphabet_size: usize,
391
4.87k
    min_block_size: usize,
392
4.87k
    split_threshold: floatX,
393
4.87k
    num_symbols: usize,
394
4.87k
    split: &mut BlockSplit<Alloc>,
395
4.87k
    histograms: &mut <Alloc as Allocator<HistogramType>>::AllocatedMemory,
396
4.87k
    histograms_size: &mut usize,
397
4.87k
) -> BlockSplitter {
398
4.87k
    let max_num_blocks: usize = num_symbols.wrapping_div(min_block_size).wrapping_add(1);
399
4.87k
    let max_num_types: usize = min(max_num_blocks, (256i32 + 1i32) as usize);
400
4.87k
    let mut xself = BlockSplitter {
401
4.87k
        last_entropy_: [0.0; 2],
402
4.87k
        alphabet_size_: alphabet_size,
403
4.87k
        min_block_size_: min_block_size,
404
4.87k
        split_threshold_: split_threshold,
405
4.87k
        num_blocks_: 0usize,
406
4.87k
        //xself.split_ : split,
407
4.87k
        //xself.histograms_size_ : histograms_size,
408
4.87k
        target_block_size_: min_block_size,
409
4.87k
        block_size_: 0usize,
410
4.87k
        curr_histogram_ix_: 0usize,
411
4.87k
        merge_last_count_: 0usize,
412
4.87k
        last_histogram_ix_: [0; 2],
413
4.87k
    };
414
4.87k
    {
415
4.87k
        if split.types.slice().len() < max_num_blocks {
416
4.87k
            let mut _new_size: usize = if split.types.slice().is_empty() {
417
4.87k
                max_num_blocks
418
            } else {
419
0
                split.types.slice().len()
420
            };
421
            let mut new_array: <Alloc as Allocator<u8>>::AllocatedMemory;
422
4.87k
            while _new_size < max_num_blocks {
423
0
                _new_size = _new_size.wrapping_mul(2);
424
0
            }
425
4.87k
            new_array = allocate::<u8, _>(alloc, _new_size);
426
4.87k
            if (!split.types.slice().is_empty()) {
427
0
                new_array.slice_mut()[..split.types.slice().len()]
428
0
                    .clone_from_slice(split.types.slice());
429
4.87k
            }
430
4.87k
            <Alloc as Allocator<u8>>::free_cell(
431
4.87k
                alloc,
432
4.87k
                core::mem::replace(&mut split.types, new_array),
433
4.87k
            );
434
0
        }
435
    }
436
    {
437
4.87k
        if split.lengths.slice().len() < max_num_blocks {
438
4.87k
            let mut _new_size: usize = if split.lengths.slice().is_empty() {
439
4.87k
                max_num_blocks
440
            } else {
441
0
                split.lengths.slice().len()
442
            };
443
4.87k
            while _new_size < max_num_blocks {
444
0
                _new_size = _new_size.wrapping_mul(2);
445
0
            }
446
4.87k
            let mut new_array = allocate::<u32, _>(alloc, _new_size);
447
4.87k
            new_array.slice_mut()[..split.lengths.slice().len()]
448
4.87k
                .clone_from_slice(split.lengths.slice());
449
4.87k
            <Alloc as Allocator<u32>>::free_cell(
450
4.87k
                alloc,
451
4.87k
                core::mem::replace(&mut split.lengths, new_array),
452
4.87k
            );
453
0
        }
454
    }
455
4.87k
    split.num_blocks = max_num_blocks;
456
4.87k
    *histograms_size = max_num_types;
457
4.87k
    let hlocal = allocate::<HistogramType, _>(alloc, *histograms_size);
458
4.87k
    <Alloc as Allocator<HistogramType>>::free_cell(
459
4.87k
        alloc,
460
4.87k
        core::mem::replace(&mut *histograms, hlocal),
461
4.87k
    );
462
4.87k
    HistogramClear(&mut histograms.slice_mut()[0]);
463
4.87k
    xself.last_histogram_ix_[0] = 0;
464
4.87k
    xself.last_histogram_ix_[1] = 0;
465
4.87k
    xself
466
4.87k
}
Unexecuted instantiation: brotli::enc::metablock::InitBlockSplitter::<_, _>
467
898
fn InitContextBlockSplitter<
468
898
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32> + alloc::Allocator<HistogramLiteral>,
469
898
>(
470
898
    alloc: &mut Alloc,
471
898
    alphabet_size: usize,
472
898
    num_contexts: usize,
473
898
    min_block_size: usize,
474
898
    split_threshold: floatX,
475
898
    num_symbols: usize,
476
898
    split: &mut BlockSplit<Alloc>,
477
898
    histograms: &mut <Alloc as Allocator<HistogramLiteral>>::AllocatedMemory,
478
898
    histograms_size: &mut usize,
479
898
) -> ContextBlockSplitter {
480
898
    let max_num_blocks: usize = num_symbols.wrapping_div(min_block_size).wrapping_add(1);
481
898
482
898
    assert!(num_contexts <= BROTLI_MAX_STATIC_CONTEXTS);
483
898
    let mut xself = ContextBlockSplitter {
484
898
        alphabet_size_: alphabet_size,
485
898
        num_contexts_: num_contexts,
486
898
        max_block_types_: (256usize).wrapping_div(num_contexts),
487
898
        min_block_size_: min_block_size,
488
898
        split_threshold_: split_threshold,
489
898
        num_blocks_: 0usize,
490
898
        //        histograms_size_: histograms_size,
491
898
        target_block_size_: min_block_size,
492
898
        block_size_: 0usize,
493
898
        curr_histogram_ix_: 0usize,
494
898
        merge_last_count_: 0usize,
495
898
        last_histogram_ix_: [0; 2],
496
898
        last_entropy_: [0.0; 2 * BROTLI_MAX_STATIC_CONTEXTS],
497
898
    };
498
898
    let max_num_types: usize = min(max_num_blocks, xself.max_block_types_.wrapping_add(1));
499
898
    {
500
898
        if split.types.slice().len() < max_num_blocks {
501
898
            let mut _new_size: usize = if split.types.slice().is_empty() {
502
898
                max_num_blocks
503
            } else {
504
0
                split.types.slice().len()
505
            };
506
898
            while _new_size < max_num_blocks {
507
0
                _new_size = _new_size.wrapping_mul(2);
508
0
            }
509
898
            let mut new_array = allocate::<u8, _>(alloc, _new_size);
510
898
            if (!split.types.slice().is_empty()) {
511
0
                new_array.slice_mut()[..split.types.slice().len()]
512
0
                    .clone_from_slice(split.types.slice());
513
898
            }
514
898
            <Alloc as Allocator<u8>>::free_cell(
515
898
                alloc,
516
898
                core::mem::replace(&mut split.types, new_array),
517
898
            );
518
0
        }
519
    }
520
    {
521
898
        if split.lengths.slice().len() < max_num_blocks {
522
898
            let mut _new_size: usize = if split.lengths.slice().is_empty() {
523
898
                max_num_blocks
524
            } else {
525
0
                split.lengths.slice().len()
526
            };
527
898
            while _new_size < max_num_blocks {
528
0
                _new_size = _new_size.wrapping_mul(2);
529
0
            }
530
898
            let mut new_array = allocate::<u32, _>(alloc, _new_size);
531
898
            if (!split.lengths.slice().is_empty()) {
532
0
                new_array.slice_mut()[..split.lengths.slice().len()]
533
0
                    .clone_from_slice(split.lengths.slice());
534
898
            }
535
898
            <Alloc as Allocator<u32>>::free_cell(
536
898
                alloc,
537
898
                core::mem::replace(&mut split.lengths, new_array),
538
898
            );
539
0
        }
540
    }
541
898
    split.num_blocks = max_num_blocks;
542
898
    *histograms_size = max_num_types.wrapping_mul(num_contexts);
543
898
    *histograms = allocate::<HistogramLiteral, _>(alloc, *histograms_size);
544
898
    //xself.histograms_ = *histograms;
545
898
    ClearHistograms(&mut histograms.slice_mut()[0..], num_contexts);
546
898
    xself.last_histogram_ix_[0] = 0;
547
898
    xself.last_histogram_ix_[1] = 0;
548
898
    xself
549
898
}
brotli::enc::metablock::InitContextBlockSplitter::<alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
467
898
fn InitContextBlockSplitter<
468
898
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32> + alloc::Allocator<HistogramLiteral>,
469
898
>(
470
898
    alloc: &mut Alloc,
471
898
    alphabet_size: usize,
472
898
    num_contexts: usize,
473
898
    min_block_size: usize,
474
898
    split_threshold: floatX,
475
898
    num_symbols: usize,
476
898
    split: &mut BlockSplit<Alloc>,
477
898
    histograms: &mut <Alloc as Allocator<HistogramLiteral>>::AllocatedMemory,
478
898
    histograms_size: &mut usize,
479
898
) -> ContextBlockSplitter {
480
898
    let max_num_blocks: usize = num_symbols.wrapping_div(min_block_size).wrapping_add(1);
481
898
482
898
    assert!(num_contexts <= BROTLI_MAX_STATIC_CONTEXTS);
483
898
    let mut xself = ContextBlockSplitter {
484
898
        alphabet_size_: alphabet_size,
485
898
        num_contexts_: num_contexts,
486
898
        max_block_types_: (256usize).wrapping_div(num_contexts),
487
898
        min_block_size_: min_block_size,
488
898
        split_threshold_: split_threshold,
489
898
        num_blocks_: 0usize,
490
898
        //        histograms_size_: histograms_size,
491
898
        target_block_size_: min_block_size,
492
898
        block_size_: 0usize,
493
898
        curr_histogram_ix_: 0usize,
494
898
        merge_last_count_: 0usize,
495
898
        last_histogram_ix_: [0; 2],
496
898
        last_entropy_: [0.0; 2 * BROTLI_MAX_STATIC_CONTEXTS],
497
898
    };
498
898
    let max_num_types: usize = min(max_num_blocks, xself.max_block_types_.wrapping_add(1));
499
898
    {
500
898
        if split.types.slice().len() < max_num_blocks {
501
898
            let mut _new_size: usize = if split.types.slice().is_empty() {
502
898
                max_num_blocks
503
            } else {
504
0
                split.types.slice().len()
505
            };
506
898
            while _new_size < max_num_blocks {
507
0
                _new_size = _new_size.wrapping_mul(2);
508
0
            }
509
898
            let mut new_array = allocate::<u8, _>(alloc, _new_size);
510
898
            if (!split.types.slice().is_empty()) {
511
0
                new_array.slice_mut()[..split.types.slice().len()]
512
0
                    .clone_from_slice(split.types.slice());
513
898
            }
514
898
            <Alloc as Allocator<u8>>::free_cell(
515
898
                alloc,
516
898
                core::mem::replace(&mut split.types, new_array),
517
898
            );
518
0
        }
519
    }
520
    {
521
898
        if split.lengths.slice().len() < max_num_blocks {
522
898
            let mut _new_size: usize = if split.lengths.slice().is_empty() {
523
898
                max_num_blocks
524
            } else {
525
0
                split.lengths.slice().len()
526
            };
527
898
            while _new_size < max_num_blocks {
528
0
                _new_size = _new_size.wrapping_mul(2);
529
0
            }
530
898
            let mut new_array = allocate::<u32, _>(alloc, _new_size);
531
898
            if (!split.lengths.slice().is_empty()) {
532
0
                new_array.slice_mut()[..split.lengths.slice().len()]
533
0
                    .clone_from_slice(split.lengths.slice());
534
898
            }
535
898
            <Alloc as Allocator<u32>>::free_cell(
536
898
                alloc,
537
898
                core::mem::replace(&mut split.lengths, new_array),
538
898
            );
539
0
        }
540
    }
541
898
    split.num_blocks = max_num_blocks;
542
898
    *histograms_size = max_num_types.wrapping_mul(num_contexts);
543
898
    *histograms = allocate::<HistogramLiteral, _>(alloc, *histograms_size);
544
898
    //xself.histograms_ = *histograms;
545
898
    ClearHistograms(&mut histograms.slice_mut()[0..], num_contexts);
546
898
    xself.last_histogram_ix_[0] = 0;
547
898
    xself.last_histogram_ix_[1] = 0;
548
898
    xself
549
898
}
Unexecuted instantiation: brotli::enc::metablock::InitContextBlockSplitter::<_>
550
551
25.0k
fn BlockSplitterFinishBlock<
552
25.0k
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors + Clone,
553
25.0k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>,
554
25.0k
>(
555
25.0k
    xself: &mut BlockSplitter,
556
25.0k
    split: &mut BlockSplit<Alloc>,
557
25.0k
    histograms: &mut [HistogramType],
558
25.0k
    histograms_size: &mut usize,
559
25.0k
    is_final: bool,
560
25.0k
) {
561
25.0k
    xself.block_size_ = max(xself.block_size_, xself.min_block_size_);
562
25.0k
    if xself.num_blocks_ == 0usize {
563
13.7k
        split.lengths.slice_mut()[0] = xself.block_size_ as u32;
564
13.7k
        split.types.slice_mut()[0] = 0u8;
565
13.7k
        xself.last_entropy_[0] = BitsEntropy((histograms[0]).slice(), xself.alphabet_size_);
566
13.7k
        xself.last_entropy_[1] = xself.last_entropy_[0];
567
13.7k
        xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
568
13.7k
        split.num_types = split.num_types.wrapping_add(1);
569
13.7k
        xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(1);
570
13.7k
        if xself.curr_histogram_ix_ < *histograms_size {
571
1.31k
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
572
12.4k
        }
573
13.7k
        xself.block_size_ = 0usize;
574
11.3k
    } else if xself.block_size_ > 0usize {
575
11.3k
        let entropy = BitsEntropy(
576
11.3k
            (histograms[xself.curr_histogram_ix_]).slice(),
577
11.3k
            xself.alphabet_size_,
578
11.3k
        );
579
11.3k
        let mut combined_histo: [HistogramType; 2] = [
580
11.3k
            histograms[xself.curr_histogram_ix_].clone(),
581
11.3k
            histograms[xself.curr_histogram_ix_].clone(),
582
11.3k
        ];
583
11.3k
584
11.3k
        let mut combined_entropy: [floatX; 2] = [0.0, 0.0];
585
11.3k
        let mut diff: [floatX; 2] = [0.0, 0.0];
586
33.9k
        for j in 0..2 {
587
22.6k
            let last_histogram_ix: usize = xself.last_histogram_ix_[j];
588
22.6k
            HistogramAddHistogram(&mut combined_histo[j], &histograms[last_histogram_ix]);
589
22.6k
            combined_entropy[j] = BitsEntropy(
590
22.6k
                &mut combined_histo[j].slice_mut()[0..],
591
22.6k
                xself.alphabet_size_,
592
22.6k
            );
593
22.6k
            diff[j] = combined_entropy[j] - entropy - xself.last_entropy_[j];
594
22.6k
        }
595
11.3k
        if split.num_types < 256usize
596
11.3k
            && (diff[0] > xself.split_threshold_)
597
2.74k
            && (diff[1] > xself.split_threshold_)
598
        {
599
2.05k
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
600
2.05k
            split.types.slice_mut()[xself.num_blocks_] = split.num_types as u8;
601
2.05k
            xself.last_histogram_ix_[1] = xself.last_histogram_ix_[0];
602
2.05k
            xself.last_histogram_ix_[0] = split.num_types as u8 as usize;
603
2.05k
            xself.last_entropy_[1] = xself.last_entropy_[0];
604
2.05k
            xself.last_entropy_[0] = entropy;
605
2.05k
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
606
2.05k
            split.num_types = split.num_types.wrapping_add(1);
607
2.05k
            xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(1);
608
2.05k
            if xself.curr_histogram_ix_ < *histograms_size {
609
2.02k
                HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
610
2.02k
            }
611
2.05k
            xself.block_size_ = 0usize;
612
2.05k
            xself.merge_last_count_ = 0usize;
613
2.05k
            xself.target_block_size_ = xself.min_block_size_;
614
9.27k
        } else if diff[1] < diff[0] - 20.0 {
615
1.30k
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
616
1.30k
            split.types.slice_mut()[xself.num_blocks_] =
617
1.30k
                split.types.slice()[xself.num_blocks_.wrapping_sub(2)]; //FIXME: investigate copy?
618
1.30k
            {
619
1.30k
                xself.last_histogram_ix_.swap(0, 1);
620
1.30k
            }
621
1.30k
            histograms[xself.last_histogram_ix_[0]] = combined_histo[1].clone();
622
1.30k
            xself.last_entropy_[1] = xself.last_entropy_[0];
623
1.30k
            xself.last_entropy_[0] = combined_entropy[1];
624
1.30k
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
625
1.30k
            xself.block_size_ = 0usize;
626
1.30k
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
627
1.30k
            xself.merge_last_count_ = 0usize;
628
1.30k
            xself.target_block_size_ = xself.min_block_size_;
629
1.30k
        } else {
630
7.97k
            {
631
7.97k
                let _rhs = xself.block_size_ as u32;
632
7.97k
                let _lhs = &mut split.lengths.slice_mut()[xself.num_blocks_.wrapping_sub(1)];
633
7.97k
                *_lhs = (*_lhs).wrapping_add(_rhs);
634
7.97k
            }
635
7.97k
            histograms[xself.last_histogram_ix_[0]] = combined_histo[0].clone();
636
7.97k
            xself.last_entropy_[0] = combined_entropy[0];
637
7.97k
            if split.num_types == 1 {
638
4.11k
                xself.last_entropy_[1] = xself.last_entropy_[0];
639
4.11k
            }
640
7.97k
            xself.block_size_ = 0usize;
641
7.97k
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
642
7.97k
            if {
643
7.97k
                xself.merge_last_count_ = xself.merge_last_count_.wrapping_add(1);
644
7.97k
                xself.merge_last_count_
645
7.97k
            } > 1
646
5.11k
            {
647
5.11k
                xself.target_block_size_ =
648
5.11k
                    xself.target_block_size_.wrapping_add(xself.min_block_size_);
649
5.11k
            }
650
        }
651
0
    }
652
25.0k
    if is_final {
653
13.7k
        *histograms_size = split.num_types;
654
13.7k
        split.num_blocks = xself.num_blocks_;
655
13.7k
    }
656
25.0k
}
brotli::enc::metablock::BlockSplitterFinishBlock::<brotli::enc::histogram::HistogramCommand, alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
551
5.62k
fn BlockSplitterFinishBlock<
552
5.62k
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors + Clone,
553
5.62k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>,
554
5.62k
>(
555
5.62k
    xself: &mut BlockSplitter,
556
5.62k
    split: &mut BlockSplit<Alloc>,
557
5.62k
    histograms: &mut [HistogramType],
558
5.62k
    histograms_size: &mut usize,
559
5.62k
    is_final: bool,
560
5.62k
) {
561
5.62k
    xself.block_size_ = max(xself.block_size_, xself.min_block_size_);
562
5.62k
    if xself.num_blocks_ == 0usize {
563
4.87k
        split.lengths.slice_mut()[0] = xself.block_size_ as u32;
564
4.87k
        split.types.slice_mut()[0] = 0u8;
565
4.87k
        xself.last_entropy_[0] = BitsEntropy((histograms[0]).slice(), xself.alphabet_size_);
566
4.87k
        xself.last_entropy_[1] = xself.last_entropy_[0];
567
4.87k
        xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
568
4.87k
        split.num_types = split.num_types.wrapping_add(1);
569
4.87k
        xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(1);
570
4.87k
        if xself.curr_histogram_ix_ < *histograms_size {
571
295
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
572
4.57k
        }
573
4.87k
        xself.block_size_ = 0usize;
574
754
    } else if xself.block_size_ > 0usize {
575
754
        let entropy = BitsEntropy(
576
754
            (histograms[xself.curr_histogram_ix_]).slice(),
577
754
            xself.alphabet_size_,
578
754
        );
579
754
        let mut combined_histo: [HistogramType; 2] = [
580
754
            histograms[xself.curr_histogram_ix_].clone(),
581
754
            histograms[xself.curr_histogram_ix_].clone(),
582
754
        ];
583
754
584
754
        let mut combined_entropy: [floatX; 2] = [0.0, 0.0];
585
754
        let mut diff: [floatX; 2] = [0.0, 0.0];
586
2.26k
        for j in 0..2 {
587
1.50k
            let last_histogram_ix: usize = xself.last_histogram_ix_[j];
588
1.50k
            HistogramAddHistogram(&mut combined_histo[j], &histograms[last_histogram_ix]);
589
1.50k
            combined_entropy[j] = BitsEntropy(
590
1.50k
                &mut combined_histo[j].slice_mut()[0..],
591
1.50k
                xself.alphabet_size_,
592
1.50k
            );
593
1.50k
            diff[j] = combined_entropy[j] - entropy - xself.last_entropy_[j];
594
1.50k
        }
595
754
        if split.num_types < 256usize
596
754
            && (diff[0] > xself.split_threshold_)
597
151
            && (diff[1] > xself.split_threshold_)
598
        {
599
120
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
600
120
            split.types.slice_mut()[xself.num_blocks_] = split.num_types as u8;
601
120
            xself.last_histogram_ix_[1] = xself.last_histogram_ix_[0];
602
120
            xself.last_histogram_ix_[0] = split.num_types as u8 as usize;
603
120
            xself.last_entropy_[1] = xself.last_entropy_[0];
604
120
            xself.last_entropy_[0] = entropy;
605
120
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
606
120
            split.num_types = split.num_types.wrapping_add(1);
607
120
            xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(1);
608
120
            if xself.curr_histogram_ix_ < *histograms_size {
609
106
                HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
610
106
            }
611
120
            xself.block_size_ = 0usize;
612
120
            xself.merge_last_count_ = 0usize;
613
120
            xself.target_block_size_ = xself.min_block_size_;
614
634
        } else if diff[1] < diff[0] - 20.0 {
615
43
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
616
43
            split.types.slice_mut()[xself.num_blocks_] =
617
43
                split.types.slice()[xself.num_blocks_.wrapping_sub(2)]; //FIXME: investigate copy?
618
43
            {
619
43
                xself.last_histogram_ix_.swap(0, 1);
620
43
            }
621
43
            histograms[xself.last_histogram_ix_[0]] = combined_histo[1].clone();
622
43
            xself.last_entropy_[1] = xself.last_entropy_[0];
623
43
            xself.last_entropy_[0] = combined_entropy[1];
624
43
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
625
43
            xself.block_size_ = 0usize;
626
43
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
627
43
            xself.merge_last_count_ = 0usize;
628
43
            xself.target_block_size_ = xself.min_block_size_;
629
43
        } else {
630
591
            {
631
591
                let _rhs = xself.block_size_ as u32;
632
591
                let _lhs = &mut split.lengths.slice_mut()[xself.num_blocks_.wrapping_sub(1)];
633
591
                *_lhs = (*_lhs).wrapping_add(_rhs);
634
591
            }
635
591
            histograms[xself.last_histogram_ix_[0]] = combined_histo[0].clone();
636
591
            xself.last_entropy_[0] = combined_entropy[0];
637
591
            if split.num_types == 1 {
638
460
                xself.last_entropy_[1] = xself.last_entropy_[0];
639
460
            }
640
591
            xself.block_size_ = 0usize;
641
591
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
642
591
            if {
643
591
                xself.merge_last_count_ = xself.merge_last_count_.wrapping_add(1);
644
591
                xself.merge_last_count_
645
591
            } > 1
646
278
            {
647
278
                xself.target_block_size_ =
648
278
                    xself.target_block_size_.wrapping_add(xself.min_block_size_);
649
313
            }
650
        }
651
0
    }
652
5.62k
    if is_final {
653
4.87k
        *histograms_size = split.num_types;
654
4.87k
        split.num_blocks = xself.num_blocks_;
655
4.87k
    }
656
5.62k
}
brotli::enc::metablock::BlockSplitterFinishBlock::<brotli::enc::histogram::HistogramLiteral, alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
551
13.4k
fn BlockSplitterFinishBlock<
552
13.4k
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors + Clone,
553
13.4k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>,
554
13.4k
>(
555
13.4k
    xself: &mut BlockSplitter,
556
13.4k
    split: &mut BlockSplit<Alloc>,
557
13.4k
    histograms: &mut [HistogramType],
558
13.4k
    histograms_size: &mut usize,
559
13.4k
    is_final: bool,
560
13.4k
) {
561
13.4k
    xself.block_size_ = max(xself.block_size_, xself.min_block_size_);
562
13.4k
    if xself.num_blocks_ == 0usize {
563
3.97k
        split.lengths.slice_mut()[0] = xself.block_size_ as u32;
564
3.97k
        split.types.slice_mut()[0] = 0u8;
565
3.97k
        xself.last_entropy_[0] = BitsEntropy((histograms[0]).slice(), xself.alphabet_size_);
566
3.97k
        xself.last_entropy_[1] = xself.last_entropy_[0];
567
3.97k
        xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
568
3.97k
        split.num_types = split.num_types.wrapping_add(1);
569
3.97k
        xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(1);
570
3.97k
        if xself.curr_histogram_ix_ < *histograms_size {
571
656
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
572
3.31k
        }
573
3.97k
        xself.block_size_ = 0usize;
574
9.52k
    } else if xself.block_size_ > 0usize {
575
9.52k
        let entropy = BitsEntropy(
576
9.52k
            (histograms[xself.curr_histogram_ix_]).slice(),
577
9.52k
            xself.alphabet_size_,
578
9.52k
        );
579
9.52k
        let mut combined_histo: [HistogramType; 2] = [
580
9.52k
            histograms[xself.curr_histogram_ix_].clone(),
581
9.52k
            histograms[xself.curr_histogram_ix_].clone(),
582
9.52k
        ];
583
9.52k
584
9.52k
        let mut combined_entropy: [floatX; 2] = [0.0, 0.0];
585
9.52k
        let mut diff: [floatX; 2] = [0.0, 0.0];
586
28.5k
        for j in 0..2 {
587
19.0k
            let last_histogram_ix: usize = xself.last_histogram_ix_[j];
588
19.0k
            HistogramAddHistogram(&mut combined_histo[j], &histograms[last_histogram_ix]);
589
19.0k
            combined_entropy[j] = BitsEntropy(
590
19.0k
                &mut combined_histo[j].slice_mut()[0..],
591
19.0k
                xself.alphabet_size_,
592
19.0k
            );
593
19.0k
            diff[j] = combined_entropy[j] - entropy - xself.last_entropy_[j];
594
19.0k
        }
595
9.52k
        if split.num_types < 256usize
596
9.52k
            && (diff[0] > xself.split_threshold_)
597
2.37k
            && (diff[1] > xself.split_threshold_)
598
        {
599
1.72k
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
600
1.72k
            split.types.slice_mut()[xself.num_blocks_] = split.num_types as u8;
601
1.72k
            xself.last_histogram_ix_[1] = xself.last_histogram_ix_[0];
602
1.72k
            xself.last_histogram_ix_[0] = split.num_types as u8 as usize;
603
1.72k
            xself.last_entropy_[1] = xself.last_entropy_[0];
604
1.72k
            xself.last_entropy_[0] = entropy;
605
1.72k
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
606
1.72k
            split.num_types = split.num_types.wrapping_add(1);
607
1.72k
            xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(1);
608
1.72k
            if xself.curr_histogram_ix_ < *histograms_size {
609
1.71k
                HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
610
1.71k
            }
611
1.72k
            xself.block_size_ = 0usize;
612
1.72k
            xself.merge_last_count_ = 0usize;
613
1.72k
            xself.target_block_size_ = xself.min_block_size_;
614
7.79k
        } else if diff[1] < diff[0] - 20.0 {
615
1.23k
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
616
1.23k
            split.types.slice_mut()[xself.num_blocks_] =
617
1.23k
                split.types.slice()[xself.num_blocks_.wrapping_sub(2)]; //FIXME: investigate copy?
618
1.23k
            {
619
1.23k
                xself.last_histogram_ix_.swap(0, 1);
620
1.23k
            }
621
1.23k
            histograms[xself.last_histogram_ix_[0]] = combined_histo[1].clone();
622
1.23k
            xself.last_entropy_[1] = xself.last_entropy_[0];
623
1.23k
            xself.last_entropy_[0] = combined_entropy[1];
624
1.23k
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
625
1.23k
            xself.block_size_ = 0usize;
626
1.23k
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
627
1.23k
            xself.merge_last_count_ = 0usize;
628
1.23k
            xself.target_block_size_ = xself.min_block_size_;
629
1.23k
        } else {
630
6.55k
            {
631
6.55k
                let _rhs = xself.block_size_ as u32;
632
6.55k
                let _lhs = &mut split.lengths.slice_mut()[xself.num_blocks_.wrapping_sub(1)];
633
6.55k
                *_lhs = (*_lhs).wrapping_add(_rhs);
634
6.55k
            }
635
6.55k
            histograms[xself.last_histogram_ix_[0]] = combined_histo[0].clone();
636
6.55k
            xself.last_entropy_[0] = combined_entropy[0];
637
6.55k
            if split.num_types == 1 {
638
3.01k
                xself.last_entropy_[1] = xself.last_entropy_[0];
639
3.53k
            }
640
6.55k
            xself.block_size_ = 0usize;
641
6.55k
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
642
6.55k
            if {
643
6.55k
                xself.merge_last_count_ = xself.merge_last_count_.wrapping_add(1);
644
6.55k
                xself.merge_last_count_
645
6.55k
            } > 1
646
4.38k
            {
647
4.38k
                xself.target_block_size_ =
648
4.38k
                    xself.target_block_size_.wrapping_add(xself.min_block_size_);
649
4.38k
            }
650
        }
651
0
    }
652
13.4k
    if is_final {
653
3.97k
        *histograms_size = split.num_types;
654
3.97k
        split.num_blocks = xself.num_blocks_;
655
9.52k
    }
656
13.4k
}
brotli::enc::metablock::BlockSplitterFinishBlock::<brotli::enc::histogram::HistogramDistance, alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
551
5.92k
fn BlockSplitterFinishBlock<
552
5.92k
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors + Clone,
553
5.92k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>,
554
5.92k
>(
555
5.92k
    xself: &mut BlockSplitter,
556
5.92k
    split: &mut BlockSplit<Alloc>,
557
5.92k
    histograms: &mut [HistogramType],
558
5.92k
    histograms_size: &mut usize,
559
5.92k
    is_final: bool,
560
5.92k
) {
561
5.92k
    xself.block_size_ = max(xself.block_size_, xself.min_block_size_);
562
5.92k
    if xself.num_blocks_ == 0usize {
563
4.87k
        split.lengths.slice_mut()[0] = xself.block_size_ as u32;
564
4.87k
        split.types.slice_mut()[0] = 0u8;
565
4.87k
        xself.last_entropy_[0] = BitsEntropy((histograms[0]).slice(), xself.alphabet_size_);
566
4.87k
        xself.last_entropy_[1] = xself.last_entropy_[0];
567
4.87k
        xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
568
4.87k
        split.num_types = split.num_types.wrapping_add(1);
569
4.87k
        xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(1);
570
4.87k
        if xself.curr_histogram_ix_ < *histograms_size {
571
367
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
572
4.50k
        }
573
4.87k
        xself.block_size_ = 0usize;
574
1.05k
    } else if xself.block_size_ > 0usize {
575
1.05k
        let entropy = BitsEntropy(
576
1.05k
            (histograms[xself.curr_histogram_ix_]).slice(),
577
1.05k
            xself.alphabet_size_,
578
1.05k
        );
579
1.05k
        let mut combined_histo: [HistogramType; 2] = [
580
1.05k
            histograms[xself.curr_histogram_ix_].clone(),
581
1.05k
            histograms[xself.curr_histogram_ix_].clone(),
582
1.05k
        ];
583
1.05k
584
1.05k
        let mut combined_entropy: [floatX; 2] = [0.0, 0.0];
585
1.05k
        let mut diff: [floatX; 2] = [0.0, 0.0];
586
3.15k
        for j in 0..2 {
587
2.10k
            let last_histogram_ix: usize = xself.last_histogram_ix_[j];
588
2.10k
            HistogramAddHistogram(&mut combined_histo[j], &histograms[last_histogram_ix]);
589
2.10k
            combined_entropy[j] = BitsEntropy(
590
2.10k
                &mut combined_histo[j].slice_mut()[0..],
591
2.10k
                xself.alphabet_size_,
592
2.10k
            );
593
2.10k
            diff[j] = combined_entropy[j] - entropy - xself.last_entropy_[j];
594
2.10k
        }
595
1.05k
        if split.num_types < 256usize
596
1.05k
            && (diff[0] > xself.split_threshold_)
597
220
            && (diff[1] > xself.split_threshold_)
598
        {
599
204
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
600
204
            split.types.slice_mut()[xself.num_blocks_] = split.num_types as u8;
601
204
            xself.last_histogram_ix_[1] = xself.last_histogram_ix_[0];
602
204
            xself.last_histogram_ix_[0] = split.num_types as u8 as usize;
603
204
            xself.last_entropy_[1] = xself.last_entropy_[0];
604
204
            xself.last_entropy_[0] = entropy;
605
204
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
606
204
            split.num_types = split.num_types.wrapping_add(1);
607
204
            xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(1);
608
204
            if xself.curr_histogram_ix_ < *histograms_size {
609
199
                HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
610
199
            }
611
204
            xself.block_size_ = 0usize;
612
204
            xself.merge_last_count_ = 0usize;
613
204
            xself.target_block_size_ = xself.min_block_size_;
614
846
        } else if diff[1] < diff[0] - 20.0 {
615
24
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
616
24
            split.types.slice_mut()[xself.num_blocks_] =
617
24
                split.types.slice()[xself.num_blocks_.wrapping_sub(2)]; //FIXME: investigate copy?
618
24
            {
619
24
                xself.last_histogram_ix_.swap(0, 1);
620
24
            }
621
24
            histograms[xself.last_histogram_ix_[0]] = combined_histo[1].clone();
622
24
            xself.last_entropy_[1] = xself.last_entropy_[0];
623
24
            xself.last_entropy_[0] = combined_entropy[1];
624
24
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
625
24
            xself.block_size_ = 0usize;
626
24
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
627
24
            xself.merge_last_count_ = 0usize;
628
24
            xself.target_block_size_ = xself.min_block_size_;
629
24
        } else {
630
822
            {
631
822
                let _rhs = xself.block_size_ as u32;
632
822
                let _lhs = &mut split.lengths.slice_mut()[xself.num_blocks_.wrapping_sub(1)];
633
822
                *_lhs = (*_lhs).wrapping_add(_rhs);
634
822
            }
635
822
            histograms[xself.last_histogram_ix_[0]] = combined_histo[0].clone();
636
822
            xself.last_entropy_[0] = combined_entropy[0];
637
822
            if split.num_types == 1 {
638
638
                xself.last_entropy_[1] = xself.last_entropy_[0];
639
638
            }
640
822
            xself.block_size_ = 0usize;
641
822
            HistogramClear(&mut histograms[xself.curr_histogram_ix_]);
642
822
            if {
643
822
                xself.merge_last_count_ = xself.merge_last_count_.wrapping_add(1);
644
822
                xself.merge_last_count_
645
822
            } > 1
646
456
            {
647
456
                xself.target_block_size_ =
648
456
                    xself.target_block_size_.wrapping_add(xself.min_block_size_);
649
456
            }
650
        }
651
0
    }
652
5.92k
    if is_final {
653
4.87k
        *histograms_size = split.num_types;
654
4.87k
        split.num_blocks = xself.num_blocks_;
655
4.87k
    }
656
5.92k
}
Unexecuted instantiation: brotli::enc::metablock::BlockSplitterFinishBlock::<_, _>
657
const BROTLI_MAX_STATIC_CONTEXTS: usize = 13;
658
659
4.24k
fn ContextBlockSplitterFinishBlock<
660
4.24k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32> + alloc::Allocator<HistogramLiteral>,
661
4.24k
    AllocHL: alloc::Allocator<HistogramLiteral>,
662
4.24k
>(
663
4.24k
    xself: &mut ContextBlockSplitter,
664
4.24k
    m: &mut AllocHL,
665
4.24k
    split: &mut BlockSplit<Alloc>,
666
4.24k
    histograms: &mut [HistogramLiteral],
667
4.24k
    histograms_size: &mut usize,
668
4.24k
    is_final: bool,
669
4.24k
) {
670
4.24k
    let num_contexts: usize = xself.num_contexts_;
671
4.24k
    if xself.block_size_ < xself.min_block_size_ {
672
856
        xself.block_size_ = xself.min_block_size_;
673
3.38k
    }
674
4.24k
    if xself.num_blocks_ == 0usize {
675
898
        split.lengths.slice_mut()[0] = xself.block_size_ as u32;
676
898
        split.types.slice_mut()[0] = 0u8;
677
2.51k
        for i in 0usize..num_contexts {
678
2.51k
            xself.last_entropy_[i] = BitsEntropy((histograms[i]).slice(), xself.alphabet_size_);
679
2.51k
            xself.last_entropy_[num_contexts.wrapping_add(i)] = xself.last_entropy_[i];
680
2.51k
        }
681
898
        xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
682
898
        split.num_types = split.num_types.wrapping_add(1);
683
898
        xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(num_contexts);
684
898
        if xself.curr_histogram_ix_ < *histograms_size {
685
308
            ClearHistograms(
686
308
                &mut histograms[xself.curr_histogram_ix_..],
687
308
                xself.num_contexts_,
688
308
            );
689
590
        }
690
898
        xself.block_size_ = 0usize;
691
3.34k
    } else if xself.block_size_ > 0usize {
692
3.34k
        let mut entropy = [0.0; BROTLI_MAX_STATIC_CONTEXTS];
693
3.34k
        let mut combined_histo = m.alloc_cell(2 * num_contexts);
694
3.34k
        let mut combined_entropy = [0.0; 2 * BROTLI_MAX_STATIC_CONTEXTS];
695
3.34k
        let mut diff = [0.0; 2];
696
9.26k
        for i in 0usize..num_contexts {
697
9.26k
            let curr_histo_ix: usize = xself.curr_histogram_ix_.wrapping_add(i);
698
9.26k
            let mut j: usize;
699
9.26k
            entropy[i] = BitsEntropy((histograms[curr_histo_ix]).slice(), xself.alphabet_size_);
700
9.26k
            j = 0usize;
701
27.7k
            while j < 2usize {
702
18.5k
                {
703
18.5k
                    let jx: usize = j.wrapping_mul(num_contexts).wrapping_add(i);
704
18.5k
                    let last_histogram_ix: usize = xself.last_histogram_ix_[j].wrapping_add(i);
705
18.5k
                    combined_histo.slice_mut()[jx] = histograms[curr_histo_ix].clone();
706
18.5k
                    HistogramAddHistogram(
707
18.5k
                        &mut combined_histo.slice_mut()[jx],
708
18.5k
                        &mut histograms[last_histogram_ix],
709
18.5k
                    );
710
18.5k
                    combined_entropy[jx] =
711
18.5k
                        BitsEntropy(combined_histo.slice()[jx].slice(), xself.alphabet_size_);
712
18.5k
                    diff[j] += combined_entropy[jx] - entropy[i] - xself.last_entropy_[jx];
713
18.5k
                }
714
18.5k
                j = j.wrapping_add(1);
715
18.5k
            }
716
        }
717
3.34k
        if split.num_types < xself.max_block_types_
718
3.29k
            && (diff[0] > xself.split_threshold_)
719
1.76k
            && (diff[1] > xself.split_threshold_)
720
        {
721
1.49k
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
722
1.49k
            split.types.slice_mut()[xself.num_blocks_] = split.num_types as u8;
723
1.49k
            xself.last_histogram_ix_[1] = xself.last_histogram_ix_[0];
724
1.49k
            xself.last_histogram_ix_[0] = split.num_types.wrapping_mul(num_contexts);
725
4.21k
            for i in 0usize..num_contexts {
726
4.21k
                xself.last_entropy_[num_contexts.wrapping_add(i)] = xself.last_entropy_[i];
727
4.21k
                xself.last_entropy_[i] = entropy[i];
728
4.21k
            }
729
1.49k
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
730
1.49k
            split.num_types = split.num_types.wrapping_add(1);
731
1.49k
            xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(num_contexts);
732
1.49k
            if xself.curr_histogram_ix_ < *histograms_size {
733
1.44k
                ClearHistograms(
734
1.44k
                    &mut histograms[xself.curr_histogram_ix_..],
735
1.44k
                    xself.num_contexts_,
736
1.44k
                );
737
1.44k
            }
738
1.49k
            xself.block_size_ = 0usize;
739
1.49k
            xself.merge_last_count_ = 0usize;
740
1.49k
            xself.target_block_size_ = xself.min_block_size_;
741
1.84k
        } else if diff[1] < diff[0] - 20.0 {
742
540
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
743
540
            let nbm2 = split.types.slice()[xself.num_blocks_.wrapping_sub(2)];
744
540
            split.types.slice_mut()[xself.num_blocks_] = nbm2;
745
540
746
540
            {
747
540
                xself.last_histogram_ix_.swap(0, 1);
748
540
            }
749
1.53k
            for i in 0usize..num_contexts {
750
1.53k
                histograms[xself.last_histogram_ix_[0].wrapping_add(i)] =
751
1.53k
                    combined_histo.slice()[num_contexts.wrapping_add(i)].clone();
752
1.53k
                xself.last_entropy_[num_contexts.wrapping_add(i)] = xself.last_entropy_[i];
753
1.53k
                xself.last_entropy_[i] = combined_entropy[num_contexts.wrapping_add(i)];
754
1.53k
                HistogramClear(&mut histograms[xself.curr_histogram_ix_.wrapping_add(i)]);
755
1.53k
            }
756
540
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
757
540
            xself.block_size_ = 0usize;
758
540
            xself.merge_last_count_ = 0usize;
759
540
            xself.target_block_size_ = xself.min_block_size_;
760
        } else {
761
1.30k
            {
762
1.30k
                let _rhs = xself.block_size_ as u32;
763
1.30k
                let _lhs = &mut split.lengths.slice_mut()[xself.num_blocks_.wrapping_sub(1)];
764
1.30k
                let old_split_length = *_lhs;
765
1.30k
                *_lhs = old_split_length.wrapping_add(_rhs);
766
1.30k
            }
767
3.51k
            for i in 0usize..num_contexts {
768
3.51k
                histograms[xself.last_histogram_ix_[0].wrapping_add(i)] =
769
3.51k
                    combined_histo.slice()[i].clone();
770
3.51k
                xself.last_entropy_[i] = combined_entropy[i];
771
3.51k
                if split.num_types == 1 {
772
1.20k
                    xself.last_entropy_[num_contexts.wrapping_add(i)] = xself.last_entropy_[i];
773
2.30k
                }
774
3.51k
                HistogramClear(&mut histograms[xself.curr_histogram_ix_.wrapping_add(i)]);
775
            }
776
1.30k
            xself.block_size_ = 0usize;
777
1.30k
            if {
778
1.30k
                xself.merge_last_count_ = xself.merge_last_count_.wrapping_add(1);
779
1.30k
                xself.merge_last_count_
780
1.30k
            } > 1
781
616
            {
782
616
                xself.target_block_size_ =
783
616
                    xself.target_block_size_.wrapping_add(xself.min_block_size_);
784
689
            }
785
        }
786
3.34k
        m.free_cell(combined_histo);
787
0
    }
788
4.24k
    if is_final {
789
898
        *histograms_size = split.num_types.wrapping_mul(num_contexts);
790
898
        split.num_blocks = xself.num_blocks_;
791
3.34k
    }
792
4.24k
}
brotli::enc::metablock::ContextBlockSplitterFinishBlock::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
659
4.24k
fn ContextBlockSplitterFinishBlock<
660
4.24k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32> + alloc::Allocator<HistogramLiteral>,
661
4.24k
    AllocHL: alloc::Allocator<HistogramLiteral>,
662
4.24k
>(
663
4.24k
    xself: &mut ContextBlockSplitter,
664
4.24k
    m: &mut AllocHL,
665
4.24k
    split: &mut BlockSplit<Alloc>,
666
4.24k
    histograms: &mut [HistogramLiteral],
667
4.24k
    histograms_size: &mut usize,
668
4.24k
    is_final: bool,
669
4.24k
) {
670
4.24k
    let num_contexts: usize = xself.num_contexts_;
671
4.24k
    if xself.block_size_ < xself.min_block_size_ {
672
856
        xself.block_size_ = xself.min_block_size_;
673
3.38k
    }
674
4.24k
    if xself.num_blocks_ == 0usize {
675
898
        split.lengths.slice_mut()[0] = xself.block_size_ as u32;
676
898
        split.types.slice_mut()[0] = 0u8;
677
2.51k
        for i in 0usize..num_contexts {
678
2.51k
            xself.last_entropy_[i] = BitsEntropy((histograms[i]).slice(), xself.alphabet_size_);
679
2.51k
            xself.last_entropy_[num_contexts.wrapping_add(i)] = xself.last_entropy_[i];
680
2.51k
        }
681
898
        xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
682
898
        split.num_types = split.num_types.wrapping_add(1);
683
898
        xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(num_contexts);
684
898
        if xself.curr_histogram_ix_ < *histograms_size {
685
308
            ClearHistograms(
686
308
                &mut histograms[xself.curr_histogram_ix_..],
687
308
                xself.num_contexts_,
688
308
            );
689
590
        }
690
898
        xself.block_size_ = 0usize;
691
3.34k
    } else if xself.block_size_ > 0usize {
692
3.34k
        let mut entropy = [0.0; BROTLI_MAX_STATIC_CONTEXTS];
693
3.34k
        let mut combined_histo = m.alloc_cell(2 * num_contexts);
694
3.34k
        let mut combined_entropy = [0.0; 2 * BROTLI_MAX_STATIC_CONTEXTS];
695
3.34k
        let mut diff = [0.0; 2];
696
9.26k
        for i in 0usize..num_contexts {
697
9.26k
            let curr_histo_ix: usize = xself.curr_histogram_ix_.wrapping_add(i);
698
9.26k
            let mut j: usize;
699
9.26k
            entropy[i] = BitsEntropy((histograms[curr_histo_ix]).slice(), xself.alphabet_size_);
700
9.26k
            j = 0usize;
701
27.7k
            while j < 2usize {
702
18.5k
                {
703
18.5k
                    let jx: usize = j.wrapping_mul(num_contexts).wrapping_add(i);
704
18.5k
                    let last_histogram_ix: usize = xself.last_histogram_ix_[j].wrapping_add(i);
705
18.5k
                    combined_histo.slice_mut()[jx] = histograms[curr_histo_ix].clone();
706
18.5k
                    HistogramAddHistogram(
707
18.5k
                        &mut combined_histo.slice_mut()[jx],
708
18.5k
                        &mut histograms[last_histogram_ix],
709
18.5k
                    );
710
18.5k
                    combined_entropy[jx] =
711
18.5k
                        BitsEntropy(combined_histo.slice()[jx].slice(), xself.alphabet_size_);
712
18.5k
                    diff[j] += combined_entropy[jx] - entropy[i] - xself.last_entropy_[jx];
713
18.5k
                }
714
18.5k
                j = j.wrapping_add(1);
715
18.5k
            }
716
        }
717
3.34k
        if split.num_types < xself.max_block_types_
718
3.29k
            && (diff[0] > xself.split_threshold_)
719
1.76k
            && (diff[1] > xself.split_threshold_)
720
        {
721
1.49k
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
722
1.49k
            split.types.slice_mut()[xself.num_blocks_] = split.num_types as u8;
723
1.49k
            xself.last_histogram_ix_[1] = xself.last_histogram_ix_[0];
724
1.49k
            xself.last_histogram_ix_[0] = split.num_types.wrapping_mul(num_contexts);
725
4.21k
            for i in 0usize..num_contexts {
726
4.21k
                xself.last_entropy_[num_contexts.wrapping_add(i)] = xself.last_entropy_[i];
727
4.21k
                xself.last_entropy_[i] = entropy[i];
728
4.21k
            }
729
1.49k
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
730
1.49k
            split.num_types = split.num_types.wrapping_add(1);
731
1.49k
            xself.curr_histogram_ix_ = xself.curr_histogram_ix_.wrapping_add(num_contexts);
732
1.49k
            if xself.curr_histogram_ix_ < *histograms_size {
733
1.44k
                ClearHistograms(
734
1.44k
                    &mut histograms[xself.curr_histogram_ix_..],
735
1.44k
                    xself.num_contexts_,
736
1.44k
                );
737
1.44k
            }
738
1.49k
            xself.block_size_ = 0usize;
739
1.49k
            xself.merge_last_count_ = 0usize;
740
1.49k
            xself.target_block_size_ = xself.min_block_size_;
741
1.84k
        } else if diff[1] < diff[0] - 20.0 {
742
540
            split.lengths.slice_mut()[xself.num_blocks_] = xself.block_size_ as u32;
743
540
            let nbm2 = split.types.slice()[xself.num_blocks_.wrapping_sub(2)];
744
540
            split.types.slice_mut()[xself.num_blocks_] = nbm2;
745
540
746
540
            {
747
540
                xself.last_histogram_ix_.swap(0, 1);
748
540
            }
749
1.53k
            for i in 0usize..num_contexts {
750
1.53k
                histograms[xself.last_histogram_ix_[0].wrapping_add(i)] =
751
1.53k
                    combined_histo.slice()[num_contexts.wrapping_add(i)].clone();
752
1.53k
                xself.last_entropy_[num_contexts.wrapping_add(i)] = xself.last_entropy_[i];
753
1.53k
                xself.last_entropy_[i] = combined_entropy[num_contexts.wrapping_add(i)];
754
1.53k
                HistogramClear(&mut histograms[xself.curr_histogram_ix_.wrapping_add(i)]);
755
1.53k
            }
756
540
            xself.num_blocks_ = xself.num_blocks_.wrapping_add(1);
757
540
            xself.block_size_ = 0usize;
758
540
            xself.merge_last_count_ = 0usize;
759
540
            xself.target_block_size_ = xself.min_block_size_;
760
        } else {
761
1.30k
            {
762
1.30k
                let _rhs = xself.block_size_ as u32;
763
1.30k
                let _lhs = &mut split.lengths.slice_mut()[xself.num_blocks_.wrapping_sub(1)];
764
1.30k
                let old_split_length = *_lhs;
765
1.30k
                *_lhs = old_split_length.wrapping_add(_rhs);
766
1.30k
            }
767
3.51k
            for i in 0usize..num_contexts {
768
3.51k
                histograms[xself.last_histogram_ix_[0].wrapping_add(i)] =
769
3.51k
                    combined_histo.slice()[i].clone();
770
3.51k
                xself.last_entropy_[i] = combined_entropy[i];
771
3.51k
                if split.num_types == 1 {
772
1.20k
                    xself.last_entropy_[num_contexts.wrapping_add(i)] = xself.last_entropy_[i];
773
2.30k
                }
774
3.51k
                HistogramClear(&mut histograms[xself.curr_histogram_ix_.wrapping_add(i)]);
775
            }
776
1.30k
            xself.block_size_ = 0usize;
777
1.30k
            if {
778
1.30k
                xself.merge_last_count_ = xself.merge_last_count_.wrapping_add(1);
779
1.30k
                xself.merge_last_count_
780
1.30k
            } > 1
781
616
            {
782
616
                xself.target_block_size_ =
783
616
                    xself.target_block_size_.wrapping_add(xself.min_block_size_);
784
689
            }
785
        }
786
3.34k
        m.free_cell(combined_histo);
787
0
    }
788
4.24k
    if is_final {
789
898
        *histograms_size = split.num_types.wrapping_mul(num_contexts);
790
898
        split.num_blocks = xself.num_blocks_;
791
3.34k
    }
792
4.24k
}
Unexecuted instantiation: brotli::enc::metablock::ContextBlockSplitterFinishBlock::<_, _>
793
794
14.7M
fn BlockSplitterAddSymbol<
795
14.7M
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors + Clone,
796
14.7M
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>,
797
14.7M
>(
798
14.7M
    xself: &mut BlockSplitter,
799
14.7M
    split: &mut BlockSplit<Alloc>,
800
14.7M
    histograms: &mut [HistogramType],
801
14.7M
    histograms_size: &mut usize,
802
14.7M
    symbol: usize,
803
14.7M
) {
804
14.7M
    HistogramAddItem(&mut histograms[xself.curr_histogram_ix_], symbol);
805
14.7M
    xself.block_size_ = xself.block_size_.wrapping_add(1);
806
14.7M
    if xself.block_size_ == xself.target_block_size_ {
807
11.3k
        BlockSplitterFinishBlock(xself, split, histograms, histograms_size, false);
808
14.7M
    }
809
14.7M
}
brotli::enc::metablock::BlockSplitterAddSymbol::<brotli::enc::histogram::HistogramCommand, alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
794
1.21M
fn BlockSplitterAddSymbol<
795
1.21M
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors + Clone,
796
1.21M
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>,
797
1.21M
>(
798
1.21M
    xself: &mut BlockSplitter,
799
1.21M
    split: &mut BlockSplit<Alloc>,
800
1.21M
    histograms: &mut [HistogramType],
801
1.21M
    histograms_size: &mut usize,
802
1.21M
    symbol: usize,
803
1.21M
) {
804
1.21M
    HistogramAddItem(&mut histograms[xself.curr_histogram_ix_], symbol);
805
1.21M
    xself.block_size_ = xself.block_size_.wrapping_add(1);
806
1.21M
    if xself.block_size_ == xself.target_block_size_ {
807
754
        BlockSplitterFinishBlock(xself, split, histograms, histograms_size, false);
808
1.21M
    }
809
1.21M
}
brotli::enc::metablock::BlockSplitterAddSymbol::<brotli::enc::histogram::HistogramLiteral, alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
794
12.6M
fn BlockSplitterAddSymbol<
795
12.6M
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors + Clone,
796
12.6M
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>,
797
12.6M
>(
798
12.6M
    xself: &mut BlockSplitter,
799
12.6M
    split: &mut BlockSplit<Alloc>,
800
12.6M
    histograms: &mut [HistogramType],
801
12.6M
    histograms_size: &mut usize,
802
12.6M
    symbol: usize,
803
12.6M
) {
804
12.6M
    HistogramAddItem(&mut histograms[xself.curr_histogram_ix_], symbol);
805
12.6M
    xself.block_size_ = xself.block_size_.wrapping_add(1);
806
12.6M
    if xself.block_size_ == xself.target_block_size_ {
807
9.52k
        BlockSplitterFinishBlock(xself, split, histograms, histograms_size, false);
808
12.6M
    }
809
12.6M
}
brotli::enc::metablock::BlockSplitterAddSymbol::<brotli::enc::histogram::HistogramDistance, alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
794
876k
fn BlockSplitterAddSymbol<
795
876k
    HistogramType: SliceWrapper<u32> + SliceWrapperMut<u32> + CostAccessors + Clone,
796
876k
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>,
797
876k
>(
798
876k
    xself: &mut BlockSplitter,
799
876k
    split: &mut BlockSplit<Alloc>,
800
876k
    histograms: &mut [HistogramType],
801
876k
    histograms_size: &mut usize,
802
876k
    symbol: usize,
803
876k
) {
804
876k
    HistogramAddItem(&mut histograms[xself.curr_histogram_ix_], symbol);
805
876k
    xself.block_size_ = xself.block_size_.wrapping_add(1);
806
876k
    if xself.block_size_ == xself.target_block_size_ {
807
1.05k
        BlockSplitterFinishBlock(xself, split, histograms, histograms_size, false);
808
875k
    }
809
876k
}
Unexecuted instantiation: brotli::enc::metablock::BlockSplitterAddSymbol::<_, _>
810
811
2.53M
fn ContextBlockSplitterAddSymbol<
812
2.53M
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32> + alloc::Allocator<HistogramLiteral>,
813
2.53M
>(
814
2.53M
    xself: &mut ContextBlockSplitter,
815
2.53M
    m: &mut Alloc,
816
2.53M
    split: &mut BlockSplit<Alloc>,
817
2.53M
    histograms: &mut [HistogramLiteral],
818
2.53M
    histograms_size: &mut usize,
819
2.53M
    symbol: usize,
820
2.53M
    context: usize,
821
2.53M
) {
822
2.53M
    HistogramAddItem(
823
2.53M
        &mut histograms[xself.curr_histogram_ix_.wrapping_add(context)],
824
2.53M
        symbol,
825
2.53M
    );
826
2.53M
    xself.block_size_ = xself.block_size_.wrapping_add(1);
827
2.53M
    if xself.block_size_ == xself.target_block_size_ {
828
3.34k
        ContextBlockSplitterFinishBlock(xself, m, split, histograms, histograms_size, false);
829
2.52M
    }
830
2.53M
}
brotli::enc::metablock::ContextBlockSplitterAddSymbol::<alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
811
2.53M
fn ContextBlockSplitterAddSymbol<
812
2.53M
    Alloc: alloc::Allocator<u8> + alloc::Allocator<u32> + alloc::Allocator<HistogramLiteral>,
813
2.53M
>(
814
2.53M
    xself: &mut ContextBlockSplitter,
815
2.53M
    m: &mut Alloc,
816
2.53M
    split: &mut BlockSplit<Alloc>,
817
2.53M
    histograms: &mut [HistogramLiteral],
818
2.53M
    histograms_size: &mut usize,
819
2.53M
    symbol: usize,
820
2.53M
    context: usize,
821
2.53M
) {
822
2.53M
    HistogramAddItem(
823
2.53M
        &mut histograms[xself.curr_histogram_ix_.wrapping_add(context)],
824
2.53M
        symbol,
825
2.53M
    );
826
2.53M
    xself.block_size_ = xself.block_size_.wrapping_add(1);
827
2.53M
    if xself.block_size_ == xself.target_block_size_ {
828
3.34k
        ContextBlockSplitterFinishBlock(xself, m, split, histograms, histograms_size, false);
829
2.52M
    }
830
2.53M
}
Unexecuted instantiation: brotli::enc::metablock::ContextBlockSplitterAddSymbol::<_>
831
832
898
fn MapStaticContexts<
833
898
    Alloc: alloc::Allocator<u8>
834
898
        + alloc::Allocator<u32>
835
898
        + alloc::Allocator<HistogramLiteral>
836
898
        + alloc::Allocator<HistogramCommand>
837
898
        + alloc::Allocator<HistogramDistance>,
838
898
>(
839
898
    m32: &mut Alloc,
840
898
    num_contexts: usize,
841
898
    static_context_map: &[u32],
842
898
    mb: &mut MetaBlockSplit<Alloc>,
843
898
) {
844
898
    mb.literal_context_map_size = mb.literal_split.num_types << 6;
845
898
    let new_literal_context_map = allocate::<u32, _>(m32, mb.literal_context_map_size);
846
898
    <Alloc as Allocator<u32>>::free_cell(
847
898
        m32,
848
898
        core::mem::replace(&mut mb.literal_context_map, new_literal_context_map),
849
898
    );
850
2.39k
    for i in 0usize..mb.literal_split.num_types {
851
2.39k
        let offset: u32 = i.wrapping_mul(num_contexts) as u32;
852
153k
        for j in 0usize..(1u32 << 6) as usize {
853
153k
            mb.literal_context_map.slice_mut()[(i << 6).wrapping_add(j)] =
854
153k
                offset.wrapping_add(static_context_map[j]);
855
153k
        }
856
    }
857
898
}
brotli::enc::metablock::MapStaticContexts::<alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
832
898
fn MapStaticContexts<
833
898
    Alloc: alloc::Allocator<u8>
834
898
        + alloc::Allocator<u32>
835
898
        + alloc::Allocator<HistogramLiteral>
836
898
        + alloc::Allocator<HistogramCommand>
837
898
        + alloc::Allocator<HistogramDistance>,
838
898
>(
839
898
    m32: &mut Alloc,
840
898
    num_contexts: usize,
841
898
    static_context_map: &[u32],
842
898
    mb: &mut MetaBlockSplit<Alloc>,
843
898
) {
844
898
    mb.literal_context_map_size = mb.literal_split.num_types << 6;
845
898
    let new_literal_context_map = allocate::<u32, _>(m32, mb.literal_context_map_size);
846
898
    <Alloc as Allocator<u32>>::free_cell(
847
898
        m32,
848
898
        core::mem::replace(&mut mb.literal_context_map, new_literal_context_map),
849
898
    );
850
2.39k
    for i in 0usize..mb.literal_split.num_types {
851
2.39k
        let offset: u32 = i.wrapping_mul(num_contexts) as u32;
852
153k
        for j in 0usize..(1u32 << 6) as usize {
853
153k
            mb.literal_context_map.slice_mut()[(i << 6).wrapping_add(j)] =
854
153k
                offset.wrapping_add(static_context_map[j]);
855
153k
        }
856
    }
857
898
}
Unexecuted instantiation: brotli::enc::metablock::MapStaticContexts::<_>
858
4.87k
pub fn BrotliBuildMetaBlockGreedyInternal<
859
4.87k
    Alloc: alloc::Allocator<u8>
860
4.87k
        + alloc::Allocator<u32>
861
4.87k
        + alloc::Allocator<HistogramLiteral>
862
4.87k
        + alloc::Allocator<HistogramCommand>
863
4.87k
        + alloc::Allocator<HistogramDistance>,
864
4.87k
>(
865
4.87k
    alloc: &mut Alloc,
866
4.87k
    ringbuffer: &[u8],
867
4.87k
    mut pos: usize,
868
4.87k
    mask: usize,
869
4.87k
    mut prev_byte: u8,
870
4.87k
    mut prev_byte2: u8,
871
4.87k
    literal_context_mode: ContextType,
872
4.87k
    num_contexts: usize,
873
4.87k
    static_context_map: &[u32],
874
4.87k
    commands: &[Command],
875
4.87k
    n_commands: usize,
876
4.87k
    mb: &mut MetaBlockSplit<Alloc>,
877
4.87k
) {
878
4.87k
    let mut lit_blocks: LitBlocks;
879
4.87k
    let mut cmd_blocks: BlockSplitter;
880
4.87k
    let mut dist_blocks: BlockSplitter;
881
4.87k
    let mut num_literals: usize = 0usize;
882
1.21M
    for i in 0usize..n_commands {
883
1.21M
        num_literals = num_literals.wrapping_add((commands[i]).insert_len_ as usize);
884
1.21M
    }
885
4.87k
    lit_blocks = if num_contexts == 1 {
886
3.97k
        LitBlocks::plain(InitBlockSplitter::<HistogramLiteral, Alloc>(
887
3.97k
            alloc,
888
3.97k
            256usize,
889
3.97k
            512usize,
890
3.97k
            400.0,
891
3.97k
            num_literals,
892
3.97k
            &mut mb.literal_split,
893
3.97k
            &mut mb.literal_histograms,
894
3.97k
            &mut mb.literal_histograms_size,
895
3.97k
        ))
896
    } else {
897
898
        LitBlocks::ctx(InitContextBlockSplitter::<Alloc>(
898
898
            alloc,
899
898
            256usize,
900
898
            num_contexts,
901
898
            512usize,
902
898
            400.0,
903
898
            num_literals,
904
898
            &mut mb.literal_split,
905
898
            &mut mb.literal_histograms,
906
898
            &mut mb.literal_histograms_size,
907
898
        ))
908
    };
909
4.87k
    cmd_blocks = InitBlockSplitter::<HistogramCommand, Alloc>(
910
4.87k
        alloc,
911
4.87k
        704usize,
912
4.87k
        1024usize,
913
4.87k
        500.0,
914
4.87k
        n_commands,
915
4.87k
        &mut mb.command_split,
916
4.87k
        &mut mb.command_histograms,
917
4.87k
        &mut mb.command_histograms_size,
918
4.87k
    );
919
4.87k
    dist_blocks = InitBlockSplitter::<HistogramDistance, Alloc>(
920
4.87k
        alloc,
921
4.87k
        64usize,
922
4.87k
        512usize,
923
4.87k
        100.0,
924
4.87k
        n_commands,
925
4.87k
        &mut mb.distance_split,
926
4.87k
        &mut mb.distance_histograms,
927
4.87k
        &mut mb.distance_histograms_size,
928
4.87k
    );
929
930
1.21M
    for i in 0usize..n_commands {
931
1.21M
        let cmd: Command = commands[i];
932
1.21M
        let mut j: usize;
933
1.21M
        BlockSplitterAddSymbol(
934
1.21M
            &mut cmd_blocks,
935
1.21M
            &mut mb.command_split,
936
1.21M
            mb.command_histograms.slice_mut(),
937
1.21M
            &mut mb.command_histograms_size,
938
1.21M
            cmd.cmd_prefix_ as usize,
939
1.21M
        );
940
1.21M
        j = cmd.insert_len_ as usize;
941
16.4M
        while j != 0usize {
942
            {
943
15.2M
                let literal: u8 = ringbuffer[(pos & mask)];
944
15.2M
                match (&mut lit_blocks) {
945
12.6M
                    &mut LitBlocks::plain(ref mut lit_blocks_plain) => BlockSplitterAddSymbol(
946
12.6M
                        lit_blocks_plain,
947
12.6M
                        &mut mb.literal_split,
948
12.6M
                        mb.literal_histograms.slice_mut(),
949
12.6M
                        &mut mb.literal_histograms_size,
950
12.6M
                        literal as usize,
951
12.6M
                    ),
952
2.53M
                    &mut LitBlocks::ctx(ref mut lit_blocks_ctx) => {
953
2.53M
                        let context: usize =
954
2.53M
                            Context(prev_byte, prev_byte2, literal_context_mode) as usize;
955
2.53M
                        ContextBlockSplitterAddSymbol(
956
2.53M
                            lit_blocks_ctx,
957
2.53M
                            alloc,
958
2.53M
                            &mut mb.literal_split,
959
2.53M
                            mb.literal_histograms.slice_mut(),
960
2.53M
                            &mut mb.literal_histograms_size,
961
2.53M
                            literal as usize,
962
2.53M
                            static_context_map[(context as usize)] as usize,
963
2.53M
                        );
964
2.53M
                    }
965
                }
966
15.2M
                prev_byte2 = prev_byte;
967
15.2M
                prev_byte = literal;
968
15.2M
                pos = pos.wrapping_add(1);
969
15.2M
            }
970
15.2M
            j = j.wrapping_sub(1);
971
        }
972
1.21M
        pos = pos.wrapping_add(cmd.copy_len() as usize);
973
1.21M
        if cmd.copy_len() != 0 {
974
1.21M
            prev_byte2 = ringbuffer[(pos.wrapping_sub(2) & mask)];
975
1.21M
            prev_byte = ringbuffer[(pos.wrapping_sub(1) & mask)];
976
1.21M
            if cmd.cmd_prefix_ as i32 >= 128i32 {
977
876k
                BlockSplitterAddSymbol(
978
876k
                    &mut dist_blocks,
979
876k
                    &mut mb.distance_split,
980
876k
                    mb.distance_histograms.slice_mut(),
981
876k
                    &mut mb.distance_histograms_size,
982
876k
                    cmd.dist_prefix_ as usize & 0x3ff,
983
876k
                );
984
876k
            }
985
3.06k
        }
986
    }
987
4.87k
    match (&mut lit_blocks) {
988
3.97k
        &mut LitBlocks::plain(ref mut lit_blocks_plain) => BlockSplitterFinishBlock(
989
3.97k
            lit_blocks_plain,
990
3.97k
            &mut mb.literal_split,
991
3.97k
            mb.literal_histograms.slice_mut(),
992
3.97k
            &mut mb.literal_histograms_size,
993
3.97k
            true,
994
3.97k
        ),
995
898
        &mut LitBlocks::ctx(ref mut lit_blocks_ctx) => ContextBlockSplitterFinishBlock(
996
898
            lit_blocks_ctx,
997
898
            alloc,
998
898
            &mut mb.literal_split,
999
898
            mb.literal_histograms.slice_mut(),
1000
898
            &mut mb.literal_histograms_size,
1001
898
            true,
1002
898
        ),
1003
    }
1004
4.87k
    BlockSplitterFinishBlock(
1005
4.87k
        &mut cmd_blocks,
1006
4.87k
        &mut mb.command_split,
1007
4.87k
        mb.command_histograms.slice_mut(),
1008
4.87k
        &mut mb.command_histograms_size,
1009
4.87k
        true,
1010
4.87k
    );
1011
4.87k
    BlockSplitterFinishBlock(
1012
4.87k
        &mut dist_blocks,
1013
4.87k
        &mut mb.distance_split,
1014
4.87k
        mb.distance_histograms.slice_mut(),
1015
4.87k
        &mut mb.distance_histograms_size,
1016
4.87k
        true,
1017
4.87k
    );
1018
4.87k
    if num_contexts > 1 {
1019
898
        MapStaticContexts(alloc, num_contexts, static_context_map, mb);
1020
3.97k
    }
1021
4.87k
}
brotli::enc::metablock::BrotliBuildMetaBlockGreedyInternal::<alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
858
4.87k
pub fn BrotliBuildMetaBlockGreedyInternal<
859
4.87k
    Alloc: alloc::Allocator<u8>
860
4.87k
        + alloc::Allocator<u32>
861
4.87k
        + alloc::Allocator<HistogramLiteral>
862
4.87k
        + alloc::Allocator<HistogramCommand>
863
4.87k
        + alloc::Allocator<HistogramDistance>,
864
4.87k
>(
865
4.87k
    alloc: &mut Alloc,
866
4.87k
    ringbuffer: &[u8],
867
4.87k
    mut pos: usize,
868
4.87k
    mask: usize,
869
4.87k
    mut prev_byte: u8,
870
4.87k
    mut prev_byte2: u8,
871
4.87k
    literal_context_mode: ContextType,
872
4.87k
    num_contexts: usize,
873
4.87k
    static_context_map: &[u32],
874
4.87k
    commands: &[Command],
875
4.87k
    n_commands: usize,
876
4.87k
    mb: &mut MetaBlockSplit<Alloc>,
877
4.87k
) {
878
4.87k
    let mut lit_blocks: LitBlocks;
879
4.87k
    let mut cmd_blocks: BlockSplitter;
880
4.87k
    let mut dist_blocks: BlockSplitter;
881
4.87k
    let mut num_literals: usize = 0usize;
882
1.21M
    for i in 0usize..n_commands {
883
1.21M
        num_literals = num_literals.wrapping_add((commands[i]).insert_len_ as usize);
884
1.21M
    }
885
4.87k
    lit_blocks = if num_contexts == 1 {
886
3.97k
        LitBlocks::plain(InitBlockSplitter::<HistogramLiteral, Alloc>(
887
3.97k
            alloc,
888
3.97k
            256usize,
889
3.97k
            512usize,
890
3.97k
            400.0,
891
3.97k
            num_literals,
892
3.97k
            &mut mb.literal_split,
893
3.97k
            &mut mb.literal_histograms,
894
3.97k
            &mut mb.literal_histograms_size,
895
3.97k
        ))
896
    } else {
897
898
        LitBlocks::ctx(InitContextBlockSplitter::<Alloc>(
898
898
            alloc,
899
898
            256usize,
900
898
            num_contexts,
901
898
            512usize,
902
898
            400.0,
903
898
            num_literals,
904
898
            &mut mb.literal_split,
905
898
            &mut mb.literal_histograms,
906
898
            &mut mb.literal_histograms_size,
907
898
        ))
908
    };
909
4.87k
    cmd_blocks = InitBlockSplitter::<HistogramCommand, Alloc>(
910
4.87k
        alloc,
911
4.87k
        704usize,
912
4.87k
        1024usize,
913
4.87k
        500.0,
914
4.87k
        n_commands,
915
4.87k
        &mut mb.command_split,
916
4.87k
        &mut mb.command_histograms,
917
4.87k
        &mut mb.command_histograms_size,
918
4.87k
    );
919
4.87k
    dist_blocks = InitBlockSplitter::<HistogramDistance, Alloc>(
920
4.87k
        alloc,
921
4.87k
        64usize,
922
4.87k
        512usize,
923
4.87k
        100.0,
924
4.87k
        n_commands,
925
4.87k
        &mut mb.distance_split,
926
4.87k
        &mut mb.distance_histograms,
927
4.87k
        &mut mb.distance_histograms_size,
928
4.87k
    );
929
930
1.21M
    for i in 0usize..n_commands {
931
1.21M
        let cmd: Command = commands[i];
932
1.21M
        let mut j: usize;
933
1.21M
        BlockSplitterAddSymbol(
934
1.21M
            &mut cmd_blocks,
935
1.21M
            &mut mb.command_split,
936
1.21M
            mb.command_histograms.slice_mut(),
937
1.21M
            &mut mb.command_histograms_size,
938
1.21M
            cmd.cmd_prefix_ as usize,
939
1.21M
        );
940
1.21M
        j = cmd.insert_len_ as usize;
941
16.4M
        while j != 0usize {
942
            {
943
15.2M
                let literal: u8 = ringbuffer[(pos & mask)];
944
15.2M
                match (&mut lit_blocks) {
945
12.6M
                    &mut LitBlocks::plain(ref mut lit_blocks_plain) => BlockSplitterAddSymbol(
946
12.6M
                        lit_blocks_plain,
947
12.6M
                        &mut mb.literal_split,
948
12.6M
                        mb.literal_histograms.slice_mut(),
949
12.6M
                        &mut mb.literal_histograms_size,
950
12.6M
                        literal as usize,
951
12.6M
                    ),
952
2.53M
                    &mut LitBlocks::ctx(ref mut lit_blocks_ctx) => {
953
2.53M
                        let context: usize =
954
2.53M
                            Context(prev_byte, prev_byte2, literal_context_mode) as usize;
955
2.53M
                        ContextBlockSplitterAddSymbol(
956
2.53M
                            lit_blocks_ctx,
957
2.53M
                            alloc,
958
2.53M
                            &mut mb.literal_split,
959
2.53M
                            mb.literal_histograms.slice_mut(),
960
2.53M
                            &mut mb.literal_histograms_size,
961
2.53M
                            literal as usize,
962
2.53M
                            static_context_map[(context as usize)] as usize,
963
2.53M
                        );
964
2.53M
                    }
965
                }
966
15.2M
                prev_byte2 = prev_byte;
967
15.2M
                prev_byte = literal;
968
15.2M
                pos = pos.wrapping_add(1);
969
15.2M
            }
970
15.2M
            j = j.wrapping_sub(1);
971
        }
972
1.21M
        pos = pos.wrapping_add(cmd.copy_len() as usize);
973
1.21M
        if cmd.copy_len() != 0 {
974
1.21M
            prev_byte2 = ringbuffer[(pos.wrapping_sub(2) & mask)];
975
1.21M
            prev_byte = ringbuffer[(pos.wrapping_sub(1) & mask)];
976
1.21M
            if cmd.cmd_prefix_ as i32 >= 128i32 {
977
876k
                BlockSplitterAddSymbol(
978
876k
                    &mut dist_blocks,
979
876k
                    &mut mb.distance_split,
980
876k
                    mb.distance_histograms.slice_mut(),
981
876k
                    &mut mb.distance_histograms_size,
982
876k
                    cmd.dist_prefix_ as usize & 0x3ff,
983
876k
                );
984
876k
            }
985
3.06k
        }
986
    }
987
4.87k
    match (&mut lit_blocks) {
988
3.97k
        &mut LitBlocks::plain(ref mut lit_blocks_plain) => BlockSplitterFinishBlock(
989
3.97k
            lit_blocks_plain,
990
3.97k
            &mut mb.literal_split,
991
3.97k
            mb.literal_histograms.slice_mut(),
992
3.97k
            &mut mb.literal_histograms_size,
993
3.97k
            true,
994
3.97k
        ),
995
898
        &mut LitBlocks::ctx(ref mut lit_blocks_ctx) => ContextBlockSplitterFinishBlock(
996
898
            lit_blocks_ctx,
997
898
            alloc,
998
898
            &mut mb.literal_split,
999
898
            mb.literal_histograms.slice_mut(),
1000
898
            &mut mb.literal_histograms_size,
1001
898
            true,
1002
898
        ),
1003
    }
1004
4.87k
    BlockSplitterFinishBlock(
1005
4.87k
        &mut cmd_blocks,
1006
4.87k
        &mut mb.command_split,
1007
4.87k
        mb.command_histograms.slice_mut(),
1008
4.87k
        &mut mb.command_histograms_size,
1009
4.87k
        true,
1010
4.87k
    );
1011
4.87k
    BlockSplitterFinishBlock(
1012
4.87k
        &mut dist_blocks,
1013
4.87k
        &mut mb.distance_split,
1014
4.87k
        mb.distance_histograms.slice_mut(),
1015
4.87k
        &mut mb.distance_histograms_size,
1016
4.87k
        true,
1017
4.87k
    );
1018
4.87k
    if num_contexts > 1 {
1019
898
        MapStaticContexts(alloc, num_contexts, static_context_map, mb);
1020
3.97k
    }
1021
4.87k
}
Unexecuted instantiation: brotli::enc::metablock::BrotliBuildMetaBlockGreedyInternal::<_>
1022
4.87k
pub fn BrotliBuildMetaBlockGreedy<
1023
4.87k
    Alloc: alloc::Allocator<u8>
1024
4.87k
        + alloc::Allocator<u32>
1025
4.87k
        + alloc::Allocator<HistogramLiteral>
1026
4.87k
        + alloc::Allocator<HistogramCommand>
1027
4.87k
        + alloc::Allocator<HistogramDistance>,
1028
4.87k
>(
1029
4.87k
    alloc: &mut Alloc,
1030
4.87k
    ringbuffer: &[u8],
1031
4.87k
    pos: usize,
1032
4.87k
    mask: usize,
1033
4.87k
    prev_byte: u8,
1034
4.87k
    prev_byte2: u8,
1035
4.87k
    literal_context_mode: ContextType,
1036
4.87k
    _literal_context_lut: &[u8],
1037
4.87k
    num_contexts: usize,
1038
4.87k
    static_context_map: &[u32],
1039
4.87k
    commands: &[Command],
1040
4.87k
    n_commands: usize,
1041
4.87k
    mb: &mut MetaBlockSplit<Alloc>,
1042
4.87k
) {
1043
4.87k
    if num_contexts == 1 {
1044
3.97k
        BrotliBuildMetaBlockGreedyInternal(
1045
3.97k
            alloc,
1046
3.97k
            ringbuffer,
1047
3.97k
            pos,
1048
3.97k
            mask,
1049
3.97k
            prev_byte,
1050
3.97k
            prev_byte2,
1051
3.97k
            literal_context_mode,
1052
3.97k
            1,
1053
3.97k
            &[],
1054
3.97k
            commands,
1055
3.97k
            n_commands,
1056
3.97k
            mb,
1057
3.97k
        );
1058
3.97k
    } else {
1059
898
        BrotliBuildMetaBlockGreedyInternal(
1060
898
            alloc,
1061
898
            ringbuffer,
1062
898
            pos,
1063
898
            mask,
1064
898
            prev_byte,
1065
898
            prev_byte2,
1066
898
            literal_context_mode,
1067
898
            num_contexts,
1068
898
            static_context_map,
1069
898
            commands,
1070
898
            n_commands,
1071
898
            mb,
1072
898
        );
1073
898
    }
1074
4.87k
}
brotli::enc::metablock::BrotliBuildMetaBlockGreedy::<alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
1022
4.87k
pub fn BrotliBuildMetaBlockGreedy<
1023
4.87k
    Alloc: alloc::Allocator<u8>
1024
4.87k
        + alloc::Allocator<u32>
1025
4.87k
        + alloc::Allocator<HistogramLiteral>
1026
4.87k
        + alloc::Allocator<HistogramCommand>
1027
4.87k
        + alloc::Allocator<HistogramDistance>,
1028
4.87k
>(
1029
4.87k
    alloc: &mut Alloc,
1030
4.87k
    ringbuffer: &[u8],
1031
4.87k
    pos: usize,
1032
4.87k
    mask: usize,
1033
4.87k
    prev_byte: u8,
1034
4.87k
    prev_byte2: u8,
1035
4.87k
    literal_context_mode: ContextType,
1036
4.87k
    _literal_context_lut: &[u8],
1037
4.87k
    num_contexts: usize,
1038
4.87k
    static_context_map: &[u32],
1039
4.87k
    commands: &[Command],
1040
4.87k
    n_commands: usize,
1041
4.87k
    mb: &mut MetaBlockSplit<Alloc>,
1042
4.87k
) {
1043
4.87k
    if num_contexts == 1 {
1044
3.97k
        BrotliBuildMetaBlockGreedyInternal(
1045
3.97k
            alloc,
1046
3.97k
            ringbuffer,
1047
3.97k
            pos,
1048
3.97k
            mask,
1049
3.97k
            prev_byte,
1050
3.97k
            prev_byte2,
1051
3.97k
            literal_context_mode,
1052
3.97k
            1,
1053
3.97k
            &[],
1054
3.97k
            commands,
1055
3.97k
            n_commands,
1056
3.97k
            mb,
1057
3.97k
        );
1058
3.97k
    } else {
1059
898
        BrotliBuildMetaBlockGreedyInternal(
1060
898
            alloc,
1061
898
            ringbuffer,
1062
898
            pos,
1063
898
            mask,
1064
898
            prev_byte,
1065
898
            prev_byte2,
1066
898
            literal_context_mode,
1067
898
            num_contexts,
1068
898
            static_context_map,
1069
898
            commands,
1070
898
            n_commands,
1071
898
            mb,
1072
898
        );
1073
898
    }
1074
4.87k
}
Unexecuted instantiation: brotli::enc::metablock::BrotliBuildMetaBlockGreedy::<_>
1075
1076
11.5k
pub fn BrotliOptimizeHistograms<
1077
11.5k
    Alloc: alloc::Allocator<u8>
1078
11.5k
        + alloc::Allocator<u32>
1079
11.5k
        + alloc::Allocator<HistogramLiteral>
1080
11.5k
        + alloc::Allocator<HistogramCommand>
1081
11.5k
        + alloc::Allocator<HistogramDistance>,
1082
11.5k
>(
1083
11.5k
    num_distance_codes: usize,
1084
11.5k
    mb: &mut MetaBlockSplit<Alloc>,
1085
11.5k
) {
1086
11.5k
    let mut good_for_rle: [u8; 704] = [0; 704];
1087
141k
    for i in 0usize..mb.literal_histograms_size {
1088
141k
        BrotliOptimizeHuffmanCountsForRle(
1089
141k
            256usize,
1090
141k
            mb.literal_histograms.slice_mut()[i].slice_mut(),
1091
141k
            &mut good_for_rle[..],
1092
141k
        );
1093
141k
    }
1094
14.2k
    for i in 0usize..mb.command_histograms_size {
1095
14.2k
        BrotliOptimizeHuffmanCountsForRle(
1096
14.2k
            704usize,
1097
14.2k
            mb.command_histograms.slice_mut()[i].slice_mut(),
1098
14.2k
            &mut good_for_rle[..],
1099
14.2k
        );
1100
14.2k
    }
1101
15.7k
    for i in 0usize..mb.distance_histograms_size {
1102
15.7k
        BrotliOptimizeHuffmanCountsForRle(
1103
15.7k
            num_distance_codes,
1104
15.7k
            mb.distance_histograms.slice_mut()[i].slice_mut(),
1105
15.7k
            &mut good_for_rle[..],
1106
15.7k
        );
1107
15.7k
    }
1108
11.5k
}
brotli::enc::metablock::BrotliOptimizeHistograms::<alloc_stdlib::std_alloc::StandardAlloc>
Line
Count
Source
1076
11.5k
pub fn BrotliOptimizeHistograms<
1077
11.5k
    Alloc: alloc::Allocator<u8>
1078
11.5k
        + alloc::Allocator<u32>
1079
11.5k
        + alloc::Allocator<HistogramLiteral>
1080
11.5k
        + alloc::Allocator<HistogramCommand>
1081
11.5k
        + alloc::Allocator<HistogramDistance>,
1082
11.5k
>(
1083
11.5k
    num_distance_codes: usize,
1084
11.5k
    mb: &mut MetaBlockSplit<Alloc>,
1085
11.5k
) {
1086
11.5k
    let mut good_for_rle: [u8; 704] = [0; 704];
1087
141k
    for i in 0usize..mb.literal_histograms_size {
1088
141k
        BrotliOptimizeHuffmanCountsForRle(
1089
141k
            256usize,
1090
141k
            mb.literal_histograms.slice_mut()[i].slice_mut(),
1091
141k
            &mut good_for_rle[..],
1092
141k
        );
1093
141k
    }
1094
14.2k
    for i in 0usize..mb.command_histograms_size {
1095
14.2k
        BrotliOptimizeHuffmanCountsForRle(
1096
14.2k
            704usize,
1097
14.2k
            mb.command_histograms.slice_mut()[i].slice_mut(),
1098
14.2k
            &mut good_for_rle[..],
1099
14.2k
        );
1100
14.2k
    }
1101
15.7k
    for i in 0usize..mb.distance_histograms_size {
1102
15.7k
        BrotliOptimizeHuffmanCountsForRle(
1103
15.7k
            num_distance_codes,
1104
15.7k
            mb.distance_histograms.slice_mut()[i].slice_mut(),
1105
15.7k
            &mut good_for_rle[..],
1106
15.7k
        );
1107
15.7k
    }
1108
11.5k
}
Unexecuted instantiation: brotli::enc::metablock::BrotliOptimizeHistograms::<_>