/rust/registry/src/index.crates.io-1949cf8c6b5b557f/brotli-decompressor-5.0.0/src/decode.rs
Line | Count | Source |
1 | | #![allow(non_snake_case)] |
2 | | #![allow(unused_parens)] |
3 | | #![allow(non_camel_case_types)] |
4 | | #![allow(non_snake_case)] |
5 | | #![allow(non_upper_case_globals)] |
6 | | #![allow(unused_macros)] |
7 | | |
8 | | // #[macro_use] //<- for debugging, remove xprintln from bit_reader and replace with println |
9 | | // extern crate std; |
10 | | use core; |
11 | | use super::alloc; |
12 | | pub use alloc::{AllocatedStackMemory, Allocator, SliceWrapper, SliceWrapperMut, StackAllocator}; |
13 | | |
14 | | use core::mem; |
15 | | |
16 | | use super::bit_reader; |
17 | | use super::huffman; |
18 | | use super::state; |
19 | | use super::prefix; |
20 | | |
21 | | use super::transform::{TransformDictionaryWord, kNumTransforms}; |
22 | | use state::{BlockTypeAndLengthState, BrotliRunningContextMapState, BrotliRunningDecodeUint8State, |
23 | | BrotliRunningHuffmanState, BrotliRunningMetablockHeaderState, |
24 | | BrotliRunningReadBlockLengthState, BrotliRunningState, BrotliRunningTreeGroupState, |
25 | | BrotliRunningUncompressedState, kLiteralContextBits, |
26 | | BrotliDecoderErrorCode, |
27 | | }; |
28 | | use context::{kContextLookup}; |
29 | | use ::dictionary::{kBrotliDictionary, kBrotliDictionaryOffsetsByLength, |
30 | | kBrotliDictionarySizeBitsByLength, kBrotliMaxDictionaryWordLength, |
31 | | kBrotliMinDictionaryWordLength}; |
32 | | pub use huffman::{HuffmanCode, HuffmanTreeGroup}; |
33 | | #[repr(C)] |
34 | | #[derive(Debug)] |
35 | | pub enum BrotliResult { |
36 | | ResultSuccess = 1, |
37 | | NeedsMoreInput = 2, |
38 | | NeedsMoreOutput = 3, |
39 | | ResultFailure = 0, |
40 | | } |
41 | | const kBrotliWindowGap: u32 = 16; |
42 | | const kBrotliLargeMinWbits: u32 = 10; |
43 | | const kBrotliLargeMaxWbits: u32 = 30; |
44 | | const kBrotliMaxPostfix: usize = 3; |
45 | | const kBrotliMaxAllowedDistance: u32 = 0x7FFFFFFC; |
46 | | const kDefaultCodeLength: u32 = 8; |
47 | | const kCodeLengthRepeatCode: u32 = 16; |
48 | | pub const kNumLiteralCodes: u16 = 256; |
49 | | pub const kNumInsertAndCopyCodes: u16 = 704; |
50 | | pub const kNumBlockLengthCodes: u32 = 26; |
51 | | const kDistanceContextBits: i32 = 2; |
52 | | const HUFFMAN_TABLE_BITS: u32 = 8; |
53 | | const HUFFMAN_TABLE_MASK: u32 = 0xff; |
54 | | const CODE_LENGTH_CODES: usize = 18; |
55 | | const kCodeLengthCodeOrder: [u8; CODE_LENGTH_CODES] = [1, 2, 3, 4, 0, 5, 17, 6, 16, 7, 8, 9, 10, |
56 | | 11, 12, 13, 14, 15]; |
57 | | |
58 | | // Static prefix code for the complex code length code lengths. |
59 | | const kCodeLengthPrefixLength: [u8; 16] = [2, 2, 2, 3, 2, 2, 2, 4, 2, 2, 2, 3, 2, 2, 2, 4]; |
60 | | |
61 | | const kCodeLengthPrefixValue: [u8; 16] = [0, 4, 3, 2, 0, 4, 3, 1, 0, 4, 3, 2, 0, 4, 3, 5]; |
62 | | |
63 | | |
64 | | macro_rules! BROTLI_LOG_UINT ( |
65 | | ($num : expr) => { |
66 | | xprintln!("{:?} = {:?}", stringify!($num), $num) |
67 | | }; |
68 | | ); |
69 | | |
70 | | macro_rules! BROTLI_LOG ( |
71 | | ($str : expr, $num : expr) => {xprintln!("{:?} {:?}", $str, $num);}; |
72 | | ($str : expr, $num0 : expr, $num1 : expr) => {xprintln!("{:?} {:?} {:?}", $str, $num0, $num1);}; |
73 | | ($str : expr, $num0 : expr, $num1 : expr, $num2 : expr) => { |
74 | | xprintln!("{:?} {:?} {:?} {:?}", $str, $num0, $num1, $num2); |
75 | | }; |
76 | | ($str : expr, $num0 : expr, $num1 : expr, $num2 : expr, $num3 : expr) => { |
77 | | xprintln!("{:?} {:?} {:?} {:?} {:?}", $str, $num0, $num1, $num2, $num3); |
78 | | }; |
79 | | ); |
80 | 4.05M | fn is_fatal(e: BrotliDecoderErrorCode) -> bool { |
81 | 4.05M | (e as i64) < 0 |
82 | 4.05M | } |
83 | 2.53M | fn assign_error_code(output: &mut BrotliDecoderErrorCode, input: BrotliDecoderErrorCode) -> BrotliDecoderErrorCode { |
84 | 2.53M | *output = input; |
85 | 2.53M | input |
86 | 2.53M | } |
87 | | |
88 | | #[allow(non_snake_case)] |
89 | | macro_rules! SaveErrorCode { |
90 | | ($state: expr, $e:expr) => { |
91 | | match assign_error_code(&mut $state.error_code, $e) { |
92 | | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => |
93 | | BrotliResult::ResultSuccess, |
94 | | BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT => |
95 | | BrotliResult::NeedsMoreInput, |
96 | | BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_OUTPUT => |
97 | | BrotliResult::NeedsMoreOutput, |
98 | | _ => |
99 | | BrotliResult::ResultFailure, |
100 | | } |
101 | | } |
102 | | } |
103 | | macro_rules! SaveResult { |
104 | | ($state: expr, $e:expr) => { |
105 | | match ($state.error_code = match $e { |
106 | | BrotliResult::ResultSuccess => BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS, |
107 | | BrotliResult::NeedsMoreInput => BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT, |
108 | | BrotliResult::NeedsMoreOutput => BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_OUTPUT, |
109 | | BrotliResult::ResultFailure => BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE, |
110 | | }) { |
111 | | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => |
112 | | BrotliResult::ResultSuccess, |
113 | | BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT => |
114 | | BrotliResult::NeedsMoreInput, |
115 | | BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_OUTPUT => |
116 | | BrotliResult::NeedsMoreOutput, |
117 | | _ => |
118 | | BrotliResult::ResultFailure, |
119 | | } |
120 | | } |
121 | | } |
122 | | macro_rules! BROTLI_LOG_ARRAY_INDEX ( |
123 | | ($array : expr, $index : expr) => { |
124 | | xprintln!("{:?}[{:?}] = {:?}", stringify!($array), $index, $array[$index as usize]) |
125 | | }; |
126 | | ); |
127 | | |
128 | | |
129 | | const NUM_DISTANCE_SHORT_CODES: u32 = 16; |
130 | | pub const BROTLI_MAX_DISTANCE_BITS:u32 = 24; |
131 | | |
132 | | pub const BROTLI_LARGE_MAX_DISTANCE_BITS: u32 = 62; |
133 | | |
134 | 150k | pub fn BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX: u32, NDIRECT:u32, MAXNBITS: u32) -> u32 { |
135 | 150k | NUM_DISTANCE_SHORT_CODES + (NDIRECT) + |
136 | 150k | ((MAXNBITS) << ((NPOSTFIX) + 1)) |
137 | 150k | } |
138 | | |
139 | | // pub struct BrotliState { |
140 | | // total_written : usize, |
141 | | // } |
142 | | // |
143 | | pub use state::BrotliState; |
144 | | // impl BrotliState { |
145 | | // pub fn new() -> BrotliState { |
146 | | // return BrotliState {total_written: 0 }; |
147 | | // } |
148 | | // } |
149 | | |
150 | | /* Decodes WBITS by reading 1 - 7 bits, or 0x11 for "Large Window Brotli". |
151 | | Precondition: bit-reader accumulator has at least 8 bits. */ |
152 | 113k | fn DecodeWindowBits(s_large_window: &mut bool, |
153 | 113k | s_window_bits:&mut u32, |
154 | 113k | br: &mut bit_reader::BrotliBitReader) -> BrotliDecoderErrorCode { |
155 | 113k | let mut n: u32 = 0; |
156 | 113k | let large_window = *s_large_window; |
157 | 113k | *s_large_window = false; |
158 | 113k | bit_reader::BrotliTakeBits(br, 1, &mut n); |
159 | 113k | if (n == 0) { |
160 | 39.2k | *s_window_bits = 16; |
161 | 39.2k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
162 | 74.5k | } |
163 | 74.5k | bit_reader::BrotliTakeBits(br, 3, &mut n); |
164 | 74.5k | if (n != 0) { |
165 | 58.8k | *s_window_bits = 17 + n; |
166 | 58.8k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
167 | 15.7k | } |
168 | 15.7k | bit_reader::BrotliTakeBits(br, 3, &mut n); |
169 | 15.7k | if (n == 1) { |
170 | 5.39k | if (large_window) { |
171 | 5.39k | bit_reader::BrotliTakeBits(br, 1, &mut n); |
172 | 5.39k | if (n == 1) { |
173 | 604 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; |
174 | 4.79k | } |
175 | 4.79k | *s_large_window = true; |
176 | 4.79k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
177 | | } else { |
178 | 0 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; |
179 | | } |
180 | 10.3k | } |
181 | 10.3k | if (n != 0) { |
182 | 4.33k | *s_window_bits = 8 + n; |
183 | 4.33k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
184 | 6.01k | } |
185 | 6.01k | *s_window_bits = 17; |
186 | 6.01k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
187 | 113k | } |
188 | | |
189 | | |
190 | | #[cold] |
191 | 166M | fn mark_unlikely() {} |
192 | | |
193 | 511k | fn DecodeVarLenUint8(substate_decode_uint8: &mut state::BrotliRunningDecodeUint8State, |
194 | 511k | mut br: &mut bit_reader::BrotliBitReader, |
195 | 511k | value: &mut u32, |
196 | 511k | input: &[u8]) |
197 | 511k | -> BrotliDecoderErrorCode { |
198 | 511k | let mut bits: u32 = 0; |
199 | | loop { |
200 | 675k | match *substate_decode_uint8 { |
201 | | BrotliRunningDecodeUint8State::BROTLI_STATE_DECODE_UINT8_NONE => { |
202 | 465k | if !bit_reader::BrotliSafeReadBits(&mut br, 1, &mut bits, input) { |
203 | 25.5k | mark_unlikely(); |
204 | 25.5k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
205 | 439k | } |
206 | 439k | if (bits == 0) { |
207 | 350k | *value = 0; |
208 | 350k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
209 | 88.8k | } |
210 | 88.8k | *substate_decode_uint8 = BrotliRunningDecodeUint8State::BROTLI_STATE_DECODE_UINT8_SHORT; |
211 | | // No break, transit to the next state. |
212 | | } |
213 | | BrotliRunningDecodeUint8State::BROTLI_STATE_DECODE_UINT8_SHORT => { |
214 | 109k | if !bit_reader::BrotliSafeReadBits(&mut br, 3, &mut bits, input) { |
215 | 21.0k | mark_unlikely(); |
216 | 21.0k | *substate_decode_uint8 = BrotliRunningDecodeUint8State::BROTLI_STATE_DECODE_UINT8_SHORT; |
217 | 21.0k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
218 | 88.8k | } |
219 | 88.8k | if (bits == 0) { |
220 | 13.4k | *value = 1; |
221 | 13.4k | *substate_decode_uint8 = BrotliRunningDecodeUint8State::BROTLI_STATE_DECODE_UINT8_NONE; |
222 | 13.4k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
223 | 75.3k | } |
224 | | // Use output value as a temporary storage. It MUST be persisted. |
225 | 75.3k | *value = bits; |
226 | | // No break, transit to the next state. |
227 | 75.3k | *substate_decode_uint8 = BrotliRunningDecodeUint8State::BROTLI_STATE_DECODE_UINT8_LONG; |
228 | | } |
229 | | BrotliRunningDecodeUint8State::BROTLI_STATE_DECODE_UINT8_LONG => { |
230 | 100k | if !bit_reader::BrotliSafeReadBits(&mut br, *value, &mut bits, input) { |
231 | 26.5k | mark_unlikely(); |
232 | 26.5k | *substate_decode_uint8 = BrotliRunningDecodeUint8State::BROTLI_STATE_DECODE_UINT8_LONG; |
233 | 26.5k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
234 | 73.6k | } |
235 | 73.6k | *value = (1u32 << *value) + bits; |
236 | 73.6k | *substate_decode_uint8 = BrotliRunningDecodeUint8State::BROTLI_STATE_DECODE_UINT8_NONE; |
237 | 73.6k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
238 | | } |
239 | | } |
240 | | } |
241 | 511k | } |
242 | | |
243 | 433k | fn DecodeMetaBlockLength<AllocU8: alloc::Allocator<u8>, |
244 | 433k | AllocU32: alloc::Allocator<u32>, |
245 | 433k | AllocHC: alloc::Allocator<HuffmanCode>> |
246 | 433k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
247 | 433k | input: &[u8]) |
248 | 433k | -> BrotliDecoderErrorCode { |
249 | 433k | let mut bits: u32 = 0; |
250 | | loop { |
251 | 878k | match s.substate_metablock_header { |
252 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE => { |
253 | 226k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { |
254 | 92.7k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
255 | 133k | } |
256 | 133k | s.is_last_metablock = bits as u8; |
257 | 133k | s.meta_block_remaining_len = 0; |
258 | 133k | s.is_uncompressed = 0; |
259 | 133k | s.is_metadata = 0; |
260 | 133k | if (s.is_last_metablock == 0) { |
261 | 89.9k | s.substate_metablock_header = |
262 | 89.9k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES; |
263 | 89.9k | continue; |
264 | 43.5k | } |
265 | 43.5k | s.substate_metablock_header = |
266 | 43.5k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_EMPTY; |
267 | | // No break, transit to the next state. |
268 | | } |
269 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_EMPTY => { |
270 | 63.9k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { |
271 | 20.5k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
272 | 43.3k | } |
273 | 43.3k | if bits != 0 { |
274 | 4.03k | s.substate_metablock_header = |
275 | 4.03k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; |
276 | 4.03k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
277 | 39.3k | } |
278 | 39.3k | s.substate_metablock_header = |
279 | 39.3k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES; |
280 | | // No break, transit to the next state. |
281 | | } |
282 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES => { |
283 | 145k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input) { |
284 | 17.0k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
285 | 128k | } |
286 | 128k | s.size_nibbles = (bits + 4) as u8; |
287 | 128k | s.loop_counter = 0; |
288 | 128k | if (bits == 3) { |
289 | 17.3k | s.is_metadata = 1; |
290 | 17.3k | s.substate_metablock_header = |
291 | 17.3k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_RESERVED; |
292 | 17.3k | continue; |
293 | 111k | } |
294 | 111k | s.substate_metablock_header = |
295 | 111k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_SIZE; |
296 | | // No break, transit to the next state. |
297 | | |
298 | | } |
299 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_SIZE => { |
300 | 237k | let mut i = s.loop_counter; |
301 | 748k | while i < s.size_nibbles as i32 { |
302 | 640k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 4, &mut bits, input) { |
303 | 128k | s.loop_counter = i; |
304 | 128k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
305 | 512k | } |
306 | 512k | if (i + 1 == s.size_nibbles as i32 && s.size_nibbles > 4 && bits == 0) { |
307 | 1.46k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE; |
308 | 511k | } |
309 | 511k | s.meta_block_remaining_len |= (bits << (i * 4)) as i32; |
310 | 511k | i += 1; |
311 | | } |
312 | 107k | s.substate_metablock_header = |
313 | 107k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED; |
314 | | // No break, transit to the next state. |
315 | | } |
316 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED => { |
317 | 127k | if (s.is_last_metablock == 0 && s.is_metadata == 0) { |
318 | 83.8k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { |
319 | 11.2k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
320 | 72.6k | } |
321 | 72.6k | s.is_uncompressed = bits as u8; |
322 | 43.8k | } |
323 | 116k | s.meta_block_remaining_len += 1; |
324 | 116k | s.substate_metablock_header = |
325 | 116k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; |
326 | 116k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
327 | | } |
328 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_RESERVED => { |
329 | 30.5k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { |
330 | 13.1k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
331 | 17.3k | } |
332 | 17.3k | if (bits != 0) { |
333 | 1.23k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_RESERVED; |
334 | 16.0k | } |
335 | 16.0k | s.substate_metablock_header = |
336 | 16.0k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_BYTES; |
337 | | // No break, transit to the next state. |
338 | | } |
339 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_BYTES => { |
340 | 27.1k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input) { |
341 | 11.1k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
342 | 16.0k | } |
343 | 16.0k | if (bits == 0) { |
344 | 5.16k | s.substate_metablock_header = |
345 | 5.16k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; |
346 | 5.16k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
347 | 10.8k | } |
348 | 10.8k | s.size_nibbles = bits as u8; |
349 | 10.8k | s.substate_metablock_header = |
350 | 10.8k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_METADATA; |
351 | | // No break, transit to the next state. |
352 | | } |
353 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_METADATA => { |
354 | 19.9k | let mut i = s.loop_counter; |
355 | 36.2k | while i < s.size_nibbles as i32 { |
356 | 27.5k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 8, &mut bits, input) { |
357 | 9.28k | s.loop_counter = i; |
358 | 9.28k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
359 | 18.2k | } |
360 | 18.2k | if (i + 1 == s.size_nibbles as i32 && s.size_nibbles > 1 && bits == 0) { |
361 | 2.00k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE; |
362 | 16.2k | } |
363 | 16.2k | s.meta_block_remaining_len |= (bits << (i * 8)) as i32; |
364 | 16.2k | i += 1; |
365 | | } |
366 | 8.68k | s.substate_metablock_header = |
367 | 8.68k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED; |
368 | 8.68k | continue; |
369 | | } |
370 | | } |
371 | | } |
372 | 433k | } brotli_decompressor::decode::DecodeMetaBlockLength::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 243 | 347k | fn DecodeMetaBlockLength<AllocU8: alloc::Allocator<u8>, | 244 | 347k | AllocU32: alloc::Allocator<u32>, | 245 | 347k | AllocHC: alloc::Allocator<HuffmanCode>> | 246 | 347k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 247 | 347k | input: &[u8]) | 248 | 347k | -> BrotliDecoderErrorCode { | 249 | 347k | let mut bits: u32 = 0; | 250 | | loop { | 251 | 597k | match s.substate_metablock_header { | 252 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE => { | 253 | 151k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 254 | 79.8k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 255 | 71.8k | } | 256 | 71.8k | s.is_last_metablock = bits as u8; | 257 | 71.8k | s.meta_block_remaining_len = 0; | 258 | 71.8k | s.is_uncompressed = 0; | 259 | 71.8k | s.is_metadata = 0; | 260 | 71.8k | if (s.is_last_metablock == 0) { | 261 | 41.2k | s.substate_metablock_header = | 262 | 41.2k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES; | 263 | 41.2k | continue; | 264 | 30.6k | } | 265 | 30.6k | s.substate_metablock_header = | 266 | 30.6k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_EMPTY; | 267 | | // No break, transit to the next state. | 268 | | } | 269 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_EMPTY => { | 270 | 48.4k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 271 | 18.0k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 272 | 30.4k | } | 273 | 30.4k | if bits != 0 { | 274 | 1.39k | s.substate_metablock_header = | 275 | 1.39k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; | 276 | 1.39k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 277 | 29.0k | } | 278 | 29.0k | s.substate_metablock_header = | 279 | 29.0k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES; | 280 | | // No break, transit to the next state. | 281 | | } | 282 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES => { | 283 | 86.1k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input) { | 284 | 15.9k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 285 | 70.1k | } | 286 | 70.1k | s.size_nibbles = (bits + 4) as u8; | 287 | 70.1k | s.loop_counter = 0; | 288 | 70.1k | if (bits == 3) { | 289 | 8.78k | s.is_metadata = 1; | 290 | 8.78k | s.substate_metablock_header = | 291 | 8.78k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_RESERVED; | 292 | 8.78k | continue; | 293 | 61.4k | } | 294 | 61.4k | s.substate_metablock_header = | 295 | 61.4k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_SIZE; | 296 | | // No break, transit to the next state. | 297 | | | 298 | | } | 299 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_SIZE => { | 300 | 182k | let mut i = s.loop_counter; | 301 | 464k | while i < s.size_nibbles as i32 { | 302 | 404k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 4, &mut bits, input) { | 303 | 122k | s.loop_counter = i; | 304 | 122k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 305 | 282k | } | 306 | 282k | if (i + 1 == s.size_nibbles as i32 && s.size_nibbles > 4 && bits == 0) { | 307 | 696 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE; | 308 | 281k | } | 309 | 281k | s.meta_block_remaining_len |= (bits << (i * 4)) as i32; | 310 | 281k | i += 1; | 311 | | } | 312 | 59.4k | s.substate_metablock_header = | 313 | 59.4k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED; | 314 | | // No break, transit to the next state. | 315 | | } | 316 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED => { | 317 | 75.4k | if (s.is_last_metablock == 0 && s.is_metadata == 0) { | 318 | 43.3k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 319 | 10.9k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 320 | 32.3k | } | 321 | 32.3k | s.is_uncompressed = bits as u8; | 322 | 32.0k | } | 323 | 64.4k | s.meta_block_remaining_len += 1; | 324 | 64.4k | s.substate_metablock_header = | 325 | 64.4k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; | 326 | 64.4k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 327 | | } | 328 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_RESERVED => { | 329 | 19.3k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 330 | 10.5k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 331 | 8.77k | } | 332 | 8.77k | if (bits != 0) { | 333 | 469 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_RESERVED; | 334 | 8.30k | } | 335 | 8.30k | s.substate_metablock_header = | 336 | 8.30k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_BYTES; | 337 | | // No break, transit to the next state. | 338 | | } | 339 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_BYTES => { | 340 | 18.8k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input) { | 341 | 10.5k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 342 | 8.28k | } | 343 | 8.28k | if (bits == 0) { | 344 | 2.02k | s.substate_metablock_header = | 345 | 2.02k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; | 346 | 2.02k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 347 | 6.25k | } | 348 | 6.25k | s.size_nibbles = bits as u8; | 349 | 6.25k | s.substate_metablock_header = | 350 | 6.25k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_METADATA; | 351 | | // No break, transit to the next state. | 352 | | } | 353 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_METADATA => { | 354 | 14.8k | let mut i = s.loop_counter; | 355 | 24.2k | while i < s.size_nibbles as i32 { | 356 | 19.2k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 8, &mut bits, input) { | 357 | 8.62k | s.loop_counter = i; | 358 | 8.62k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 359 | 10.5k | } | 360 | 10.5k | if (i + 1 == s.size_nibbles as i32 && s.size_nibbles > 1 && bits == 0) { | 361 | 1.18k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE; | 362 | 9.41k | } | 363 | 9.41k | s.meta_block_remaining_len |= (bits << (i * 8)) as i32; | 364 | 9.41k | i += 1; | 365 | | } | 366 | 5.00k | s.substate_metablock_header = | 367 | 5.00k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED; | 368 | 5.00k | continue; | 369 | | } | 370 | | } | 371 | | } | 372 | 347k | } |
Unexecuted instantiation: brotli_decompressor::decode::DecodeMetaBlockLength::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::DecodeMetaBlockLength::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::DecodeMetaBlockLength::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 243 | 34.8k | fn DecodeMetaBlockLength<AllocU8: alloc::Allocator<u8>, | 244 | 34.8k | AllocU32: alloc::Allocator<u32>, | 245 | 34.8k | AllocHC: alloc::Allocator<HuffmanCode>> | 246 | 34.8k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 247 | 34.8k | input: &[u8]) | 248 | 34.8k | -> BrotliDecoderErrorCode { | 249 | 34.8k | let mut bits: u32 = 0; | 250 | | loop { | 251 | 131k | match s.substate_metablock_header { | 252 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE => { | 253 | 31.3k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 254 | 180 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 255 | 31.1k | } | 256 | 31.1k | s.is_last_metablock = bits as u8; | 257 | 31.1k | s.meta_block_remaining_len = 0; | 258 | 31.1k | s.is_uncompressed = 0; | 259 | 31.1k | s.is_metadata = 0; | 260 | 31.1k | if (s.is_last_metablock == 0) { | 261 | 24.6k | s.substate_metablock_header = | 262 | 24.6k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES; | 263 | 24.6k | continue; | 264 | 6.49k | } | 265 | 6.49k | s.substate_metablock_header = | 266 | 6.49k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_EMPTY; | 267 | | // No break, transit to the next state. | 268 | | } | 269 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_EMPTY => { | 270 | 6.49k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 271 | 8 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 272 | 6.49k | } | 273 | 6.49k | if bits != 0 { | 274 | 1.54k | s.substate_metablock_header = | 275 | 1.54k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; | 276 | 1.54k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 277 | 4.94k | } | 278 | 4.94k | s.substate_metablock_header = | 279 | 4.94k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES; | 280 | | // No break, transit to the next state. | 281 | | } | 282 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES => { | 283 | 29.8k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input) { | 284 | 467 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 285 | 29.3k | } | 286 | 29.3k | s.size_nibbles = (bits + 4) as u8; | 287 | 29.3k | s.loop_counter = 0; | 288 | 29.3k | if (bits == 3) { | 289 | 3.33k | s.is_metadata = 1; | 290 | 3.33k | s.substate_metablock_header = | 291 | 3.33k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_RESERVED; | 292 | 3.33k | continue; | 293 | 26.0k | } | 294 | 26.0k | s.substate_metablock_header = | 295 | 26.0k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_SIZE; | 296 | | // No break, transit to the next state. | 297 | | | 298 | | } | 299 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_SIZE => { | 300 | 29.0k | let mut i = s.loop_counter; | 301 | 147k | while i < s.size_nibbles as i32 { | 302 | 122k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 4, &mut bits, input) { | 303 | 3.15k | s.loop_counter = i; | 304 | 3.15k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 305 | 118k | } | 306 | 118k | if (i + 1 == s.size_nibbles as i32 && s.size_nibbles > 4 && bits == 0) { | 307 | 522 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE; | 308 | 118k | } | 309 | 118k | s.meta_block_remaining_len |= (bits << (i * 4)) as i32; | 310 | 118k | i += 1; | 311 | | } | 312 | 25.3k | s.substate_metablock_header = | 313 | 25.3k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED; | 314 | | // No break, transit to the next state. | 315 | | } | 316 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED => { | 317 | 26.7k | if (s.is_last_metablock == 0 && s.is_metadata == 0) { | 318 | 20.8k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 319 | 71 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 320 | 20.8k | } | 321 | 20.8k | s.is_uncompressed = bits as u8; | 322 | 5.82k | } | 323 | 26.6k | s.meta_block_remaining_len += 1; | 324 | 26.6k | s.substate_metablock_header = | 325 | 26.6k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; | 326 | 26.6k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 327 | | } | 328 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_RESERVED => { | 329 | 3.34k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 330 | 6 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 331 | 3.33k | } | 332 | 3.33k | if (bits != 0) { | 333 | 532 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_RESERVED; | 334 | 2.80k | } | 335 | 2.80k | s.substate_metablock_header = | 336 | 2.80k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_BYTES; | 337 | | // No break, transit to the next state. | 338 | | } | 339 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_BYTES => { | 340 | 2.80k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input) { | 341 | 6 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 342 | 2.80k | } | 343 | 2.80k | if (bits == 0) { | 344 | 726 | s.substate_metablock_header = | 345 | 726 | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; | 346 | 726 | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 347 | 2.07k | } | 348 | 2.07k | s.size_nibbles = bits as u8; | 349 | 2.07k | s.substate_metablock_header = | 350 | 2.07k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_METADATA; | 351 | | // No break, transit to the next state. | 352 | | } | 353 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_METADATA => { | 354 | 2.31k | let mut i = s.loop_counter; | 355 | 5.29k | while i < s.size_nibbles as i32 { | 356 | 3.95k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 8, &mut bits, input) { | 357 | 374 | s.loop_counter = i; | 358 | 374 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 359 | 3.58k | } | 360 | 3.58k | if (i + 1 == s.size_nibbles as i32 && s.size_nibbles > 1 && bits == 0) { | 361 | 594 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE; | 362 | 2.98k | } | 363 | 2.98k | s.meta_block_remaining_len |= (bits << (i * 8)) as i32; | 364 | 2.98k | i += 1; | 365 | | } | 366 | 1.34k | s.substate_metablock_header = | 367 | 1.34k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED; | 368 | 1.34k | continue; | 369 | | } | 370 | | } | 371 | | } | 372 | 34.8k | } |
brotli_decompressor::decode::DecodeMetaBlockLength::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 243 | 51.7k | fn DecodeMetaBlockLength<AllocU8: alloc::Allocator<u8>, | 244 | 51.7k | AllocU32: alloc::Allocator<u32>, | 245 | 51.7k | AllocHC: alloc::Allocator<HuffmanCode>> | 246 | 51.7k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 247 | 51.7k | input: &[u8]) | 248 | 51.7k | -> BrotliDecoderErrorCode { | 249 | 51.7k | let mut bits: u32 = 0; | 250 | | loop { | 251 | 149k | match s.substate_metablock_header { | 252 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE => { | 253 | 43.2k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 254 | 12.6k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 255 | 30.5k | } | 256 | 30.5k | s.is_last_metablock = bits as u8; | 257 | 30.5k | s.meta_block_remaining_len = 0; | 258 | 30.5k | s.is_uncompressed = 0; | 259 | 30.5k | s.is_metadata = 0; | 260 | 30.5k | if (s.is_last_metablock == 0) { | 261 | 24.0k | s.substate_metablock_header = | 262 | 24.0k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES; | 263 | 24.0k | continue; | 264 | 6.45k | } | 265 | 6.45k | s.substate_metablock_header = | 266 | 6.45k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_EMPTY; | 267 | | // No break, transit to the next state. | 268 | | } | 269 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_EMPTY => { | 270 | 8.94k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 271 | 2.55k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 272 | 6.39k | } | 273 | 6.39k | if bits != 0 { | 274 | 1.10k | s.substate_metablock_header = | 275 | 1.10k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; | 276 | 1.10k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 277 | 5.29k | } | 278 | 5.29k | s.substate_metablock_header = | 279 | 5.29k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES; | 280 | | // No break, transit to the next state. | 281 | | } | 282 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NIBBLES => { | 283 | 30.0k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input) { | 284 | 676 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 285 | 29.3k | } | 286 | 29.3k | s.size_nibbles = (bits + 4) as u8; | 287 | 29.3k | s.loop_counter = 0; | 288 | 29.3k | if (bits == 3) { | 289 | 5.22k | s.is_metadata = 1; | 290 | 5.22k | s.substate_metablock_header = | 291 | 5.22k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_RESERVED; | 292 | 5.22k | continue; | 293 | 24.1k | } | 294 | 24.1k | s.substate_metablock_header = | 295 | 24.1k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_SIZE; | 296 | | // No break, transit to the next state. | 297 | | | 298 | | } | 299 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_SIZE => { | 300 | 25.8k | let mut i = s.loop_counter; | 301 | 136k | while i < s.size_nibbles as i32 { | 302 | 113k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 4, &mut bits, input) { | 303 | 2.58k | s.loop_counter = i; | 304 | 2.58k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 305 | 111k | } | 306 | 111k | if (i + 1 == s.size_nibbles as i32 && s.size_nibbles > 4 && bits == 0) { | 307 | 244 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE; | 308 | 111k | } | 309 | 111k | s.meta_block_remaining_len |= (bits << (i * 4)) as i32; | 310 | 111k | i += 1; | 311 | | } | 312 | 23.0k | s.substate_metablock_header = | 313 | 23.0k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED; | 314 | | // No break, transit to the next state. | 315 | | } | 316 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED => { | 317 | 25.5k | if (s.is_last_metablock == 0 && s.is_metadata == 0) { | 318 | 19.6k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 319 | 210 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 320 | 19.4k | } | 321 | 19.4k | s.is_uncompressed = bits as u8; | 322 | 5.90k | } | 323 | 25.3k | s.meta_block_remaining_len += 1; | 324 | 25.3k | s.substate_metablock_header = | 325 | 25.3k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; | 326 | 25.3k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 327 | | } | 328 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_RESERVED => { | 329 | 7.83k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input) { | 330 | 2.61k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 331 | 5.22k | } | 332 | 5.22k | if (bits != 0) { | 333 | 233 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_RESERVED; | 334 | 4.98k | } | 335 | 4.98k | s.substate_metablock_header = | 336 | 4.98k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_BYTES; | 337 | | // No break, transit to the next state. | 338 | | } | 339 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_BYTES => { | 340 | 5.52k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input) { | 341 | 546 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 342 | 4.98k | } | 343 | 4.98k | if (bits == 0) { | 344 | 2.41k | s.substate_metablock_header = | 345 | 2.41k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_NONE; | 346 | 2.41k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 347 | 2.56k | } | 348 | 2.56k | s.size_nibbles = bits as u8; | 349 | 2.56k | s.substate_metablock_header = | 350 | 2.56k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_METADATA; | 351 | | // No break, transit to the next state. | 352 | | } | 353 | | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_METADATA => { | 354 | 2.85k | let mut i = s.loop_counter; | 355 | 6.68k | while i < s.size_nibbles as i32 { | 356 | 4.35k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 8, &mut bits, input) { | 357 | 295 | s.loop_counter = i; | 358 | 295 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 359 | 4.05k | } | 360 | 4.05k | if (i + 1 == s.size_nibbles as i32 && s.size_nibbles > 1 && bits == 0) { | 361 | 223 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE; | 362 | 3.83k | } | 363 | 3.83k | s.meta_block_remaining_len |= (bits << (i * 8)) as i32; | 364 | 3.83k | i += 1; | 365 | | } | 366 | 2.33k | s.substate_metablock_header = | 367 | 2.33k | BrotliRunningMetablockHeaderState::BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED; | 368 | 2.33k | continue; | 369 | | } | 370 | | } | 371 | | } | 372 | 51.7k | } |
|
373 | | // Decodes the Huffman code. |
374 | | // This method doesn't read data from the bit reader, BUT drops the amount of |
375 | | // bits that correspond to the decoded symbol. |
376 | | // bits MUST contain at least 15 (BROTLI_HUFFMAN_MAX_CODE_LENGTH) valid bits. |
377 | | #[inline(always)] |
378 | 2.44G | fn DecodeSymbol(bits: u32, table: &[HuffmanCode], br: &mut bit_reader::BrotliBitReader) -> u32 { |
379 | 2.44G | let mut table_index = bits & HUFFMAN_TABLE_MASK; |
380 | 2.44G | let mut table_element = fast!((table)[table_index as usize]); |
381 | 2.44G | if table_element.bits > HUFFMAN_TABLE_BITS as u8 { |
382 | 43.4k | let nbits = table_element.bits - HUFFMAN_TABLE_BITS as u8; |
383 | 43.4k | bit_reader::BrotliDropBits(br, HUFFMAN_TABLE_BITS); |
384 | 43.4k | table_index += table_element.value as u32; |
385 | 43.4k | table_element = fast!((table)[(table_index |
386 | 43.4k | + ((bits >> HUFFMAN_TABLE_BITS) |
387 | 43.4k | & bit_reader::BitMask(nbits as u32))) as usize]); |
388 | 2.44G | } |
389 | 2.44G | bit_reader::BrotliDropBits(br, table_element.bits as u32); |
390 | 2.44G | table_element.value as u32 |
391 | 2.44G | } |
392 | | |
393 | | // Reads and decodes the next Huffman code from bit-stream. |
394 | | // This method peeks 16 bits of input and drops 0 - 15 of them. |
395 | | #[inline(always)] |
396 | 268M | fn ReadSymbol(table: &[HuffmanCode], br: &mut bit_reader::BrotliBitReader, input: &[u8]) -> u32 { |
397 | 268M | DecodeSymbol(bit_reader::BrotliGet16BitsUnmasked(br, input), table, br) |
398 | 268M | } |
399 | | |
400 | | // Same as DecodeSymbol, but it is known that there is less than 15 bits of |
401 | | // input are currently available. |
402 | 153M | fn SafeDecodeSymbol(table: &[HuffmanCode], |
403 | 153M | mut br: &mut bit_reader::BrotliBitReader, |
404 | 153M | result: &mut u32) |
405 | 153M | -> bool { |
406 | 153M | let mut available_bits = bit_reader::BrotliGetAvailableBits(br); |
407 | 153M | if (available_bits == 0) { |
408 | 18.2M | if (fast!((table)[0]).bits == 0) { |
409 | 18.0M | *result = fast!((table)[0]).value as u32; |
410 | 18.0M | return true; |
411 | 168k | } |
412 | 168k | return false; /* No valid bits at all. */ |
413 | 134M | } |
414 | 134M | let mut val = bit_reader::BrotliGetBitsUnmasked(br) as u32; |
415 | 134M | let table_index = (val & HUFFMAN_TABLE_MASK) as usize; |
416 | 134M | let table_element = fast!((table)[table_index]); |
417 | 134M | if (table_element.bits <= HUFFMAN_TABLE_BITS as u8) { |
418 | 134M | if (table_element.bits as u32 <= available_bits) { |
419 | 134M | bit_reader::BrotliDropBits(&mut br, table_element.bits as u32); |
420 | 134M | *result = table_element.value as u32; |
421 | 134M | return true; |
422 | | } else { |
423 | 45.6k | return false; /* Not enough bits for the first level. */ |
424 | | } |
425 | 4.80k | } |
426 | 4.80k | if (available_bits <= HUFFMAN_TABLE_BITS) { |
427 | 1.79k | return false; /* Not enough bits to move to the second level. */ |
428 | 3.01k | } |
429 | | |
430 | | // Speculatively drop HUFFMAN_TABLE_BITS. |
431 | 3.01k | val = (val & bit_reader::BitMask(table_element.bits as u32)) >> HUFFMAN_TABLE_BITS; |
432 | 3.01k | available_bits -= HUFFMAN_TABLE_BITS; |
433 | 3.01k | let table_sub_element = fast!((table)[table_index + table_element.value as usize + val as usize]); |
434 | 3.01k | if (available_bits < table_sub_element.bits as u32) { |
435 | 1.83k | return false; /* Not enough bits for the second level. */ |
436 | 1.18k | } |
437 | | |
438 | 1.18k | bit_reader::BrotliDropBits(&mut br, HUFFMAN_TABLE_BITS + table_sub_element.bits as u32); |
439 | 1.18k | *result = table_sub_element.value as u32; |
440 | 1.18k | true |
441 | 153M | } |
442 | | |
443 | 2.33G | fn SafeReadSymbol(table: &[HuffmanCode], |
444 | 2.33G | br: &mut bit_reader::BrotliBitReader, |
445 | 2.33G | result: &mut u32, |
446 | 2.33G | input: &[u8]) |
447 | 2.33G | -> bool { |
448 | 2.33G | let mut val: u32 = 0; |
449 | 2.33G | if (bit_reader::BrotliSafeGetBits(br, 15, &mut val, input)) { |
450 | 2.18G | *result = DecodeSymbol(val, table, br); |
451 | 2.18G | return true; |
452 | 153M | } else { |
453 | 153M | mark_unlikely(); |
454 | 153M | } |
455 | 153M | SafeDecodeSymbol(table, br, result) |
456 | 2.33G | } |
457 | | |
458 | | // Makes a look-up in first level Huffman table. Peeks 8 bits. |
459 | 423M | fn PreloadSymbol(safe: bool, |
460 | 423M | table: &[HuffmanCode], |
461 | 423M | br: &mut bit_reader::BrotliBitReader, |
462 | 423M | bits: &mut u32, |
463 | 423M | value: &mut u32, |
464 | 423M | input: &[u8]) { |
465 | 423M | if (safe) { |
466 | 16.6M | return; |
467 | 406M | } |
468 | 406M | let table_element = |
469 | 406M | fast!((table)[bit_reader::BrotliGetBits(br, HUFFMAN_TABLE_BITS, input) as usize]); |
470 | 406M | *bits = table_element.bits as u32; |
471 | 406M | *value = table_element.value as u32; |
472 | 423M | } |
473 | | |
474 | | // Decodes the next Huffman code using data prepared by PreloadSymbol. |
475 | | // Reads 0 - 15 bits. Also peeks 8 following bits. |
476 | 384M | fn ReadPreloadedSymbol(table: &[HuffmanCode], |
477 | 384M | br: &mut bit_reader::BrotliBitReader, |
478 | 384M | bits: &mut u32, |
479 | 384M | value: &mut u32, |
480 | 384M | input: &[u8]) |
481 | 384M | -> u32 { |
482 | 384M | let result = if *bits > HUFFMAN_TABLE_BITS { |
483 | 2.42k | mark_unlikely(); |
484 | 2.42k | let val = bit_reader::BrotliGet16BitsUnmasked(br, input); |
485 | 2.42k | let mut ext_index = (val & HUFFMAN_TABLE_MASK) + *value; |
486 | 2.42k | let mask = bit_reader::BitMask((*bits - HUFFMAN_TABLE_BITS)); |
487 | 2.42k | bit_reader::BrotliDropBits(br, HUFFMAN_TABLE_BITS); |
488 | 2.42k | ext_index += (val >> HUFFMAN_TABLE_BITS) & mask; |
489 | 2.42k | let ext = fast!((table)[ext_index as usize]); |
490 | 2.42k | bit_reader::BrotliDropBits(br, ext.bits as u32); |
491 | 2.42k | ext.value as u32 |
492 | | } else { |
493 | 384M | bit_reader::BrotliDropBits(br, *bits); |
494 | 384M | *value |
495 | | }; |
496 | 384M | PreloadSymbol(false, table, br, bits, value, input); |
497 | 384M | result |
498 | 384M | } |
499 | | |
500 | 270k | fn Log2Floor(mut x: u32) -> u32 { |
501 | 270k | let mut result: u32 = 0; |
502 | 2.12M | while x != 0 { |
503 | 1.85M | x >>= 1; |
504 | 1.85M | result += 1; |
505 | 1.85M | } |
506 | 270k | result |
507 | 270k | } |
508 | | |
509 | | |
510 | | // Reads (s->symbol + 1) symbols. |
511 | | // Totally 1..4 symbols are read, 1..11 bits each. |
512 | | // The list of symbols MUST NOT contain duplicates. |
513 | | // |
514 | 270k | fn ReadSimpleHuffmanSymbols<AllocU8: alloc::Allocator<u8>, |
515 | 270k | AllocU32: alloc::Allocator<u32>, |
516 | 270k | AllocHC: alloc::Allocator<HuffmanCode>> |
517 | 270k | (alphabet_size: u32, max_symbol: u32, |
518 | 270k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
519 | 270k | input: &[u8]) |
520 | 270k | -> BrotliDecoderErrorCode { |
521 | | |
522 | | // max_bits == 1..11; symbol == 0..3; 1..44 bits will be read. |
523 | 270k | let max_bits = Log2Floor(alphabet_size - 1); |
524 | 270k | let mut i = s.sub_loop_counter; |
525 | 270k | let num_symbols = s.symbol; |
526 | 514k | for symbols_lists_item in fast_mut!((s.symbols_lists_array)[s.sub_loop_counter as usize; |
527 | 270k | num_symbols as usize + 1]) |
528 | 270k | .iter_mut() { |
529 | 514k | let mut v: u32 = 0; |
530 | 514k | if !bit_reader::BrotliSafeReadBits(&mut s.br, max_bits, &mut v, input) { |
531 | 52.2k | mark_unlikely(); |
532 | 52.2k | s.sub_loop_counter = i; |
533 | 52.2k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ; |
534 | 52.2k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
535 | 462k | } |
536 | 462k | if (v >= max_symbol) { |
537 | 2.06k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET; |
538 | 460k | } |
539 | 460k | *symbols_lists_item = v as u16; |
540 | | BROTLI_LOG_UINT!(v); |
541 | 460k | i += 1; |
542 | | } |
543 | 216k | i = 0; |
544 | 238k | for symbols_list_item in fast!((s.symbols_lists_array)[0; num_symbols as usize]).iter() { |
545 | 368k | for other_item in fast!((s.symbols_lists_array)[i as usize + 1 ; num_symbols as usize+ 1]) |
546 | 238k | .iter() { |
547 | 368k | if (*symbols_list_item == *other_item) { |
548 | 2.51k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME; |
549 | 365k | } |
550 | | } |
551 | 236k | i += 1; |
552 | | } |
553 | 213k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS |
554 | 270k | } brotli_decompressor::decode::ReadSimpleHuffmanSymbols::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 514 | 159k | fn ReadSimpleHuffmanSymbols<AllocU8: alloc::Allocator<u8>, | 515 | 159k | AllocU32: alloc::Allocator<u32>, | 516 | 159k | AllocHC: alloc::Allocator<HuffmanCode>> | 517 | 159k | (alphabet_size: u32, max_symbol: u32, | 518 | 159k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 519 | 159k | input: &[u8]) | 520 | 159k | -> BrotliDecoderErrorCode { | 521 | | | 522 | | // max_bits == 1..11; symbol == 0..3; 1..44 bits will be read. | 523 | 159k | let max_bits = Log2Floor(alphabet_size - 1); | 524 | 159k | let mut i = s.sub_loop_counter; | 525 | 159k | let num_symbols = s.symbol; | 526 | 303k | for symbols_lists_item in fast_mut!((s.symbols_lists_array)[s.sub_loop_counter as usize; | 527 | 159k | num_symbols as usize + 1]) | 528 | 159k | .iter_mut() { | 529 | 303k | let mut v: u32 = 0; | 530 | 303k | if !bit_reader::BrotliSafeReadBits(&mut s.br, max_bits, &mut v, input) { | 531 | 42.0k | mark_unlikely(); | 532 | 42.0k | s.sub_loop_counter = i; | 533 | 42.0k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ; | 534 | 42.0k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 535 | 261k | } | 536 | 261k | if (v >= max_symbol) { | 537 | 1.19k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET; | 538 | 260k | } | 539 | 260k | *symbols_lists_item = v as u16; | 540 | | BROTLI_LOG_UINT!(v); | 541 | 260k | i += 1; | 542 | | } | 543 | 115k | i = 0; | 544 | 141k | for symbols_list_item in fast!((s.symbols_lists_array)[0; num_symbols as usize]).iter() { | 545 | 227k | for other_item in fast!((s.symbols_lists_array)[i as usize + 1 ; num_symbols as usize+ 1]) | 546 | 141k | .iter() { | 547 | 227k | if (*symbols_list_item == *other_item) { | 548 | 958 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME; | 549 | 227k | } | 550 | | } | 551 | 140k | i += 1; | 552 | | } | 553 | 114k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 554 | 159k | } |
Unexecuted instantiation: brotli_decompressor::decode::ReadSimpleHuffmanSymbols::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::ReadSimpleHuffmanSymbols::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::ReadSimpleHuffmanSymbols::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 514 | 60.7k | fn ReadSimpleHuffmanSymbols<AllocU8: alloc::Allocator<u8>, | 515 | 60.7k | AllocU32: alloc::Allocator<u32>, | 516 | 60.7k | AllocHC: alloc::Allocator<HuffmanCode>> | 517 | 60.7k | (alphabet_size: u32, max_symbol: u32, | 518 | 60.7k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 519 | 60.7k | input: &[u8]) | 520 | 60.7k | -> BrotliDecoderErrorCode { | 521 | | | 522 | | // max_bits == 1..11; symbol == 0..3; 1..44 bits will be read. | 523 | 60.7k | let max_bits = Log2Floor(alphabet_size - 1); | 524 | 60.7k | let mut i = s.sub_loop_counter; | 525 | 60.7k | let num_symbols = s.symbol; | 526 | 110k | for symbols_lists_item in fast_mut!((s.symbols_lists_array)[s.sub_loop_counter as usize; | 527 | 60.7k | num_symbols as usize + 1]) | 528 | 60.7k | .iter_mut() { | 529 | 110k | let mut v: u32 = 0; | 530 | 110k | if !bit_reader::BrotliSafeReadBits(&mut s.br, max_bits, &mut v, input) { | 531 | 8.64k | mark_unlikely(); | 532 | 8.64k | s.sub_loop_counter = i; | 533 | 8.64k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ; | 534 | 8.64k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 535 | 101k | } | 536 | 101k | if (v >= max_symbol) { | 537 | 428 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET; | 538 | 101k | } | 539 | 101k | *symbols_lists_item = v as u16; | 540 | | BROTLI_LOG_UINT!(v); | 541 | 101k | i += 1; | 542 | | } | 543 | 51.6k | i = 0; | 544 | 51.6k | for symbols_list_item in fast!((s.symbols_lists_array)[0; num_symbols as usize]).iter() { | 545 | 66.1k | for other_item in fast!((s.symbols_lists_array)[i as usize + 1 ; num_symbols as usize+ 1]) | 546 | 48.3k | .iter() { | 547 | 66.1k | if (*symbols_list_item == *other_item) { | 548 | 690 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME; | 549 | 65.4k | } | 550 | | } | 551 | 47.6k | i += 1; | 552 | | } | 553 | 50.9k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 554 | 60.7k | } |
brotli_decompressor::decode::ReadSimpleHuffmanSymbols::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 514 | 50.4k | fn ReadSimpleHuffmanSymbols<AllocU8: alloc::Allocator<u8>, | 515 | 50.4k | AllocU32: alloc::Allocator<u32>, | 516 | 50.4k | AllocHC: alloc::Allocator<HuffmanCode>> | 517 | 50.4k | (alphabet_size: u32, max_symbol: u32, | 518 | 50.4k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 519 | 50.4k | input: &[u8]) | 520 | 50.4k | -> BrotliDecoderErrorCode { | 521 | | | 522 | | // max_bits == 1..11; symbol == 0..3; 1..44 bits will be read. | 523 | 50.4k | let max_bits = Log2Floor(alphabet_size - 1); | 524 | 50.4k | let mut i = s.sub_loop_counter; | 525 | 50.4k | let num_symbols = s.symbol; | 526 | 100k | for symbols_lists_item in fast_mut!((s.symbols_lists_array)[s.sub_loop_counter as usize; | 527 | 50.4k | num_symbols as usize + 1]) | 528 | 50.4k | .iter_mut() { | 529 | 100k | let mut v: u32 = 0; | 530 | 100k | if !bit_reader::BrotliSafeReadBits(&mut s.br, max_bits, &mut v, input) { | 531 | 1.49k | mark_unlikely(); | 532 | 1.49k | s.sub_loop_counter = i; | 533 | 1.49k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ; | 534 | 1.49k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 535 | 99.4k | } | 536 | 99.4k | if (v >= max_symbol) { | 537 | 448 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET; | 538 | 98.9k | } | 539 | 98.9k | *symbols_lists_item = v as u16; | 540 | | BROTLI_LOG_UINT!(v); | 541 | 98.9k | i += 1; | 542 | | } | 543 | 48.5k | i = 0; | 544 | 48.9k | for symbols_list_item in fast!((s.symbols_lists_array)[0; num_symbols as usize]).iter() { | 545 | 74.2k | for other_item in fast!((s.symbols_lists_array)[i as usize + 1 ; num_symbols as usize+ 1]) | 546 | 48.9k | .iter() { | 547 | 74.2k | if (*symbols_list_item == *other_item) { | 548 | 866 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME; | 549 | 73.3k | } | 550 | | } | 551 | 48.0k | i += 1; | 552 | | } | 553 | 47.6k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 554 | 50.4k | } |
|
555 | | |
556 | | // Process single decoded symbol code length: |
557 | | // A) reset the repeat variable |
558 | | // B) remember code length (if it is not 0) |
559 | | // C) extend corredponding index-chain |
560 | | // D) reduce the huffman space |
561 | | // E) update the histogram |
562 | | // |
563 | 2.63M | fn ProcessSingleCodeLength(code_len: u32, |
564 | 2.63M | symbol: &mut u32, |
565 | 2.63M | repeat: &mut u32, |
566 | 2.63M | space: &mut u32, |
567 | 2.63M | prev_code_len: &mut u32, |
568 | 2.63M | symbol_lists: &mut [u16], |
569 | 2.63M | symbol_list_index_offset: usize, |
570 | 2.63M | code_length_histo: &mut [u16], |
571 | 2.63M | next_symbol: &mut [i32]) { |
572 | 2.63M | *repeat = 0; |
573 | 2.63M | if (code_len != 0) { |
574 | 2.24M | // code_len == 1..15 |
575 | 2.24M | // next_symbol may be negative, hence we have to supply offset to function |
576 | 2.24M | fast_mut!((symbol_lists)[(symbol_list_index_offset as i32 + |
577 | 2.24M | fast_inner!((next_symbol)[code_len as usize])) as usize]) = |
578 | 2.24M | (*symbol) as u16; |
579 | 2.24M | fast_mut!((next_symbol)[code_len as usize]) = (*symbol) as i32; |
580 | 2.24M | *prev_code_len = code_len; |
581 | 2.24M | *space = space.wrapping_sub(32768 >> code_len); |
582 | 2.24M | fast_mut!((code_length_histo)[code_len as usize]) += 1; |
583 | 2.24M | BROTLI_LOG!("[ReadHuffmanCode] code_length[{:}]={:} histo[]={:}\n", |
584 | 2.24M | *symbol, code_len, code_length_histo[code_len as usize]); |
585 | 2.24M | } |
586 | 2.63M | (*symbol) += 1; |
587 | 2.63M | } |
588 | | |
589 | | // Process repeated symbol code length. |
590 | | // A) Check if it is the extension of previous repeat sequence; if the decoded |
591 | | // value is not kCodeLengthRepeatCode, then it is a new symbol-skip |
592 | | // B) Update repeat variable |
593 | | // C) Check if operation is feasible (fits alphapet) |
594 | | // D) For each symbol do the same operations as in ProcessSingleCodeLength |
595 | | // |
596 | | // PRECONDITION: code_len == kCodeLengthRepeatCode or kCodeLengthRepeatCode + 1 |
597 | | // |
598 | 285k | fn ProcessRepeatedCodeLength(code_len: u32, |
599 | 285k | mut repeat_delta: u32, |
600 | 285k | alphabet_size: u32, |
601 | 285k | symbol: &mut u32, |
602 | 285k | repeat: &mut u32, |
603 | 285k | space: &mut u32, |
604 | 285k | prev_code_len: &mut u32, |
605 | 285k | repeat_code_len: &mut u32, |
606 | 285k | symbol_lists: &mut [u16], |
607 | 285k | symbol_lists_index: usize, |
608 | 285k | code_length_histo: &mut [u16], |
609 | 285k | next_symbol: &mut [i32]) { |
610 | | let old_repeat: u32; |
611 | | let extra_bits: u32; |
612 | | let new_len: u32; |
613 | 285k | if (code_len == kCodeLengthRepeatCode) { |
614 | 116k | extra_bits = 2; |
615 | 116k | new_len = *prev_code_len |
616 | | } else { |
617 | 169k | extra_bits = 3; |
618 | 169k | new_len = 0 |
619 | | } |
620 | 285k | if (*repeat_code_len != new_len) { |
621 | 66.0k | *repeat = 0; |
622 | 66.0k | *repeat_code_len = new_len; |
623 | 219k | } |
624 | 285k | old_repeat = *repeat; |
625 | 285k | if (*repeat > 0) { |
626 | 73.5k | *repeat -= 2; |
627 | 73.5k | *repeat <<= extra_bits; |
628 | 212k | } |
629 | 285k | *repeat += repeat_delta + 3; |
630 | 285k | repeat_delta = *repeat - old_repeat; |
631 | 285k | if (*symbol + repeat_delta > alphabet_size) { |
632 | 7.51k | *symbol = alphabet_size; |
633 | 7.51k | *space = 0xFFFFF; |
634 | 7.51k | return; |
635 | 278k | } |
636 | | BROTLI_LOG!("[ReadHuffmanCode] code_length[{:}..{:}] = {:}\n", |
637 | | *symbol, *symbol + repeat_delta - 1, *repeat_code_len); |
638 | 278k | if (*repeat_code_len != 0) { |
639 | 112k | let last: u32 = *symbol + repeat_delta; |
640 | 112k | let mut next: i32 = fast!((next_symbol)[*repeat_code_len as usize]); |
641 | | loop { |
642 | 1.04M | fast_mut!((symbol_lists)[(symbol_lists_index as i32 + next) as usize]) = (*symbol) as u16; |
643 | 1.04M | next = (*symbol) as i32; |
644 | 1.04M | (*symbol) += 1; |
645 | 1.04M | if *symbol == last { |
646 | 112k | break; |
647 | 933k | } |
648 | | } |
649 | 112k | fast_mut!((next_symbol)[*repeat_code_len as usize]) = next; |
650 | 112k | *space = space.wrapping_sub(repeat_delta << (15 - *repeat_code_len)); |
651 | 112k | fast_mut!((code_length_histo)[*repeat_code_len as usize]) = |
652 | 112k | (fast!((code_length_histo)[*repeat_code_len as usize]) as u32 + repeat_delta) as u16; |
653 | 166k | } else { |
654 | 166k | *symbol += repeat_delta; |
655 | 166k | } |
656 | 285k | } |
657 | | |
658 | | // Reads and decodes symbol codelengths. |
659 | 154k | fn ReadSymbolCodeLengths<AllocU8: alloc::Allocator<u8>, |
660 | 154k | AllocU32: alloc::Allocator<u32>, |
661 | 154k | AllocHC: alloc::Allocator<HuffmanCode>> |
662 | 154k | (alphabet_size: u32, |
663 | 154k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
664 | 154k | input: &[u8]) |
665 | 154k | -> BrotliDecoderErrorCode { |
666 | | |
667 | 154k | let mut symbol = s.symbol; |
668 | 154k | let mut repeat = s.repeat; |
669 | 154k | let mut space = s.space; |
670 | 154k | let mut prev_code_len: u32 = s.prev_code_len; |
671 | 154k | let mut repeat_code_len: u32 = s.repeat_code_len; |
672 | 154k | if (!bit_reader::BrotliWarmupBitReader(&mut s.br, input)) { |
673 | 28.0k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
674 | 126k | } |
675 | 2.32M | while (symbol < alphabet_size && space > 0) { |
676 | 2.26M | let mut p_index = 0; |
677 | | let code_len: u32; |
678 | 2.26M | if (!bit_reader::BrotliCheckInputAmount(&s.br, bit_reader::BROTLI_SHORT_FILL_BIT_WINDOW_READ)) { |
679 | 69.5k | s.symbol = symbol; |
680 | 69.5k | s.repeat = repeat; |
681 | 69.5k | s.prev_code_len = prev_code_len; |
682 | 69.5k | s.repeat_code_len = repeat_code_len; |
683 | 69.5k | s.space = space; |
684 | 69.5k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
685 | 2.19M | } |
686 | 2.19M | bit_reader::BrotliFillBitWindow16(&mut s.br, input); |
687 | 2.19M | p_index += |
688 | 2.19M | bit_reader::BrotliGetBitsUnmasked(&s.br) & |
689 | 2.19M | bit_reader::BitMask(huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as u32) as u64; |
690 | 2.19M | let p = fast!((s.table)[p_index as usize]); |
691 | 2.19M | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32); /* Use 1..5 bits */ |
692 | 2.19M | code_len = p.value as u32; /* code_len == 0..17 */ |
693 | 2.19M | if (code_len < kCodeLengthRepeatCode) { |
694 | 1.96M | ProcessSingleCodeLength(code_len, |
695 | 1.96M | &mut symbol, |
696 | 1.96M | &mut repeat, |
697 | 1.96M | &mut space, |
698 | 1.96M | &mut prev_code_len, |
699 | 1.96M | &mut s.symbols_lists_array, |
700 | 1.96M | s.symbol_lists_index as usize, |
701 | 1.96M | &mut s.code_length_histo[..], |
702 | 1.96M | &mut s.next_symbol[..]); |
703 | 1.96M | } else { |
704 | | // code_len == 16..17, extra_bits == 2..3 |
705 | 230k | let extra_bits: u32 = if code_len == kCodeLengthRepeatCode { |
706 | 86.9k | 2 |
707 | | } else { |
708 | 143k | 3 |
709 | | }; |
710 | 230k | let repeat_delta: u32 = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32 & |
711 | 230k | bit_reader::BitMask(extra_bits); |
712 | 230k | bit_reader::BrotliDropBits(&mut s.br, extra_bits); |
713 | 230k | ProcessRepeatedCodeLength(code_len, |
714 | 230k | repeat_delta, |
715 | 230k | alphabet_size, |
716 | 230k | &mut symbol, |
717 | 230k | &mut repeat, |
718 | 230k | &mut space, |
719 | 230k | &mut prev_code_len, |
720 | 230k | &mut repeat_code_len, |
721 | 230k | &mut s.symbols_lists_array, |
722 | 230k | s.symbol_lists_index as usize, |
723 | 230k | &mut s.code_length_histo[..], |
724 | 230k | &mut s.next_symbol[..]); |
725 | | } |
726 | | } |
727 | 57.3k | s.space = space; |
728 | 57.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS |
729 | 154k | } brotli_decompressor::decode::ReadSymbolCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 659 | 90.5k | fn ReadSymbolCodeLengths<AllocU8: alloc::Allocator<u8>, | 660 | 90.5k | AllocU32: alloc::Allocator<u32>, | 661 | 90.5k | AllocHC: alloc::Allocator<HuffmanCode>> | 662 | 90.5k | (alphabet_size: u32, | 663 | 90.5k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 664 | 90.5k | input: &[u8]) | 665 | 90.5k | -> BrotliDecoderErrorCode { | 666 | | | 667 | 90.5k | let mut symbol = s.symbol; | 668 | 90.5k | let mut repeat = s.repeat; | 669 | 90.5k | let mut space = s.space; | 670 | 90.5k | let mut prev_code_len: u32 = s.prev_code_len; | 671 | 90.5k | let mut repeat_code_len: u32 = s.repeat_code_len; | 672 | 90.5k | if (!bit_reader::BrotliWarmupBitReader(&mut s.br, input)) { | 673 | 21.5k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 674 | 69.0k | } | 675 | 1.26M | while (symbol < alphabet_size && space > 0) { | 676 | 1.23M | let mut p_index = 0; | 677 | | let code_len: u32; | 678 | 1.23M | if (!bit_reader::BrotliCheckInputAmount(&s.br, bit_reader::BROTLI_SHORT_FILL_BIT_WINDOW_READ)) { | 679 | 37.9k | s.symbol = symbol; | 680 | 37.9k | s.repeat = repeat; | 681 | 37.9k | s.prev_code_len = prev_code_len; | 682 | 37.9k | s.repeat_code_len = repeat_code_len; | 683 | 37.9k | s.space = space; | 684 | 37.9k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 685 | 1.19M | } | 686 | 1.19M | bit_reader::BrotliFillBitWindow16(&mut s.br, input); | 687 | 1.19M | p_index += | 688 | 1.19M | bit_reader::BrotliGetBitsUnmasked(&s.br) & | 689 | 1.19M | bit_reader::BitMask(huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as u32) as u64; | 690 | 1.19M | let p = fast!((s.table)[p_index as usize]); | 691 | 1.19M | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32); /* Use 1..5 bits */ | 692 | 1.19M | code_len = p.value as u32; /* code_len == 0..17 */ | 693 | 1.19M | if (code_len < kCodeLengthRepeatCode) { | 694 | 1.05M | ProcessSingleCodeLength(code_len, | 695 | 1.05M | &mut symbol, | 696 | 1.05M | &mut repeat, | 697 | 1.05M | &mut space, | 698 | 1.05M | &mut prev_code_len, | 699 | 1.05M | &mut s.symbols_lists_array, | 700 | 1.05M | s.symbol_lists_index as usize, | 701 | 1.05M | &mut s.code_length_histo[..], | 702 | 1.05M | &mut s.next_symbol[..]); | 703 | 1.05M | } else { | 704 | | // code_len == 16..17, extra_bits == 2..3 | 705 | 139k | let extra_bits: u32 = if code_len == kCodeLengthRepeatCode { | 706 | 41.7k | 2 | 707 | | } else { | 708 | 97.3k | 3 | 709 | | }; | 710 | 139k | let repeat_delta: u32 = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32 & | 711 | 139k | bit_reader::BitMask(extra_bits); | 712 | 139k | bit_reader::BrotliDropBits(&mut s.br, extra_bits); | 713 | 139k | ProcessRepeatedCodeLength(code_len, | 714 | 139k | repeat_delta, | 715 | 139k | alphabet_size, | 716 | 139k | &mut symbol, | 717 | 139k | &mut repeat, | 718 | 139k | &mut space, | 719 | 139k | &mut prev_code_len, | 720 | 139k | &mut repeat_code_len, | 721 | 139k | &mut s.symbols_lists_array, | 722 | 139k | s.symbol_lists_index as usize, | 723 | 139k | &mut s.code_length_histo[..], | 724 | 139k | &mut s.next_symbol[..]); | 725 | | } | 726 | | } | 727 | 31.0k | s.space = space; | 728 | 31.0k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 729 | 90.5k | } |
Unexecuted instantiation: brotli_decompressor::decode::ReadSymbolCodeLengths::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::ReadSymbolCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::ReadSymbolCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 659 | 36.3k | fn ReadSymbolCodeLengths<AllocU8: alloc::Allocator<u8>, | 660 | 36.3k | AllocU32: alloc::Allocator<u32>, | 661 | 36.3k | AllocHC: alloc::Allocator<HuffmanCode>> | 662 | 36.3k | (alphabet_size: u32, | 663 | 36.3k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 664 | 36.3k | input: &[u8]) | 665 | 36.3k | -> BrotliDecoderErrorCode { | 666 | | | 667 | 36.3k | let mut symbol = s.symbol; | 668 | 36.3k | let mut repeat = s.repeat; | 669 | 36.3k | let mut space = s.space; | 670 | 36.3k | let mut prev_code_len: u32 = s.prev_code_len; | 671 | 36.3k | let mut repeat_code_len: u32 = s.repeat_code_len; | 672 | 36.3k | if (!bit_reader::BrotliWarmupBitReader(&mut s.br, input)) { | 673 | 2.39k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 674 | 34.0k | } | 675 | 594k | while (symbol < alphabet_size && space > 0) { | 676 | 583k | let mut p_index = 0; | 677 | | let code_len: u32; | 678 | 583k | if (!bit_reader::BrotliCheckInputAmount(&s.br, bit_reader::BROTLI_SHORT_FILL_BIT_WINDOW_READ)) { | 679 | 22.9k | s.symbol = symbol; | 680 | 22.9k | s.repeat = repeat; | 681 | 22.9k | s.prev_code_len = prev_code_len; | 682 | 22.9k | s.repeat_code_len = repeat_code_len; | 683 | 22.9k | s.space = space; | 684 | 22.9k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 685 | 560k | } | 686 | 560k | bit_reader::BrotliFillBitWindow16(&mut s.br, input); | 687 | 560k | p_index += | 688 | 560k | bit_reader::BrotliGetBitsUnmasked(&s.br) & | 689 | 560k | bit_reader::BitMask(huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as u32) as u64; | 690 | 560k | let p = fast!((s.table)[p_index as usize]); | 691 | 560k | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32); /* Use 1..5 bits */ | 692 | 560k | code_len = p.value as u32; /* code_len == 0..17 */ | 693 | 560k | if (code_len < kCodeLengthRepeatCode) { | 694 | 504k | ProcessSingleCodeLength(code_len, | 695 | 504k | &mut symbol, | 696 | 504k | &mut repeat, | 697 | 504k | &mut space, | 698 | 504k | &mut prev_code_len, | 699 | 504k | &mut s.symbols_lists_array, | 700 | 504k | s.symbol_lists_index as usize, | 701 | 504k | &mut s.code_length_histo[..], | 702 | 504k | &mut s.next_symbol[..]); | 703 | 504k | } else { | 704 | | // code_len == 16..17, extra_bits == 2..3 | 705 | 56.3k | let extra_bits: u32 = if code_len == kCodeLengthRepeatCode { | 706 | 29.3k | 2 | 707 | | } else { | 708 | 27.0k | 3 | 709 | | }; | 710 | 56.3k | let repeat_delta: u32 = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32 & | 711 | 56.3k | bit_reader::BitMask(extra_bits); | 712 | 56.3k | bit_reader::BrotliDropBits(&mut s.br, extra_bits); | 713 | 56.3k | ProcessRepeatedCodeLength(code_len, | 714 | 56.3k | repeat_delta, | 715 | 56.3k | alphabet_size, | 716 | 56.3k | &mut symbol, | 717 | 56.3k | &mut repeat, | 718 | 56.3k | &mut space, | 719 | 56.3k | &mut prev_code_len, | 720 | 56.3k | &mut repeat_code_len, | 721 | 56.3k | &mut s.symbols_lists_array, | 722 | 56.3k | s.symbol_lists_index as usize, | 723 | 56.3k | &mut s.code_length_histo[..], | 724 | 56.3k | &mut s.next_symbol[..]); | 725 | | } | 726 | | } | 727 | 11.0k | s.space = space; | 728 | 11.0k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 729 | 36.3k | } |
brotli_decompressor::decode::ReadSymbolCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 659 | 27.9k | fn ReadSymbolCodeLengths<AllocU8: alloc::Allocator<u8>, | 660 | 27.9k | AllocU32: alloc::Allocator<u32>, | 661 | 27.9k | AllocHC: alloc::Allocator<HuffmanCode>> | 662 | 27.9k | (alphabet_size: u32, | 663 | 27.9k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 664 | 27.9k | input: &[u8]) | 665 | 27.9k | -> BrotliDecoderErrorCode { | 666 | | | 667 | 27.9k | let mut symbol = s.symbol; | 668 | 27.9k | let mut repeat = s.repeat; | 669 | 27.9k | let mut space = s.space; | 670 | 27.9k | let mut prev_code_len: u32 = s.prev_code_len; | 671 | 27.9k | let mut repeat_code_len: u32 = s.repeat_code_len; | 672 | 27.9k | if (!bit_reader::BrotliWarmupBitReader(&mut s.br, input)) { | 673 | 4.13k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 674 | 23.8k | } | 675 | 463k | while (symbol < alphabet_size && space > 0) { | 676 | 448k | let mut p_index = 0; | 677 | | let code_len: u32; | 678 | 448k | if (!bit_reader::BrotliCheckInputAmount(&s.br, bit_reader::BROTLI_SHORT_FILL_BIT_WINDOW_READ)) { | 679 | 8.68k | s.symbol = symbol; | 680 | 8.68k | s.repeat = repeat; | 681 | 8.68k | s.prev_code_len = prev_code_len; | 682 | 8.68k | s.repeat_code_len = repeat_code_len; | 683 | 8.68k | s.space = space; | 684 | 8.68k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 685 | 439k | } | 686 | 439k | bit_reader::BrotliFillBitWindow16(&mut s.br, input); | 687 | 439k | p_index += | 688 | 439k | bit_reader::BrotliGetBitsUnmasked(&s.br) & | 689 | 439k | bit_reader::BitMask(huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as u32) as u64; | 690 | 439k | let p = fast!((s.table)[p_index as usize]); | 691 | 439k | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32); /* Use 1..5 bits */ | 692 | 439k | code_len = p.value as u32; /* code_len == 0..17 */ | 693 | 439k | if (code_len < kCodeLengthRepeatCode) { | 694 | 405k | ProcessSingleCodeLength(code_len, | 695 | 405k | &mut symbol, | 696 | 405k | &mut repeat, | 697 | 405k | &mut space, | 698 | 405k | &mut prev_code_len, | 699 | 405k | &mut s.symbols_lists_array, | 700 | 405k | s.symbol_lists_index as usize, | 701 | 405k | &mut s.code_length_histo[..], | 702 | 405k | &mut s.next_symbol[..]); | 703 | 405k | } else { | 704 | | // code_len == 16..17, extra_bits == 2..3 | 705 | 34.6k | let extra_bits: u32 = if code_len == kCodeLengthRepeatCode { | 706 | 15.8k | 2 | 707 | | } else { | 708 | 18.8k | 3 | 709 | | }; | 710 | 34.6k | let repeat_delta: u32 = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32 & | 711 | 34.6k | bit_reader::BitMask(extra_bits); | 712 | 34.6k | bit_reader::BrotliDropBits(&mut s.br, extra_bits); | 713 | 34.6k | ProcessRepeatedCodeLength(code_len, | 714 | 34.6k | repeat_delta, | 715 | 34.6k | alphabet_size, | 716 | 34.6k | &mut symbol, | 717 | 34.6k | &mut repeat, | 718 | 34.6k | &mut space, | 719 | 34.6k | &mut prev_code_len, | 720 | 34.6k | &mut repeat_code_len, | 721 | 34.6k | &mut s.symbols_lists_array, | 722 | 34.6k | s.symbol_lists_index as usize, | 723 | 34.6k | &mut s.code_length_histo[..], | 724 | 34.6k | &mut s.next_symbol[..]); | 725 | | } | 726 | | } | 727 | 15.1k | s.space = space; | 728 | 15.1k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 729 | 27.9k | } |
|
730 | | |
731 | 97.5k | fn SafeReadSymbolCodeLengths<AllocU8: alloc::Allocator<u8>, |
732 | 97.5k | AllocU32: alloc::Allocator<u32>, |
733 | 97.5k | AllocHC: alloc::Allocator<HuffmanCode>> |
734 | 97.5k | (alphabet_size: u32, |
735 | 97.5k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
736 | 97.5k | input: &[u8]) |
737 | 97.5k | -> BrotliDecoderErrorCode { |
738 | 860k | while (s.symbol < alphabet_size && s.space > 0) { |
739 | 842k | let mut p_index = 0; |
740 | | let code_len: u32; |
741 | 842k | let mut bits: u32 = 0; |
742 | 842k | let available_bits: u32 = bit_reader::BrotliGetAvailableBits(&s.br); |
743 | 842k | if (available_bits != 0) { |
744 | 775k | bits = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32; |
745 | 775k | } |
746 | 842k | p_index += bits & |
747 | 842k | bit_reader::BitMask(huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as u32); |
748 | 842k | let p = fast!((s.table)[p_index as usize]); |
749 | 842k | if (p.bits as u32 > available_bits) { |
750 | | // pullMoreInput; |
751 | 97.4k | if (!bit_reader::BrotliPullByte(&mut s.br, input)) { |
752 | 62.4k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
753 | 34.9k | } |
754 | 34.9k | continue; |
755 | 745k | } |
756 | 745k | code_len = p.value as u32; /* code_len == 0..17 */ |
757 | 745k | if (code_len < kCodeLengthRepeatCode) { |
758 | 667k | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32); |
759 | 667k | ProcessSingleCodeLength(code_len, |
760 | 667k | &mut s.symbol, |
761 | 667k | &mut s.repeat, |
762 | 667k | &mut s.space, |
763 | 667k | &mut s.prev_code_len, |
764 | 667k | &mut s.symbols_lists_array, |
765 | 667k | s.symbol_lists_index as usize, |
766 | 667k | &mut s.code_length_histo[..], |
767 | 667k | &mut s.next_symbol[..]); |
768 | 667k | } else { |
769 | | // code_len == 16..17, extra_bits == 2..3 |
770 | 77.9k | let extra_bits: u32 = code_len - 14; |
771 | 77.9k | let repeat_delta: u32 = (bits >> p.bits) & bit_reader::BitMask(extra_bits); |
772 | 77.9k | if (available_bits < p.bits as u32 + extra_bits) { |
773 | | // pullMoreInput; |
774 | 22.0k | if (!bit_reader::BrotliPullByte(&mut s.br, input)) { |
775 | 16.7k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
776 | 5.29k | } |
777 | 5.29k | continue; |
778 | 55.8k | } |
779 | 55.8k | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32 + extra_bits); |
780 | 55.8k | ProcessRepeatedCodeLength(code_len, |
781 | 55.8k | repeat_delta, |
782 | 55.8k | alphabet_size, |
783 | 55.8k | &mut s.symbol, |
784 | 55.8k | &mut s.repeat, |
785 | 55.8k | &mut s.space, |
786 | 55.8k | &mut s.prev_code_len, |
787 | 55.8k | &mut s.repeat_code_len, |
788 | 55.8k | &mut s.symbols_lists_array, |
789 | 55.8k | s.symbol_lists_index as usize, |
790 | 55.8k | &mut s.code_length_histo[..], |
791 | 55.8k | &mut s.next_symbol[..]); |
792 | | } |
793 | | } |
794 | 18.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS |
795 | 97.5k | } brotli_decompressor::decode::SafeReadSymbolCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 731 | 59.4k | fn SafeReadSymbolCodeLengths<AllocU8: alloc::Allocator<u8>, | 732 | 59.4k | AllocU32: alloc::Allocator<u32>, | 733 | 59.4k | AllocHC: alloc::Allocator<HuffmanCode>> | 734 | 59.4k | (alphabet_size: u32, | 735 | 59.4k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 736 | 59.4k | input: &[u8]) | 737 | 59.4k | -> BrotliDecoderErrorCode { | 738 | 379k | while (s.symbol < alphabet_size && s.space > 0) { | 739 | 372k | let mut p_index = 0; | 740 | | let code_len: u32; | 741 | 372k | let mut bits: u32 = 0; | 742 | 372k | let available_bits: u32 = bit_reader::BrotliGetAvailableBits(&s.br); | 743 | 372k | if (available_bits != 0) { | 744 | 335k | bits = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32; | 745 | 335k | } | 746 | 372k | p_index += bits & | 747 | 372k | bit_reader::BitMask(huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as u32); | 748 | 372k | let p = fast!((s.table)[p_index as usize]); | 749 | 372k | if (p.bits as u32 > available_bits) { | 750 | | // pullMoreInput; | 751 | 49.6k | if (!bit_reader::BrotliPullByte(&mut s.br, input)) { | 752 | 38.1k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 753 | 11.4k | } | 754 | 11.4k | continue; | 755 | 322k | } | 756 | 322k | code_len = p.value as u32; /* code_len == 0..17 */ | 757 | 322k | if (code_len < kCodeLengthRepeatCode) { | 758 | 287k | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32); | 759 | 287k | ProcessSingleCodeLength(code_len, | 760 | 287k | &mut s.symbol, | 761 | 287k | &mut s.repeat, | 762 | 287k | &mut s.space, | 763 | 287k | &mut s.prev_code_len, | 764 | 287k | &mut s.symbols_lists_array, | 765 | 287k | s.symbol_lists_index as usize, | 766 | 287k | &mut s.code_length_histo[..], | 767 | 287k | &mut s.next_symbol[..]); | 768 | 287k | } else { | 769 | | // code_len == 16..17, extra_bits == 2..3 | 770 | 35.2k | let extra_bits: u32 = code_len - 14; | 771 | 35.2k | let repeat_delta: u32 = (bits >> p.bits) & bit_reader::BitMask(extra_bits); | 772 | 35.2k | if (available_bits < p.bits as u32 + extra_bits) { | 773 | | // pullMoreInput; | 774 | 15.7k | if (!bit_reader::BrotliPullByte(&mut s.br, input)) { | 775 | 14.4k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 776 | 1.27k | } | 777 | 1.27k | continue; | 778 | 19.5k | } | 779 | 19.5k | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32 + extra_bits); | 780 | 19.5k | ProcessRepeatedCodeLength(code_len, | 781 | 19.5k | repeat_delta, | 782 | 19.5k | alphabet_size, | 783 | 19.5k | &mut s.symbol, | 784 | 19.5k | &mut s.repeat, | 785 | 19.5k | &mut s.space, | 786 | 19.5k | &mut s.prev_code_len, | 787 | 19.5k | &mut s.repeat_code_len, | 788 | 19.5k | &mut s.symbols_lists_array, | 789 | 19.5k | s.symbol_lists_index as usize, | 790 | 19.5k | &mut s.code_length_histo[..], | 791 | 19.5k | &mut s.next_symbol[..]); | 792 | | } | 793 | | } | 794 | 6.85k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 795 | 59.4k | } |
Unexecuted instantiation: brotli_decompressor::decode::SafeReadSymbolCodeLengths::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::SafeReadSymbolCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::SafeReadSymbolCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 731 | 25.3k | fn SafeReadSymbolCodeLengths<AllocU8: alloc::Allocator<u8>, | 732 | 25.3k | AllocU32: alloc::Allocator<u32>, | 733 | 25.3k | AllocHC: alloc::Allocator<HuffmanCode>> | 734 | 25.3k | (alphabet_size: u32, | 735 | 25.3k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 736 | 25.3k | input: &[u8]) | 737 | 25.3k | -> BrotliDecoderErrorCode { | 738 | 339k | while (s.symbol < alphabet_size && s.space > 0) { | 739 | 331k | let mut p_index = 0; | 740 | | let code_len: u32; | 741 | 331k | let mut bits: u32 = 0; | 742 | 331k | let available_bits: u32 = bit_reader::BrotliGetAvailableBits(&s.br); | 743 | 331k | if (available_bits != 0) { | 744 | 310k | bits = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32; | 745 | 310k | } | 746 | 331k | p_index += bits & | 747 | 331k | bit_reader::BitMask(huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as u32); | 748 | 331k | let p = fast!((s.table)[p_index as usize]); | 749 | 331k | if (p.bits as u32 > available_bits) { | 750 | | // pullMoreInput; | 751 | 35.5k | if (!bit_reader::BrotliPullByte(&mut s.br, input)) { | 752 | 16.3k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 753 | 19.2k | } | 754 | 19.2k | continue; | 755 | 296k | } | 756 | 296k | code_len = p.value as u32; /* code_len == 0..17 */ | 757 | 296k | if (code_len < kCodeLengthRepeatCode) { | 758 | 264k | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32); | 759 | 264k | ProcessSingleCodeLength(code_len, | 760 | 264k | &mut s.symbol, | 761 | 264k | &mut s.repeat, | 762 | 264k | &mut s.space, | 763 | 264k | &mut s.prev_code_len, | 764 | 264k | &mut s.symbols_lists_array, | 765 | 264k | s.symbol_lists_index as usize, | 766 | 264k | &mut s.code_length_histo[..], | 767 | 264k | &mut s.next_symbol[..]); | 768 | 264k | } else { | 769 | | // code_len == 16..17, extra_bits == 2..3 | 770 | 31.7k | let extra_bits: u32 = code_len - 14; | 771 | 31.7k | let repeat_delta: u32 = (bits >> p.bits) & bit_reader::BitMask(extra_bits); | 772 | 31.7k | if (available_bits < p.bits as u32 + extra_bits) { | 773 | | // pullMoreInput; | 774 | 4.56k | if (!bit_reader::BrotliPullByte(&mut s.br, input)) { | 775 | 1.03k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 776 | 3.52k | } | 777 | 3.52k | continue; | 778 | 27.2k | } | 779 | 27.2k | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32 + extra_bits); | 780 | 27.2k | ProcessRepeatedCodeLength(code_len, | 781 | 27.2k | repeat_delta, | 782 | 27.2k | alphabet_size, | 783 | 27.2k | &mut s.symbol, | 784 | 27.2k | &mut s.repeat, | 785 | 27.2k | &mut s.space, | 786 | 27.2k | &mut s.prev_code_len, | 787 | 27.2k | &mut s.repeat_code_len, | 788 | 27.2k | &mut s.symbols_lists_array, | 789 | 27.2k | s.symbol_lists_index as usize, | 790 | 27.2k | &mut s.code_length_histo[..], | 791 | 27.2k | &mut s.next_symbol[..]); | 792 | | } | 793 | | } | 794 | 7.91k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 795 | 25.3k | } |
brotli_decompressor::decode::SafeReadSymbolCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 731 | 12.8k | fn SafeReadSymbolCodeLengths<AllocU8: alloc::Allocator<u8>, | 732 | 12.8k | AllocU32: alloc::Allocator<u32>, | 733 | 12.8k | AllocHC: alloc::Allocator<HuffmanCode>> | 734 | 12.8k | (alphabet_size: u32, | 735 | 12.8k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 736 | 12.8k | input: &[u8]) | 737 | 12.8k | -> BrotliDecoderErrorCode { | 738 | 141k | while (s.symbol < alphabet_size && s.space > 0) { | 739 | 138k | let mut p_index = 0; | 740 | | let code_len: u32; | 741 | 138k | let mut bits: u32 = 0; | 742 | 138k | let available_bits: u32 = bit_reader::BrotliGetAvailableBits(&s.br); | 743 | 138k | if (available_bits != 0) { | 744 | 129k | bits = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32; | 745 | 129k | } | 746 | 138k | p_index += bits & | 747 | 138k | bit_reader::BitMask(huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as u32); | 748 | 138k | let p = fast!((s.table)[p_index as usize]); | 749 | 138k | if (p.bits as u32 > available_bits) { | 750 | | // pullMoreInput; | 751 | 12.2k | if (!bit_reader::BrotliPullByte(&mut s.br, input)) { | 752 | 8.00k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 753 | 4.24k | } | 754 | 4.24k | continue; | 755 | 125k | } | 756 | 125k | code_len = p.value as u32; /* code_len == 0..17 */ | 757 | 125k | if (code_len < kCodeLengthRepeatCode) { | 758 | 115k | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32); | 759 | 115k | ProcessSingleCodeLength(code_len, | 760 | 115k | &mut s.symbol, | 761 | 115k | &mut s.repeat, | 762 | 115k | &mut s.space, | 763 | 115k | &mut s.prev_code_len, | 764 | 115k | &mut s.symbols_lists_array, | 765 | 115k | s.symbol_lists_index as usize, | 766 | 115k | &mut s.code_length_histo[..], | 767 | 115k | &mut s.next_symbol[..]); | 768 | 115k | } else { | 769 | | // code_len == 16..17, extra_bits == 2..3 | 770 | 10.8k | let extra_bits: u32 = code_len - 14; | 771 | 10.8k | let repeat_delta: u32 = (bits >> p.bits) & bit_reader::BitMask(extra_bits); | 772 | 10.8k | if (available_bits < p.bits as u32 + extra_bits) { | 773 | | // pullMoreInput; | 774 | 1.76k | if (!bit_reader::BrotliPullByte(&mut s.br, input)) { | 775 | 1.26k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 776 | 505 | } | 777 | 505 | continue; | 778 | 9.04k | } | 779 | 9.04k | bit_reader::BrotliDropBits(&mut s.br, p.bits as u32 + extra_bits); | 780 | 9.04k | ProcessRepeatedCodeLength(code_len, | 781 | 9.04k | repeat_delta, | 782 | 9.04k | alphabet_size, | 783 | 9.04k | &mut s.symbol, | 784 | 9.04k | &mut s.repeat, | 785 | 9.04k | &mut s.space, | 786 | 9.04k | &mut s.prev_code_len, | 787 | 9.04k | &mut s.repeat_code_len, | 788 | 9.04k | &mut s.symbols_lists_array, | 789 | 9.04k | s.symbol_lists_index as usize, | 790 | 9.04k | &mut s.code_length_histo[..], | 791 | 9.04k | &mut s.next_symbol[..]); | 792 | | } | 793 | | } | 794 | 3.55k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 795 | 12.8k | } |
|
796 | | |
797 | | // Reads and decodes 15..18 codes using static prefix code. |
798 | | // Each code is 2..4 bits long. In total 30..72 bits are used. |
799 | 376k | fn ReadCodeLengthCodeLengths<AllocU8: alloc::Allocator<u8>, |
800 | 376k | AllocU32: alloc::Allocator<u32>, |
801 | 376k | AllocHC: alloc::Allocator<HuffmanCode>> |
802 | 376k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
803 | 376k | input: &[u8]) |
804 | 376k | -> BrotliDecoderErrorCode { |
805 | | |
806 | 376k | let mut num_codes: u32 = s.repeat; |
807 | 376k | let mut space: u32 = s.space; |
808 | 376k | let mut i = s.sub_loop_counter; |
809 | 1.31M | for code_length_code_order in |
810 | 376k | fast!((kCodeLengthCodeOrder)[s.sub_loop_counter as usize; CODE_LENGTH_CODES]).iter() { |
811 | 1.31M | let code_len_idx = *code_length_code_order; |
812 | 1.31M | let mut ix: u32 = 0; |
813 | | |
814 | 1.31M | if !bit_reader::BrotliSafeGetBits(&mut s.br, 4, &mut ix, input) { |
815 | 283k | mark_unlikely(); |
816 | 283k | let available_bits: u32 = bit_reader::BrotliGetAvailableBits(&s.br); |
817 | 283k | if (available_bits != 0) { |
818 | 105k | ix = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32 & 0xF; |
819 | 178k | } else { |
820 | 178k | ix = 0; |
821 | 178k | } |
822 | 283k | if (fast!((kCodeLengthPrefixLength)[ix as usize]) as u32 > available_bits) { |
823 | 273k | s.sub_loop_counter = i; |
824 | 273k | s.repeat = num_codes; |
825 | 273k | s.space = space; |
826 | 273k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX; |
827 | 273k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
828 | 10.3k | } |
829 | 1.03M | } |
830 | | BROTLI_LOG_UINT!(ix); |
831 | 1.04M | let v: u32 = fast!((kCodeLengthPrefixValue)[ix as usize]) as u32; |
832 | 1.04M | bit_reader::BrotliDropBits(&mut s.br, |
833 | 1.04M | fast!((kCodeLengthPrefixLength)[ix as usize]) as u32); |
834 | 1.04M | fast_mut!((s.code_length_code_lengths)[code_len_idx as usize]) = v as u8; |
835 | | BROTLI_LOG_ARRAY_INDEX!(s.code_length_code_lengths, code_len_idx); |
836 | 1.04M | if v != 0 { |
837 | 563k | space = space.wrapping_sub(32 >> v); |
838 | 563k | num_codes += 1; |
839 | 563k | fast_mut!((s.code_length_histo)[v as usize]) += 1; |
840 | 563k | if space.wrapping_sub(1) >= 32 { |
841 | | // space is 0 or wrapped around |
842 | 86.5k | break; |
843 | 477k | } |
844 | 478k | } |
845 | 956k | i += 1; |
846 | | } |
847 | 103k | if (!(num_codes == 1 || space == 0)) { |
848 | 17.9k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_CL_SPACE; |
849 | 85.3k | } |
850 | 85.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS |
851 | 376k | } brotli_decompressor::decode::ReadCodeLengthCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 799 | 235k | fn ReadCodeLengthCodeLengths<AllocU8: alloc::Allocator<u8>, | 800 | 235k | AllocU32: alloc::Allocator<u32>, | 801 | 235k | AllocHC: alloc::Allocator<HuffmanCode>> | 802 | 235k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 803 | 235k | input: &[u8]) | 804 | 235k | -> BrotliDecoderErrorCode { | 805 | | | 806 | 235k | let mut num_codes: u32 = s.repeat; | 807 | 235k | let mut space: u32 = s.space; | 808 | 235k | let mut i = s.sub_loop_counter; | 809 | 690k | for code_length_code_order in | 810 | 235k | fast!((kCodeLengthCodeOrder)[s.sub_loop_counter as usize; CODE_LENGTH_CODES]).iter() { | 811 | 690k | let code_len_idx = *code_length_code_order; | 812 | 690k | let mut ix: u32 = 0; | 813 | | | 814 | 690k | if !bit_reader::BrotliSafeGetBits(&mut s.br, 4, &mut ix, input) { | 815 | 188k | mark_unlikely(); | 816 | 188k | let available_bits: u32 = bit_reader::BrotliGetAvailableBits(&s.br); | 817 | 188k | if (available_bits != 0) { | 818 | 91.1k | ix = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32 & 0xF; | 819 | 97.1k | } else { | 820 | 97.1k | ix = 0; | 821 | 97.1k | } | 822 | 188k | if (fast!((kCodeLengthPrefixLength)[ix as usize]) as u32 > available_bits) { | 823 | 184k | s.sub_loop_counter = i; | 824 | 184k | s.repeat = num_codes; | 825 | 184k | s.space = space; | 826 | 184k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX; | 827 | 184k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 828 | 3.35k | } | 829 | 502k | } | 830 | | BROTLI_LOG_UINT!(ix); | 831 | 505k | let v: u32 = fast!((kCodeLengthPrefixValue)[ix as usize]) as u32; | 832 | 505k | bit_reader::BrotliDropBits(&mut s.br, | 833 | 505k | fast!((kCodeLengthPrefixLength)[ix as usize]) as u32); | 834 | 505k | fast_mut!((s.code_length_code_lengths)[code_len_idx as usize]) = v as u8; | 835 | | BROTLI_LOG_ARRAY_INDEX!(s.code_length_code_lengths, code_len_idx); | 836 | 505k | if v != 0 { | 837 | 268k | space = space.wrapping_sub(32 >> v); | 838 | 268k | num_codes += 1; | 839 | 268k | fast_mut!((s.code_length_histo)[v as usize]) += 1; | 840 | 268k | if space.wrapping_sub(1) >= 32 { | 841 | | // space is 0 or wrapped around | 842 | 42.5k | break; | 843 | 226k | } | 844 | 236k | } | 845 | 462k | i += 1; | 846 | | } | 847 | 50.2k | if (!(num_codes == 1 || space == 0)) { | 848 | 6.91k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_CL_SPACE; | 849 | 43.3k | } | 850 | 43.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 851 | 235k | } |
Unexecuted instantiation: brotli_decompressor::decode::ReadCodeLengthCodeLengths::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::ReadCodeLengthCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::ReadCodeLengthCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 799 | 33.4k | fn ReadCodeLengthCodeLengths<AllocU8: alloc::Allocator<u8>, | 800 | 33.4k | AllocU32: alloc::Allocator<u32>, | 801 | 33.4k | AllocHC: alloc::Allocator<HuffmanCode>> | 802 | 33.4k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 803 | 33.4k | input: &[u8]) | 804 | 33.4k | -> BrotliDecoderErrorCode { | 805 | | | 806 | 33.4k | let mut num_codes: u32 = s.repeat; | 807 | 33.4k | let mut space: u32 = s.space; | 808 | 33.4k | let mut i = s.sub_loop_counter; | 809 | 286k | for code_length_code_order in | 810 | 33.4k | fast!((kCodeLengthCodeOrder)[s.sub_loop_counter as usize; CODE_LENGTH_CODES]).iter() { | 811 | 286k | let code_len_idx = *code_length_code_order; | 812 | 286k | let mut ix: u32 = 0; | 813 | | | 814 | 286k | if !bit_reader::BrotliSafeGetBits(&mut s.br, 4, &mut ix, input) { | 815 | 10.9k | mark_unlikely(); | 816 | 10.9k | let available_bits: u32 = bit_reader::BrotliGetAvailableBits(&s.br); | 817 | 10.9k | if (available_bits != 0) { | 818 | 7.77k | ix = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32 & 0xF; | 819 | 7.77k | } else { | 820 | 3.19k | ix = 0; | 821 | 3.19k | } | 822 | 10.9k | if (fast!((kCodeLengthPrefixLength)[ix as usize]) as u32 > available_bits) { | 823 | 5.89k | s.sub_loop_counter = i; | 824 | 5.89k | s.repeat = num_codes; | 825 | 5.89k | s.space = space; | 826 | 5.89k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX; | 827 | 5.89k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 828 | 5.07k | } | 829 | 275k | } | 830 | | BROTLI_LOG_UINT!(ix); | 831 | 280k | let v: u32 = fast!((kCodeLengthPrefixValue)[ix as usize]) as u32; | 832 | 280k | bit_reader::BrotliDropBits(&mut s.br, | 833 | 280k | fast!((kCodeLengthPrefixLength)[ix as usize]) as u32); | 834 | 280k | fast_mut!((s.code_length_code_lengths)[code_len_idx as usize]) = v as u8; | 835 | | BROTLI_LOG_ARRAY_INDEX!(s.code_length_code_lengths, code_len_idx); | 836 | 280k | if v != 0 { | 837 | 167k | space = space.wrapping_sub(32 >> v); | 838 | 167k | num_codes += 1; | 839 | 167k | fast_mut!((s.code_length_histo)[v as usize]) += 1; | 840 | 167k | if space.wrapping_sub(1) >= 32 { | 841 | | // space is 0 or wrapped around | 842 | 23.4k | break; | 843 | 143k | } | 844 | 113k | } | 845 | 257k | i += 1; | 846 | | } | 847 | 27.5k | if (!(num_codes == 1 || space == 0)) { | 848 | 5.87k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_CL_SPACE; | 849 | 21.6k | } | 850 | 21.6k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 851 | 33.4k | } |
brotli_decompressor::decode::ReadCodeLengthCodeLengths::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 799 | 108k | fn ReadCodeLengthCodeLengths<AllocU8: alloc::Allocator<u8>, | 800 | 108k | AllocU32: alloc::Allocator<u32>, | 801 | 108k | AllocHC: alloc::Allocator<HuffmanCode>> | 802 | 108k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 803 | 108k | input: &[u8]) | 804 | 108k | -> BrotliDecoderErrorCode { | 805 | | | 806 | 108k | let mut num_codes: u32 = s.repeat; | 807 | 108k | let mut space: u32 = s.space; | 808 | 108k | let mut i = s.sub_loop_counter; | 809 | 338k | for code_length_code_order in | 810 | 108k | fast!((kCodeLengthCodeOrder)[s.sub_loop_counter as usize; CODE_LENGTH_CODES]).iter() { | 811 | 338k | let code_len_idx = *code_length_code_order; | 812 | 338k | let mut ix: u32 = 0; | 813 | | | 814 | 338k | if !bit_reader::BrotliSafeGetBits(&mut s.br, 4, &mut ix, input) { | 815 | 84.4k | mark_unlikely(); | 816 | 84.4k | let available_bits: u32 = bit_reader::BrotliGetAvailableBits(&s.br); | 817 | 84.4k | if (available_bits != 0) { | 818 | 6.56k | ix = bit_reader::BrotliGetBitsUnmasked(&s.br) as u32 & 0xF; | 819 | 77.9k | } else { | 820 | 77.9k | ix = 0; | 821 | 77.9k | } | 822 | 84.4k | if (fast!((kCodeLengthPrefixLength)[ix as usize]) as u32 > available_bits) { | 823 | 82.5k | s.sub_loop_counter = i; | 824 | 82.5k | s.repeat = num_codes; | 825 | 82.5k | s.space = space; | 826 | 82.5k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX; | 827 | 82.5k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 828 | 1.95k | } | 829 | 254k | } | 830 | | BROTLI_LOG_UINT!(ix); | 831 | 256k | let v: u32 = fast!((kCodeLengthPrefixValue)[ix as usize]) as u32; | 832 | 256k | bit_reader::BrotliDropBits(&mut s.br, | 833 | 256k | fast!((kCodeLengthPrefixLength)[ix as usize]) as u32); | 834 | 256k | fast_mut!((s.code_length_code_lengths)[code_len_idx as usize]) = v as u8; | 835 | | BROTLI_LOG_ARRAY_INDEX!(s.code_length_code_lengths, code_len_idx); | 836 | 256k | if v != 0 { | 837 | 127k | space = space.wrapping_sub(32 >> v); | 838 | 127k | num_codes += 1; | 839 | 127k | fast_mut!((s.code_length_histo)[v as usize]) += 1; | 840 | 127k | if space.wrapping_sub(1) >= 32 { | 841 | | // space is 0 or wrapped around | 842 | 20.5k | break; | 843 | 107k | } | 844 | 128k | } | 845 | 235k | i += 1; | 846 | | } | 847 | 25.5k | if (!(num_codes == 1 || space == 0)) { | 848 | 5.12k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_CL_SPACE; | 849 | 20.3k | } | 850 | 20.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 851 | 108k | } |
|
852 | | |
853 | | |
854 | | // Decodes the Huffman tables. |
855 | | // There are 2 scenarios: |
856 | | // A) Huffman code contains only few symbols (1..4). Those symbols are read |
857 | | // directly; their code lengths are defined by the number of symbols. |
858 | | // For this scenario 4 - 49 bits will be read. |
859 | | // |
860 | | // B) 2-phase decoding: |
861 | | // B.1) Small Huffman table is decoded; it is specified with code lengths |
862 | | // encoded with predefined entropy code. 32 - 74 bits are used. |
863 | | // B.2) Decoded table is used to decode code lengths of symbols in resulting |
864 | | // Huffman table. In worst case 3520 bits are read. |
865 | | // |
866 | 739k | fn ReadHuffmanCode<AllocU8: alloc::Allocator<u8>, |
867 | 739k | AllocU32: alloc::Allocator<u32>, |
868 | 739k | AllocHC: alloc::Allocator<HuffmanCode>> |
869 | 739k | (mut alphabet_size: u32, |
870 | 739k | max_symbol: u32, |
871 | 739k | table: &mut [HuffmanCode], |
872 | 739k | offset: usize, |
873 | 739k | opt_table_size: Option<&mut u32>, |
874 | 739k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
875 | 739k | input: &[u8]) |
876 | 739k | -> BrotliDecoderErrorCode { |
877 | | // Unnecessary masking, but might be good for safety. |
878 | 739k | alphabet_size &= 0x7ff; |
879 | | // State machine |
880 | | loop { |
881 | 1.58M | match s.substate_huffman { |
882 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE => { |
883 | 337k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut s.sub_loop_counter, input) { |
884 | 10.1k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
885 | 327k | } |
886 | | |
887 | | BROTLI_LOG_UINT!(s.sub_loop_counter); |
888 | | // The value is used as follows: |
889 | | // 1 for simple code; |
890 | | // 0 for no skipping, 2 skips 2 code lengths, 3 skips 3 code lengths |
891 | 327k | if (s.sub_loop_counter != 1) { |
892 | 108k | s.space = 32; |
893 | 108k | s.repeat = 0; /* num_codes */ |
894 | 108k | let max_code_len_len = huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as usize + 1; |
895 | 653k | for code_length_histo in fast_mut!((s.code_length_histo)[0;max_code_len_len]).iter_mut() { |
896 | 653k | *code_length_histo = 0; // memset |
897 | 653k | } |
898 | 1.96M | for code_length_code_length in s.code_length_code_lengths[..].iter_mut() { |
899 | 1.96M | *code_length_code_length = 0; |
900 | 1.96M | } |
901 | 108k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX; |
902 | | // goto Complex; |
903 | 108k | continue; |
904 | 218k | } |
905 | 218k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE; |
906 | | // No break, transit to the next state. |
907 | | } |
908 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE => { |
909 | | // Read symbols, codes & code lengths directly. |
910 | 223k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut s.symbol, input)) { |
911 | | // num_symbols |
912 | 4.79k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE; |
913 | 4.79k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
914 | 218k | } |
915 | 218k | s.sub_loop_counter = 0; |
916 | | // No break, transit to the next state. |
917 | 218k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ; |
918 | | } |
919 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ => { |
920 | 270k | let result = ReadSimpleHuffmanSymbols(alphabet_size, max_symbol, s, input); |
921 | 270k | match result { |
922 | 213k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
923 | 56.7k | _ => return result, |
924 | | } |
925 | | // No break, transit to the next state. |
926 | 213k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD; |
927 | | } |
928 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD => { |
929 | | let table_size: u32; |
930 | 221k | if (s.symbol == 3) { |
931 | 39.0k | let mut bits: u32 = 0; |
932 | 39.0k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input)) { |
933 | 8.13k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD; |
934 | 8.13k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
935 | 30.9k | } |
936 | 30.9k | s.symbol += bits; |
937 | 182k | } |
938 | | BROTLI_LOG_UINT!(s.symbol); |
939 | 213k | table_size = huffman::BrotliBuildSimpleHuffmanTable(&mut table[offset..], |
940 | 213k | HUFFMAN_TABLE_BITS as i32, |
941 | 213k | &s.symbols_lists_array[..], |
942 | 213k | s.symbol); |
943 | 213k | if let Some(opt_table_size_ref) = opt_table_size { |
944 | 130k | *opt_table_size_ref = table_size |
945 | 83.2k | } |
946 | 213k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE; |
947 | 213k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
948 | | } |
949 | | |
950 | | // Decode Huffman-coded code lengths. |
951 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX => { |
952 | | |
953 | 376k | let result = ReadCodeLengthCodeLengths(s, input); |
954 | 376k | match result { |
955 | 85.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
956 | 291k | _ => return result, |
957 | | } |
958 | 85.3k | huffman::BrotliBuildCodeLengthsHuffmanTable(&mut s.table, |
959 | 85.3k | &s.code_length_code_lengths, |
960 | 85.3k | &s.code_length_histo); |
961 | 1.36M | for code_length_histo in s.code_length_histo[..].iter_mut() { |
962 | 1.36M | *code_length_histo = 0; // memset |
963 | 1.36M | } |
964 | | |
965 | 85.3k | let max_code_length = huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH as usize + 1; |
966 | 1.36M | for (i, next_symbol_mut) in fast_mut!((s.next_symbol)[0; max_code_length]) |
967 | 85.3k | .iter_mut() |
968 | 1.36M | .enumerate() { |
969 | 1.36M | *next_symbol_mut = i as i32 - (max_code_length as i32); |
970 | 1.36M | fast_mut!((s.symbols_lists_array)[(s.symbol_lists_index as i32 |
971 | 1.36M | + i as i32 |
972 | 1.36M | - (max_code_length as i32)) as usize]) = 0xFFFF; |
973 | 1.36M | } |
974 | | |
975 | 85.3k | s.symbol = 0; |
976 | 85.3k | s.prev_code_len = kDefaultCodeLength; |
977 | 85.3k | s.repeat = 0; |
978 | 85.3k | s.repeat_code_len = 0; |
979 | 85.3k | s.space = 32768; |
980 | | // No break, transit to the next state. |
981 | 85.3k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS; |
982 | | } |
983 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS => { |
984 | | let table_size: u32; |
985 | 154k | let mut result = ReadSymbolCodeLengths(max_symbol, s, input); |
986 | 154k | if let BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT = result { |
987 | 97.5k | result = SafeReadSymbolCodeLengths(max_symbol, s, input) |
988 | 57.3k | } |
989 | 154k | match result { |
990 | 75.6k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
991 | 79.2k | _ => return result, |
992 | | } |
993 | | |
994 | 75.6k | if (s.space != 0) { |
995 | | BROTLI_LOG!("[ReadHuffmanCode] space = %d\n", s.space); |
996 | 10.5k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE; |
997 | 65.0k | } |
998 | 65.0k | table_size = huffman::BrotliBuildHuffmanTable(fast_mut!((table)[offset;]), |
999 | 65.0k | HUFFMAN_TABLE_BITS as i32, |
1000 | 65.0k | &s.symbols_lists_array[..], |
1001 | 65.0k | s.symbol_lists_index, |
1002 | 65.0k | &mut s.code_length_histo); |
1003 | 65.0k | if let Some(opt_table_size_ref) = opt_table_size { |
1004 | 46.1k | *opt_table_size_ref = table_size |
1005 | 18.9k | } |
1006 | 65.0k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE; |
1007 | 65.0k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
1008 | | } |
1009 | | } |
1010 | | } |
1011 | 739k | } brotli_decompressor::decode::ReadHuffmanCode::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 866 | 459k | fn ReadHuffmanCode<AllocU8: alloc::Allocator<u8>, | 867 | 459k | AllocU32: alloc::Allocator<u32>, | 868 | 459k | AllocHC: alloc::Allocator<HuffmanCode>> | 869 | 459k | (mut alphabet_size: u32, | 870 | 459k | max_symbol: u32, | 871 | 459k | table: &mut [HuffmanCode], | 872 | 459k | offset: usize, | 873 | 459k | opt_table_size: Option<&mut u32>, | 874 | 459k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 875 | 459k | input: &[u8]) | 876 | 459k | -> BrotliDecoderErrorCode { | 877 | | // Unnecessary masking, but might be good for safety. | 878 | 459k | alphabet_size &= 0x7ff; | 879 | | // State machine | 880 | | loop { | 881 | 906k | match s.substate_huffman { | 882 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE => { | 883 | 178k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut s.sub_loop_counter, input) { | 884 | 7.33k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 885 | 171k | } | 886 | | | 887 | | BROTLI_LOG_UINT!(s.sub_loop_counter); | 888 | | // The value is used as follows: | 889 | | // 1 for simple code; | 890 | | // 0 for no skipping, 2 skips 2 code lengths, 3 skips 3 code lengths | 891 | 171k | if (s.sub_loop_counter != 1) { | 892 | 53.6k | s.space = 32; | 893 | 53.6k | s.repeat = 0; /* num_codes */ | 894 | 53.6k | let max_code_len_len = huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as usize + 1; | 895 | 321k | for code_length_histo in fast_mut!((s.code_length_histo)[0;max_code_len_len]).iter_mut() { | 896 | 321k | *code_length_histo = 0; // memset | 897 | 321k | } | 898 | 965k | for code_length_code_length in s.code_length_code_lengths[..].iter_mut() { | 899 | 965k | *code_length_code_length = 0; | 900 | 965k | } | 901 | 53.6k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX; | 902 | | // goto Complex; | 903 | 53.6k | continue; | 904 | 117k | } | 905 | 117k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE; | 906 | | // No break, transit to the next state. | 907 | | } | 908 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE => { | 909 | | // Read symbols, codes & code lengths directly. | 910 | 121k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut s.symbol, input)) { | 911 | | // num_symbols | 912 | 4.17k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE; | 913 | 4.17k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 914 | 117k | } | 915 | 117k | s.sub_loop_counter = 0; | 916 | | // No break, transit to the next state. | 917 | 117k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ; | 918 | | } | 919 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ => { | 920 | 159k | let result = ReadSimpleHuffmanSymbols(alphabet_size, max_symbol, s, input); | 921 | 159k | match result { | 922 | 114k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 923 | 44.2k | _ => return result, | 924 | | } | 925 | | // No break, transit to the next state. | 926 | 114k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD; | 927 | | } | 928 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD => { | 929 | | let table_size: u32; | 930 | 121k | if (s.symbol == 3) { | 931 | 26.6k | let mut bits: u32 = 0; | 932 | 26.6k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input)) { | 933 | 6.44k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD; | 934 | 6.44k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 935 | 20.1k | } | 936 | 20.1k | s.symbol += bits; | 937 | 94.6k | } | 938 | | BROTLI_LOG_UINT!(s.symbol); | 939 | 114k | table_size = huffman::BrotliBuildSimpleHuffmanTable(&mut table[offset..], | 940 | 114k | HUFFMAN_TABLE_BITS as i32, | 941 | 114k | &s.symbols_lists_array[..], | 942 | 114k | s.symbol); | 943 | 114k | if let Some(opt_table_size_ref) = opt_table_size { | 944 | 77.7k | *opt_table_size_ref = table_size | 945 | 37.0k | } | 946 | 114k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE; | 947 | 114k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 948 | | } | 949 | | | 950 | | // Decode Huffman-coded code lengths. | 951 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX => { | 952 | | | 953 | 235k | let result = ReadCodeLengthCodeLengths(s, input); | 954 | 235k | match result { | 955 | 43.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 956 | 191k | _ => return result, | 957 | | } | 958 | 43.3k | huffman::BrotliBuildCodeLengthsHuffmanTable(&mut s.table, | 959 | 43.3k | &s.code_length_code_lengths, | 960 | 43.3k | &s.code_length_histo); | 961 | 692k | for code_length_histo in s.code_length_histo[..].iter_mut() { | 962 | 692k | *code_length_histo = 0; // memset | 963 | 692k | } | 964 | | | 965 | 43.3k | let max_code_length = huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH as usize + 1; | 966 | 692k | for (i, next_symbol_mut) in fast_mut!((s.next_symbol)[0; max_code_length]) | 967 | 43.3k | .iter_mut() | 968 | 692k | .enumerate() { | 969 | 692k | *next_symbol_mut = i as i32 - (max_code_length as i32); | 970 | 692k | fast_mut!((s.symbols_lists_array)[(s.symbol_lists_index as i32 | 971 | 692k | + i as i32 | 972 | 692k | - (max_code_length as i32)) as usize]) = 0xFFFF; | 973 | 692k | } | 974 | | | 975 | 43.3k | s.symbol = 0; | 976 | 43.3k | s.prev_code_len = kDefaultCodeLength; | 977 | 43.3k | s.repeat = 0; | 978 | 43.3k | s.repeat_code_len = 0; | 979 | 43.3k | s.space = 32768; | 980 | | // No break, transit to the next state. | 981 | 43.3k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS; | 982 | | } | 983 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS => { | 984 | | let table_size: u32; | 985 | 90.5k | let mut result = ReadSymbolCodeLengths(max_symbol, s, input); | 986 | 90.5k | if let BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT = result { | 987 | 59.4k | result = SafeReadSymbolCodeLengths(max_symbol, s, input) | 988 | 31.0k | } | 989 | 90.5k | match result { | 990 | 37.9k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 991 | 52.5k | _ => return result, | 992 | | } | 993 | | | 994 | 37.9k | if (s.space != 0) { | 995 | | BROTLI_LOG!("[ReadHuffmanCode] space = %d\n", s.space); | 996 | 4.55k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE; | 997 | 33.3k | } | 998 | 33.3k | table_size = huffman::BrotliBuildHuffmanTable(fast_mut!((table)[offset;]), | 999 | 33.3k | HUFFMAN_TABLE_BITS as i32, | 1000 | 33.3k | &s.symbols_lists_array[..], | 1001 | 33.3k | s.symbol_lists_index, | 1002 | 33.3k | &mut s.code_length_histo); | 1003 | 33.3k | if let Some(opt_table_size_ref) = opt_table_size { | 1004 | 25.2k | *opt_table_size_ref = table_size | 1005 | 8.14k | } | 1006 | 33.3k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE; | 1007 | 33.3k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1008 | | } | 1009 | | } | 1010 | | } | 1011 | 459k | } |
Unexecuted instantiation: brotli_decompressor::decode::ReadHuffmanCode::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::ReadHuffmanCode::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::ReadHuffmanCode::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 866 | 110k | fn ReadHuffmanCode<AllocU8: alloc::Allocator<u8>, | 867 | 110k | AllocU32: alloc::Allocator<u32>, | 868 | 110k | AllocHC: alloc::Allocator<HuffmanCode>> | 869 | 110k | (mut alphabet_size: u32, | 870 | 110k | max_symbol: u32, | 871 | 110k | table: &mut [HuffmanCode], | 872 | 110k | offset: usize, | 873 | 110k | opt_table_size: Option<&mut u32>, | 874 | 110k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 875 | 110k | input: &[u8]) | 876 | 110k | -> BrotliDecoderErrorCode { | 877 | | // Unnecessary masking, but might be good for safety. | 878 | 110k | alphabet_size &= 0x7ff; | 879 | | // State machine | 880 | | loop { | 881 | 315k | match s.substate_huffman { | 882 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE => { | 883 | 81.7k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut s.sub_loop_counter, input) { | 884 | 1.37k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 885 | 80.3k | } | 886 | | | 887 | | BROTLI_LOG_UINT!(s.sub_loop_counter); | 888 | | // The value is used as follows: | 889 | | // 1 for simple code; | 890 | | // 0 for no skipping, 2 skips 2 code lengths, 3 skips 3 code lengths | 891 | 80.3k | if (s.sub_loop_counter != 1) { | 892 | 28.2k | s.space = 32; | 893 | 28.2k | s.repeat = 0; /* num_codes */ | 894 | 28.2k | let max_code_len_len = huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as usize + 1; | 895 | 169k | for code_length_histo in fast_mut!((s.code_length_histo)[0;max_code_len_len]).iter_mut() { | 896 | 169k | *code_length_histo = 0; // memset | 897 | 169k | } | 898 | 508k | for code_length_code_length in s.code_length_code_lengths[..].iter_mut() { | 899 | 508k | *code_length_code_length = 0; | 900 | 508k | } | 901 | 28.2k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX; | 902 | | // goto Complex; | 903 | 28.2k | continue; | 904 | 52.1k | } | 905 | 52.1k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE; | 906 | | // No break, transit to the next state. | 907 | | } | 908 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE => { | 909 | | // Read symbols, codes & code lengths directly. | 910 | 52.1k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut s.symbol, input)) { | 911 | | // num_symbols | 912 | 75 | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE; | 913 | 75 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 914 | 52.0k | } | 915 | 52.0k | s.sub_loop_counter = 0; | 916 | | // No break, transit to the next state. | 917 | 52.0k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ; | 918 | | } | 919 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ => { | 920 | 60.7k | let result = ReadSimpleHuffmanSymbols(alphabet_size, max_symbol, s, input); | 921 | 60.7k | match result { | 922 | 50.9k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 923 | 9.76k | _ => return result, | 924 | | } | 925 | | // No break, transit to the next state. | 926 | 50.9k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD; | 927 | | } | 928 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD => { | 929 | | let table_size: u32; | 930 | 51.1k | if (s.symbol == 3) { | 931 | 4.66k | let mut bits: u32 = 0; | 932 | 4.66k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input)) { | 933 | 197 | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD; | 934 | 197 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 935 | 4.46k | } | 936 | 4.46k | s.symbol += bits; | 937 | 46.4k | } | 938 | | BROTLI_LOG_UINT!(s.symbol); | 939 | 50.9k | table_size = huffman::BrotliBuildSimpleHuffmanTable(&mut table[offset..], | 940 | 50.9k | HUFFMAN_TABLE_BITS as i32, | 941 | 50.9k | &s.symbols_lists_array[..], | 942 | 50.9k | s.symbol); | 943 | 50.9k | if let Some(opt_table_size_ref) = opt_table_size { | 944 | 21.5k | *opt_table_size_ref = table_size | 945 | 29.4k | } | 946 | 50.9k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE; | 947 | 50.9k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 948 | | } | 949 | | | 950 | | // Decode Huffman-coded code lengths. | 951 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX => { | 952 | | | 953 | 33.4k | let result = ReadCodeLengthCodeLengths(s, input); | 954 | 33.4k | match result { | 955 | 21.6k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 956 | 11.7k | _ => return result, | 957 | | } | 958 | 21.6k | huffman::BrotliBuildCodeLengthsHuffmanTable(&mut s.table, | 959 | 21.6k | &s.code_length_code_lengths, | 960 | 21.6k | &s.code_length_histo); | 961 | 346k | for code_length_histo in s.code_length_histo[..].iter_mut() { | 962 | 346k | *code_length_histo = 0; // memset | 963 | 346k | } | 964 | | | 965 | 21.6k | let max_code_length = huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH as usize + 1; | 966 | 346k | for (i, next_symbol_mut) in fast_mut!((s.next_symbol)[0; max_code_length]) | 967 | 21.6k | .iter_mut() | 968 | 346k | .enumerate() { | 969 | 346k | *next_symbol_mut = i as i32 - (max_code_length as i32); | 970 | 346k | fast_mut!((s.symbols_lists_array)[(s.symbol_lists_index as i32 | 971 | 346k | + i as i32 | 972 | 346k | - (max_code_length as i32)) as usize]) = 0xFFFF; | 973 | 346k | } | 974 | | | 975 | 21.6k | s.symbol = 0; | 976 | 21.6k | s.prev_code_len = kDefaultCodeLength; | 977 | 21.6k | s.repeat = 0; | 978 | 21.6k | s.repeat_code_len = 0; | 979 | 21.6k | s.space = 32768; | 980 | | // No break, transit to the next state. | 981 | 21.6k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS; | 982 | | } | 983 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS => { | 984 | | let table_size: u32; | 985 | 36.3k | let mut result = ReadSymbolCodeLengths(max_symbol, s, input); | 986 | 36.3k | if let BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT = result { | 987 | 25.3k | result = SafeReadSymbolCodeLengths(max_symbol, s, input) | 988 | 11.0k | } | 989 | 36.3k | match result { | 990 | 19.0k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 991 | 17.3k | _ => return result, | 992 | | } | 993 | | | 994 | 19.0k | if (s.space != 0) { | 995 | | BROTLI_LOG!("[ReadHuffmanCode] space = %d\n", s.space); | 996 | 4.48k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE; | 997 | 14.5k | } | 998 | 14.5k | table_size = huffman::BrotliBuildHuffmanTable(fast_mut!((table)[offset;]), | 999 | 14.5k | HUFFMAN_TABLE_BITS as i32, | 1000 | 14.5k | &s.symbols_lists_array[..], | 1001 | 14.5k | s.symbol_lists_index, | 1002 | 14.5k | &mut s.code_length_histo); | 1003 | 14.5k | if let Some(opt_table_size_ref) = opt_table_size { | 1004 | 9.20k | *opt_table_size_ref = table_size | 1005 | 5.32k | } | 1006 | 14.5k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE; | 1007 | 14.5k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1008 | | } | 1009 | | } | 1010 | | } | 1011 | 110k | } |
brotli_decompressor::decode::ReadHuffmanCode::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 866 | 169k | fn ReadHuffmanCode<AllocU8: alloc::Allocator<u8>, | 867 | 169k | AllocU32: alloc::Allocator<u32>, | 868 | 169k | AllocHC: alloc::Allocator<HuffmanCode>> | 869 | 169k | (mut alphabet_size: u32, | 870 | 169k | max_symbol: u32, | 871 | 169k | table: &mut [HuffmanCode], | 872 | 169k | offset: usize, | 873 | 169k | opt_table_size: Option<&mut u32>, | 874 | 169k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 875 | 169k | input: &[u8]) | 876 | 169k | -> BrotliDecoderErrorCode { | 877 | | // Unnecessary masking, but might be good for safety. | 878 | 169k | alphabet_size &= 0x7ff; | 879 | | // State machine | 880 | | loop { | 881 | 363k | match s.substate_huffman { | 882 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE => { | 883 | 77.7k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut s.sub_loop_counter, input) { | 884 | 1.40k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 885 | 76.3k | } | 886 | | | 887 | | BROTLI_LOG_UINT!(s.sub_loop_counter); | 888 | | // The value is used as follows: | 889 | | // 1 for simple code; | 890 | | // 0 for no skipping, 2 skips 2 code lengths, 3 skips 3 code lengths | 891 | 76.3k | if (s.sub_loop_counter != 1) { | 892 | 27.0k | s.space = 32; | 893 | 27.0k | s.repeat = 0; /* num_codes */ | 894 | 27.0k | let max_code_len_len = huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH as usize + 1; | 895 | 162k | for code_length_histo in fast_mut!((s.code_length_histo)[0;max_code_len_len]).iter_mut() { | 896 | 162k | *code_length_histo = 0; // memset | 897 | 162k | } | 898 | 486k | for code_length_code_length in s.code_length_code_lengths[..].iter_mut() { | 899 | 486k | *code_length_code_length = 0; | 900 | 486k | } | 901 | 27.0k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX; | 902 | | // goto Complex; | 903 | 27.0k | continue; | 904 | 49.2k | } | 905 | 49.2k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE; | 906 | | // No break, transit to the next state. | 907 | | } | 908 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE => { | 909 | | // Read symbols, codes & code lengths directly. | 910 | 49.6k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut s.symbol, input)) { | 911 | | // num_symbols | 912 | 550 | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_SIZE; | 913 | 550 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 914 | 49.1k | } | 915 | 49.1k | s.sub_loop_counter = 0; | 916 | | // No break, transit to the next state. | 917 | 49.1k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ; | 918 | | } | 919 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_READ => { | 920 | 50.4k | let result = ReadSimpleHuffmanSymbols(alphabet_size, max_symbol, s, input); | 921 | 50.4k | match result { | 922 | 47.6k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 923 | 2.80k | _ => return result, | 924 | | } | 925 | | // No break, transit to the next state. | 926 | 47.6k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD; | 927 | | } | 928 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD => { | 929 | | let table_size: u32; | 930 | 49.1k | if (s.symbol == 3) { | 931 | 7.81k | let mut bits: u32 = 0; | 932 | 7.81k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input)) { | 933 | 1.49k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_SIMPLE_BUILD; | 934 | 1.49k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 935 | 6.31k | } | 936 | 6.31k | s.symbol += bits; | 937 | 41.3k | } | 938 | | BROTLI_LOG_UINT!(s.symbol); | 939 | 47.6k | table_size = huffman::BrotliBuildSimpleHuffmanTable(&mut table[offset..], | 940 | 47.6k | HUFFMAN_TABLE_BITS as i32, | 941 | 47.6k | &s.symbols_lists_array[..], | 942 | 47.6k | s.symbol); | 943 | 47.6k | if let Some(opt_table_size_ref) = opt_table_size { | 944 | 30.8k | *opt_table_size_ref = table_size | 945 | 16.8k | } | 946 | 47.6k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE; | 947 | 47.6k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 948 | | } | 949 | | | 950 | | // Decode Huffman-coded code lengths. | 951 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_COMPLEX => { | 952 | | | 953 | 108k | let result = ReadCodeLengthCodeLengths(s, input); | 954 | 108k | match result { | 955 | 20.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 956 | 87.6k | _ => return result, | 957 | | } | 958 | 20.3k | huffman::BrotliBuildCodeLengthsHuffmanTable(&mut s.table, | 959 | 20.3k | &s.code_length_code_lengths, | 960 | 20.3k | &s.code_length_histo); | 961 | 326k | for code_length_histo in s.code_length_histo[..].iter_mut() { | 962 | 326k | *code_length_histo = 0; // memset | 963 | 326k | } | 964 | | | 965 | 20.3k | let max_code_length = huffman::BROTLI_HUFFMAN_MAX_CODE_LENGTH as usize + 1; | 966 | 326k | for (i, next_symbol_mut) in fast_mut!((s.next_symbol)[0; max_code_length]) | 967 | 20.3k | .iter_mut() | 968 | 326k | .enumerate() { | 969 | 326k | *next_symbol_mut = i as i32 - (max_code_length as i32); | 970 | 326k | fast_mut!((s.symbols_lists_array)[(s.symbol_lists_index as i32 | 971 | 326k | + i as i32 | 972 | 326k | - (max_code_length as i32)) as usize]) = 0xFFFF; | 973 | 326k | } | 974 | | | 975 | 20.3k | s.symbol = 0; | 976 | 20.3k | s.prev_code_len = kDefaultCodeLength; | 977 | 20.3k | s.repeat = 0; | 978 | 20.3k | s.repeat_code_len = 0; | 979 | 20.3k | s.space = 32768; | 980 | | // No break, transit to the next state. | 981 | 20.3k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS; | 982 | | } | 983 | | BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS => { | 984 | | let table_size: u32; | 985 | 27.9k | let mut result = ReadSymbolCodeLengths(max_symbol, s, input); | 986 | 27.9k | if let BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT = result { | 987 | 12.8k | result = SafeReadSymbolCodeLengths(max_symbol, s, input) | 988 | 15.1k | } | 989 | 27.9k | match result { | 990 | 18.6k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 991 | 9.26k | _ => return result, | 992 | | } | 993 | | | 994 | 18.6k | if (s.space != 0) { | 995 | | BROTLI_LOG!("[ReadHuffmanCode] space = %d\n", s.space); | 996 | 1.50k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE; | 997 | 17.1k | } | 998 | 17.1k | table_size = huffman::BrotliBuildHuffmanTable(fast_mut!((table)[offset;]), | 999 | 17.1k | HUFFMAN_TABLE_BITS as i32, | 1000 | 17.1k | &s.symbols_lists_array[..], | 1001 | 17.1k | s.symbol_lists_index, | 1002 | 17.1k | &mut s.code_length_histo); | 1003 | 17.1k | if let Some(opt_table_size_ref) = opt_table_size { | 1004 | 11.7k | *opt_table_size_ref = table_size | 1005 | 5.48k | } | 1006 | 17.1k | s.substate_huffman = BrotliRunningHuffmanState::BROTLI_STATE_HUFFMAN_NONE; | 1007 | 17.1k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1008 | | } | 1009 | | } | 1010 | | } | 1011 | 169k | } |
|
1012 | | |
1013 | | // Decodes a block length by reading 3..39 bits. |
1014 | 10.5M | fn ReadBlockLength(table: &[HuffmanCode], |
1015 | 10.5M | br: &mut bit_reader::BrotliBitReader, |
1016 | 10.5M | input: &[u8]) |
1017 | 10.5M | -> u32 { |
1018 | | let code: u32; |
1019 | | let nbits: u32; |
1020 | 10.5M | code = ReadSymbol(table, br, input); |
1021 | 10.5M | nbits = fast_ref!((prefix::kBlockLengthPrefixCode)[code as usize]).nbits as u32; /*nbits==2..24*/ |
1022 | 10.5M | fast_ref!((prefix::kBlockLengthPrefixCode)[code as usize]).offset as u32 + |
1023 | 10.5M | bit_reader::BrotliReadBits(br, nbits, input) |
1024 | 10.5M | } |
1025 | | |
1026 | | |
1027 | | // WARNING: if state is not BROTLI_STATE_READ_BLOCK_LENGTH_NONE, then |
1028 | | // reading can't be continued with ReadBlockLength. |
1029 | 410k | fn SafeReadBlockLengthIndex(substate_read_block_length: &state::BrotliRunningReadBlockLengthState, |
1030 | 410k | block_length_index: u32, |
1031 | 410k | table: &[HuffmanCode], |
1032 | 410k | mut br: &mut bit_reader::BrotliBitReader, |
1033 | 410k | input: &[u8]) |
1034 | 410k | -> (bool, u32) { |
1035 | 410k | match *substate_read_block_length { |
1036 | | state::BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_NONE => { |
1037 | 398k | let mut index: u32 = 0; |
1038 | 398k | if (!SafeReadSymbol(table, &mut br, &mut index, input)) { |
1039 | 20.7k | return (false, 0); |
1040 | 377k | } |
1041 | 377k | (true, index) |
1042 | | } |
1043 | 11.8k | _ => (true, block_length_index), |
1044 | | } |
1045 | 410k | } |
1046 | 410k | fn SafeReadBlockLengthFromIndex< |
1047 | 410k | AllocHC : alloc::Allocator<HuffmanCode> >(s : &mut BlockTypeAndLengthState<AllocHC>, |
1048 | 410k | br : &mut bit_reader::BrotliBitReader, |
1049 | 410k | result : &mut u32, |
1050 | 410k | res_index : (bool, u32), |
1051 | 410k | input : &[u8]) -> bool{ |
1052 | 410k | let (res, index) = res_index; |
1053 | 410k | if !res { |
1054 | 20.7k | return false; |
1055 | 389k | } |
1056 | 389k | let mut bits: u32 = 0; |
1057 | 389k | let nbits = fast_ref!((prefix::kBlockLengthPrefixCode)[index as usize]).nbits; /* nbits==2..24 */ |
1058 | 389k | if (!bit_reader::BrotliSafeReadBits(br, nbits as u32, &mut bits, input)) { |
1059 | 60.3k | s.block_length_index = index; |
1060 | 60.3k | s.substate_read_block_length = |
1061 | 60.3k | state::BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX; |
1062 | 60.3k | return false; |
1063 | 329k | } |
1064 | 329k | *result = fast_ref!((prefix::kBlockLengthPrefixCode)[index as usize]).offset as u32 + bits; |
1065 | 329k | s.substate_read_block_length = |
1066 | 329k | state::BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_NONE; |
1067 | 329k | true |
1068 | 410k | } brotli_decompressor::decode::SafeReadBlockLengthFromIndex::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1046 | 246k | fn SafeReadBlockLengthFromIndex< | 1047 | 246k | AllocHC : alloc::Allocator<HuffmanCode> >(s : &mut BlockTypeAndLengthState<AllocHC>, | 1048 | 246k | br : &mut bit_reader::BrotliBitReader, | 1049 | 246k | result : &mut u32, | 1050 | 246k | res_index : (bool, u32), | 1051 | 246k | input : &[u8]) -> bool{ | 1052 | 246k | let (res, index) = res_index; | 1053 | 246k | if !res { | 1054 | 17.0k | return false; | 1055 | 229k | } | 1056 | 229k | let mut bits: u32 = 0; | 1057 | 229k | let nbits = fast_ref!((prefix::kBlockLengthPrefixCode)[index as usize]).nbits; /* nbits==2..24 */ | 1058 | 229k | if (!bit_reader::BrotliSafeReadBits(br, nbits as u32, &mut bits, input)) { | 1059 | 42.1k | s.block_length_index = index; | 1060 | 42.1k | s.substate_read_block_length = | 1061 | 42.1k | state::BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX; | 1062 | 42.1k | return false; | 1063 | 187k | } | 1064 | 187k | *result = fast_ref!((prefix::kBlockLengthPrefixCode)[index as usize]).offset as u32 + bits; | 1065 | 187k | s.substate_read_block_length = | 1066 | 187k | state::BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_NONE; | 1067 | 187k | true | 1068 | 246k | } |
Unexecuted instantiation: brotli_decompressor::decode::SafeReadBlockLengthFromIndex::<alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::SafeReadBlockLengthFromIndex::<alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::SafeReadBlockLengthFromIndex::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1046 | 81.3k | fn SafeReadBlockLengthFromIndex< | 1047 | 81.3k | AllocHC : alloc::Allocator<HuffmanCode> >(s : &mut BlockTypeAndLengthState<AllocHC>, | 1048 | 81.3k | br : &mut bit_reader::BrotliBitReader, | 1049 | 81.3k | result : &mut u32, | 1050 | 81.3k | res_index : (bool, u32), | 1051 | 81.3k | input : &[u8]) -> bool{ | 1052 | 81.3k | let (res, index) = res_index; | 1053 | 81.3k | if !res { | 1054 | 1.91k | return false; | 1055 | 79.4k | } | 1056 | 79.4k | let mut bits: u32 = 0; | 1057 | 79.4k | let nbits = fast_ref!((prefix::kBlockLengthPrefixCode)[index as usize]).nbits; /* nbits==2..24 */ | 1058 | 79.4k | if (!bit_reader::BrotliSafeReadBits(br, nbits as u32, &mut bits, input)) { | 1059 | 4.22k | s.block_length_index = index; | 1060 | 4.22k | s.substate_read_block_length = | 1061 | 4.22k | state::BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX; | 1062 | 4.22k | return false; | 1063 | 75.1k | } | 1064 | 75.1k | *result = fast_ref!((prefix::kBlockLengthPrefixCode)[index as usize]).offset as u32 + bits; | 1065 | 75.1k | s.substate_read_block_length = | 1066 | 75.1k | state::BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_NONE; | 1067 | 75.1k | true | 1068 | 81.3k | } |
brotli_decompressor::decode::SafeReadBlockLengthFromIndex::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1046 | 82.3k | fn SafeReadBlockLengthFromIndex< | 1047 | 82.3k | AllocHC : alloc::Allocator<HuffmanCode> >(s : &mut BlockTypeAndLengthState<AllocHC>, | 1048 | 82.3k | br : &mut bit_reader::BrotliBitReader, | 1049 | 82.3k | result : &mut u32, | 1050 | 82.3k | res_index : (bool, u32), | 1051 | 82.3k | input : &[u8]) -> bool{ | 1052 | 82.3k | let (res, index) = res_index; | 1053 | 82.3k | if !res { | 1054 | 1.79k | return false; | 1055 | 80.5k | } | 1056 | 80.5k | let mut bits: u32 = 0; | 1057 | 80.5k | let nbits = fast_ref!((prefix::kBlockLengthPrefixCode)[index as usize]).nbits; /* nbits==2..24 */ | 1058 | 80.5k | if (!bit_reader::BrotliSafeReadBits(br, nbits as u32, &mut bits, input)) { | 1059 | 13.9k | s.block_length_index = index; | 1060 | 13.9k | s.substate_read_block_length = | 1061 | 13.9k | state::BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX; | 1062 | 13.9k | return false; | 1063 | 66.5k | } | 1064 | 66.5k | *result = fast_ref!((prefix::kBlockLengthPrefixCode)[index as usize]).offset as u32 + bits; | 1065 | 66.5k | s.substate_read_block_length = | 1066 | 66.5k | state::BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_NONE; | 1067 | 66.5k | true | 1068 | 82.3k | } |
|
1069 | | macro_rules! SafeReadBlockLength ( |
1070 | | ($state : expr, $result : expr , $table : expr) => { |
1071 | | SafeReadBlockLengthFromIndex(&mut $state, &mut $result, |
1072 | | SafeReadBlockLengthIndex($state.substate_read_block_length, |
1073 | | $state.block_length_index, |
1074 | | $table, |
1075 | | &mut $state.br)) |
1076 | | }; |
1077 | | ); |
1078 | | |
1079 | | // Transform: |
1080 | | // 1) initialize list L with values 0, 1,... 255 |
1081 | | // 2) For each input element X: |
1082 | | // 2.1) let Y = L[X] |
1083 | | // 2.2) remove X-th element from L |
1084 | | // 2.3) prepend Y to L |
1085 | | // 2.4) append Y to output |
1086 | | // |
1087 | | // In most cases max(Y) <= 7, so most of L remains intact. |
1088 | | // To reduce the cost of initialization, we reuse L, remember the upper bound |
1089 | | // of Y values, and reinitialize only first elements in L. |
1090 | | // |
1091 | | // Most of input values are 0 and 1. To reduce number of branches, we replace |
1092 | | // inner for loop with do-while. |
1093 | | // |
1094 | 27.5k | fn InverseMoveToFrontTransform(v: &mut [u8], |
1095 | 27.5k | v_len: u32, |
1096 | 27.5k | mtf: &mut [u8;256], |
1097 | 27.5k | mtf_upper_bound: &mut u32) { |
1098 | | // Reinitialize elements that could have been changed. |
1099 | 27.5k | let mut upper_bound: u32 = *mtf_upper_bound; |
1100 | 5.30M | for (i, item) in fast_mut!((mtf)[0;(upper_bound as usize + 1usize)]).iter_mut().enumerate() { |
1101 | 5.30M | *item = i as u8; |
1102 | 5.30M | } |
1103 | | |
1104 | | // Transform the input. |
1105 | 27.5k | upper_bound = 0; |
1106 | 2.68M | for v_i in fast_mut!((v)[0usize ; (v_len as usize)]).iter_mut() { |
1107 | 2.68M | let mut index = (*v_i) as i32; |
1108 | 2.68M | let value = fast!((mtf)[index as usize]); |
1109 | 2.68M | upper_bound |= (*v_i) as u32; |
1110 | 2.68M | *v_i = value; |
1111 | 2.68M | if index <= 0 { |
1112 | 770k | fast_mut!((mtf)[0]) = 0; |
1113 | 770k | } else { |
1114 | | loop { |
1115 | 59.0M | index -= 1; |
1116 | 59.0M | fast_mut!((mtf)[(index + 1) as usize]) = fast!((mtf)[index as usize]); |
1117 | 59.0M | if index <= 0 { |
1118 | 1.91M | break; |
1119 | 57.1M | } |
1120 | | } |
1121 | | } |
1122 | 2.68M | fast_mut!((mtf)[0]) = value; |
1123 | | } |
1124 | | // Remember amount of elements to be reinitialized. |
1125 | 27.5k | *mtf_upper_bound = upper_bound; |
1126 | 27.5k | } |
1127 | | // Decodes a series of Huffman table using ReadHuffmanCode function. |
1128 | 258k | fn HuffmanTreeGroupDecode<AllocU8: alloc::Allocator<u8>, |
1129 | 258k | AllocU32: alloc::Allocator<u32>, |
1130 | 258k | AllocHC: alloc::Allocator<HuffmanCode>> |
1131 | 258k | (group_index: i32, |
1132 | 258k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1133 | 258k | input: &[u8]) |
1134 | 258k | -> BrotliDecoderErrorCode { |
1135 | | let mut hcodes: AllocHC::AllocatedMemory; |
1136 | | let mut htrees: AllocU32::AllocatedMemory; |
1137 | | let alphabet_size: u16; |
1138 | | let group_num_htrees: u16; |
1139 | | let group_max_symbol; |
1140 | 258k | if group_index == 0 { |
1141 | 133k | hcodes = mem::replace(&mut s.literal_hgroup.codes, |
1142 | 133k | AllocHC::AllocatedMemory::default()); |
1143 | 133k | htrees = mem::replace(&mut s.literal_hgroup.htrees, |
1144 | 133k | AllocU32::AllocatedMemory::default()); |
1145 | 133k | group_num_htrees = s.literal_hgroup.num_htrees; |
1146 | 133k | alphabet_size = s.literal_hgroup.alphabet_size; |
1147 | 133k | group_max_symbol = s.literal_hgroup.max_symbol; |
1148 | 133k | } else if group_index == 1 { |
1149 | 72.4k | hcodes = mem::replace(&mut s.insert_copy_hgroup.codes, |
1150 | 72.4k | AllocHC::AllocatedMemory::default()); |
1151 | 72.4k | htrees = mem::replace(&mut s.insert_copy_hgroup.htrees, |
1152 | 72.4k | AllocU32::AllocatedMemory::default()); |
1153 | 72.4k | group_num_htrees = s.insert_copy_hgroup.num_htrees; |
1154 | 72.4k | alphabet_size = s.insert_copy_hgroup.alphabet_size; |
1155 | 72.4k | group_max_symbol = s.insert_copy_hgroup.max_symbol; |
1156 | 72.4k | } else { |
1157 | 52.9k | if group_index != 2 { |
1158 | 0 | let ret = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; |
1159 | 0 | SaveErrorCode!(s, ret); |
1160 | 0 | return ret; |
1161 | 52.9k | } |
1162 | 52.9k | hcodes = mem::replace(&mut s.distance_hgroup.codes, |
1163 | 52.9k | AllocHC::AllocatedMemory::default()); |
1164 | 52.9k | htrees = mem::replace(&mut s.distance_hgroup.htrees, |
1165 | 52.9k | AllocU32::AllocatedMemory::default()); |
1166 | 52.9k | group_num_htrees = s.distance_hgroup.num_htrees; |
1167 | 52.9k | alphabet_size = s.distance_hgroup.alphabet_size; |
1168 | 52.9k | group_max_symbol = s.distance_hgroup.max_symbol; |
1169 | | } |
1170 | 258k | match s.substate_tree_group { |
1171 | 166k | BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_NONE => { |
1172 | 166k | s.htree_next_offset = 0; |
1173 | 166k | s.htree_index = 0; |
1174 | 166k | s.substate_tree_group = BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_LOOP; |
1175 | 166k | } |
1176 | 92.4k | BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_LOOP => {} |
1177 | | } |
1178 | 258k | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
1179 | 300k | for htree_iter in |
1180 | 258k | fast_mut!((htrees.slice_mut())[s.htree_index as usize ; (group_num_htrees as usize)]) |
1181 | 258k | .iter_mut() { |
1182 | 300k | let mut table_size: u32 = 0; |
1183 | 300k | result = ReadHuffmanCode(u32::from(alphabet_size), u32::from(group_max_symbol), |
1184 | 300k | hcodes.slice_mut(), |
1185 | 300k | s.htree_next_offset as usize, |
1186 | 300k | Some(&mut table_size), |
1187 | 300k | &mut s, |
1188 | 300k | input); |
1189 | 300k | match result { |
1190 | 176k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
1191 | 123k | _ => break, // break and return the result code |
1192 | | } |
1193 | 176k | *htree_iter = s.htree_next_offset; |
1194 | 176k | s.htree_next_offset += table_size; |
1195 | 176k | s.htree_index += 1; |
1196 | | } |
1197 | 258k | if group_index == 0 { |
1198 | 133k | let _ = mem::replace(&mut s.literal_hgroup.codes, |
1199 | 133k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); |
1200 | 133k | let _ = mem::replace(&mut s.literal_hgroup.htrees, |
1201 | 133k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); |
1202 | 133k | } else if group_index == 1 { |
1203 | 72.4k | let _ = mem::replace(&mut s.insert_copy_hgroup.codes, |
1204 | 72.4k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); |
1205 | 72.4k | let _ = mem::replace(&mut s.insert_copy_hgroup.htrees, |
1206 | 72.4k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); |
1207 | 72.4k | } else { |
1208 | 52.9k | let _ = mem::replace(&mut s.distance_hgroup.codes, |
1209 | 52.9k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); |
1210 | 52.9k | let _ = mem::replace(&mut s.distance_hgroup.htrees, |
1211 | 52.9k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); |
1212 | 52.9k | } |
1213 | 258k | if let BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS = result { |
1214 | 134k | s.substate_tree_group = BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_NONE |
1215 | 123k | } |
1216 | 258k | result |
1217 | 258k | } brotli_decompressor::decode::HuffmanTreeGroupDecode::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1128 | 160k | fn HuffmanTreeGroupDecode<AllocU8: alloc::Allocator<u8>, | 1129 | 160k | AllocU32: alloc::Allocator<u32>, | 1130 | 160k | AllocHC: alloc::Allocator<HuffmanCode>> | 1131 | 160k | (group_index: i32, | 1132 | 160k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1133 | 160k | input: &[u8]) | 1134 | 160k | -> BrotliDecoderErrorCode { | 1135 | | let mut hcodes: AllocHC::AllocatedMemory; | 1136 | | let mut htrees: AllocU32::AllocatedMemory; | 1137 | | let alphabet_size: u16; | 1138 | | let group_num_htrees: u16; | 1139 | | let group_max_symbol; | 1140 | 160k | if group_index == 0 { | 1141 | 80.4k | hcodes = mem::replace(&mut s.literal_hgroup.codes, | 1142 | 80.4k | AllocHC::AllocatedMemory::default()); | 1143 | 80.4k | htrees = mem::replace(&mut s.literal_hgroup.htrees, | 1144 | 80.4k | AllocU32::AllocatedMemory::default()); | 1145 | 80.4k | group_num_htrees = s.literal_hgroup.num_htrees; | 1146 | 80.4k | alphabet_size = s.literal_hgroup.alphabet_size; | 1147 | 80.4k | group_max_symbol = s.literal_hgroup.max_symbol; | 1148 | 80.5k | } else if group_index == 1 { | 1149 | 48.9k | hcodes = mem::replace(&mut s.insert_copy_hgroup.codes, | 1150 | 48.9k | AllocHC::AllocatedMemory::default()); | 1151 | 48.9k | htrees = mem::replace(&mut s.insert_copy_hgroup.htrees, | 1152 | 48.9k | AllocU32::AllocatedMemory::default()); | 1153 | 48.9k | group_num_htrees = s.insert_copy_hgroup.num_htrees; | 1154 | 48.9k | alphabet_size = s.insert_copy_hgroup.alphabet_size; | 1155 | 48.9k | group_max_symbol = s.insert_copy_hgroup.max_symbol; | 1156 | 48.9k | } else { | 1157 | 31.5k | if group_index != 2 { | 1158 | 0 | let ret = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; | 1159 | 0 | SaveErrorCode!(s, ret); | 1160 | 0 | return ret; | 1161 | 31.5k | } | 1162 | 31.5k | hcodes = mem::replace(&mut s.distance_hgroup.codes, | 1163 | 31.5k | AllocHC::AllocatedMemory::default()); | 1164 | 31.5k | htrees = mem::replace(&mut s.distance_hgroup.htrees, | 1165 | 31.5k | AllocU32::AllocatedMemory::default()); | 1166 | 31.5k | group_num_htrees = s.distance_hgroup.num_htrees; | 1167 | 31.5k | alphabet_size = s.distance_hgroup.alphabet_size; | 1168 | 31.5k | group_max_symbol = s.distance_hgroup.max_symbol; | 1169 | | } | 1170 | 160k | match s.substate_tree_group { | 1171 | 101k | BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_NONE => { | 1172 | 101k | s.htree_next_offset = 0; | 1173 | 101k | s.htree_index = 0; | 1174 | 101k | s.substate_tree_group = BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_LOOP; | 1175 | 101k | } | 1176 | 58.9k | BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_LOOP => {} | 1177 | | } | 1178 | 160k | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1179 | 178k | for htree_iter in | 1180 | 160k | fast_mut!((htrees.slice_mut())[s.htree_index as usize ; (group_num_htrees as usize)]) | 1181 | 160k | .iter_mut() { | 1182 | 178k | let mut table_size: u32 = 0; | 1183 | 178k | result = ReadHuffmanCode(u32::from(alphabet_size), u32::from(group_max_symbol), | 1184 | 178k | hcodes.slice_mut(), | 1185 | 178k | s.htree_next_offset as usize, | 1186 | 178k | Some(&mut table_size), | 1187 | 178k | &mut s, | 1188 | 178k | input); | 1189 | 178k | match result { | 1190 | 103k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1191 | 75.2k | _ => break, // break and return the result code | 1192 | | } | 1193 | 103k | *htree_iter = s.htree_next_offset; | 1194 | 103k | s.htree_next_offset += table_size; | 1195 | 103k | s.htree_index += 1; | 1196 | | } | 1197 | 160k | if group_index == 0 { | 1198 | 80.4k | let _ = mem::replace(&mut s.literal_hgroup.codes, | 1199 | 80.4k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); | 1200 | 80.4k | let _ = mem::replace(&mut s.literal_hgroup.htrees, | 1201 | 80.4k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); | 1202 | 80.5k | } else if group_index == 1 { | 1203 | 48.9k | let _ = mem::replace(&mut s.insert_copy_hgroup.codes, | 1204 | 48.9k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); | 1205 | 48.9k | let _ = mem::replace(&mut s.insert_copy_hgroup.htrees, | 1206 | 48.9k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); | 1207 | 48.9k | } else { | 1208 | 31.5k | let _ = mem::replace(&mut s.distance_hgroup.codes, | 1209 | 31.5k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); | 1210 | 31.5k | let _ = mem::replace(&mut s.distance_hgroup.htrees, | 1211 | 31.5k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); | 1212 | 31.5k | } | 1213 | 160k | if let BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS = result { | 1214 | 85.6k | s.substate_tree_group = BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_NONE | 1215 | 75.2k | } | 1216 | 160k | result | 1217 | 160k | } |
Unexecuted instantiation: brotli_decompressor::decode::HuffmanTreeGroupDecode::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::HuffmanTreeGroupDecode::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::HuffmanTreeGroupDecode::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1128 | 46.3k | fn HuffmanTreeGroupDecode<AllocU8: alloc::Allocator<u8>, | 1129 | 46.3k | AllocU32: alloc::Allocator<u32>, | 1130 | 46.3k | AllocHC: alloc::Allocator<HuffmanCode>> | 1131 | 46.3k | (group_index: i32, | 1132 | 46.3k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1133 | 46.3k | input: &[u8]) | 1134 | 46.3k | -> BrotliDecoderErrorCode { | 1135 | | let mut hcodes: AllocHC::AllocatedMemory; | 1136 | | let mut htrees: AllocU32::AllocatedMemory; | 1137 | | let alphabet_size: u16; | 1138 | | let group_num_htrees: u16; | 1139 | | let group_max_symbol; | 1140 | 46.3k | if group_index == 0 { | 1141 | 26.0k | hcodes = mem::replace(&mut s.literal_hgroup.codes, | 1142 | 26.0k | AllocHC::AllocatedMemory::default()); | 1143 | 26.0k | htrees = mem::replace(&mut s.literal_hgroup.htrees, | 1144 | 26.0k | AllocU32::AllocatedMemory::default()); | 1145 | 26.0k | group_num_htrees = s.literal_hgroup.num_htrees; | 1146 | 26.0k | alphabet_size = s.literal_hgroup.alphabet_size; | 1147 | 26.0k | group_max_symbol = s.literal_hgroup.max_symbol; | 1148 | 26.0k | } else if group_index == 1 { | 1149 | 10.5k | hcodes = mem::replace(&mut s.insert_copy_hgroup.codes, | 1150 | 10.5k | AllocHC::AllocatedMemory::default()); | 1151 | 10.5k | htrees = mem::replace(&mut s.insert_copy_hgroup.htrees, | 1152 | 10.5k | AllocU32::AllocatedMemory::default()); | 1153 | 10.5k | group_num_htrees = s.insert_copy_hgroup.num_htrees; | 1154 | 10.5k | alphabet_size = s.insert_copy_hgroup.alphabet_size; | 1155 | 10.5k | group_max_symbol = s.insert_copy_hgroup.max_symbol; | 1156 | 10.5k | } else { | 1157 | 9.79k | if group_index != 2 { | 1158 | 0 | let ret = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; | 1159 | 0 | SaveErrorCode!(s, ret); | 1160 | 0 | return ret; | 1161 | 9.79k | } | 1162 | 9.79k | hcodes = mem::replace(&mut s.distance_hgroup.codes, | 1163 | 9.79k | AllocHC::AllocatedMemory::default()); | 1164 | 9.79k | htrees = mem::replace(&mut s.distance_hgroup.htrees, | 1165 | 9.79k | AllocU32::AllocatedMemory::default()); | 1166 | 9.79k | group_num_htrees = s.distance_hgroup.num_htrees; | 1167 | 9.79k | alphabet_size = s.distance_hgroup.alphabet_size; | 1168 | 9.79k | group_max_symbol = s.distance_hgroup.max_symbol; | 1169 | | } | 1170 | 46.3k | match s.substate_tree_group { | 1171 | 28.2k | BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_NONE => { | 1172 | 28.2k | s.htree_next_offset = 0; | 1173 | 28.2k | s.htree_index = 0; | 1174 | 28.2k | s.substate_tree_group = BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_LOOP; | 1175 | 28.2k | } | 1176 | 18.1k | BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_LOOP => {} | 1177 | | } | 1178 | 46.3k | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1179 | 55.3k | for htree_iter in | 1180 | 46.3k | fast_mut!((htrees.slice_mut())[s.htree_index as usize ; (group_num_htrees as usize)]) | 1181 | 46.3k | .iter_mut() { | 1182 | 55.3k | let mut table_size: u32 = 0; | 1183 | 55.3k | result = ReadHuffmanCode(u32::from(alphabet_size), u32::from(group_max_symbol), | 1184 | 55.3k | hcodes.slice_mut(), | 1185 | 55.3k | s.htree_next_offset as usize, | 1186 | 55.3k | Some(&mut table_size), | 1187 | 55.3k | &mut s, | 1188 | 55.3k | input); | 1189 | 55.3k | match result { | 1190 | 30.7k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1191 | 24.5k | _ => break, // break and return the result code | 1192 | | } | 1193 | 30.7k | *htree_iter = s.htree_next_offset; | 1194 | 30.7k | s.htree_next_offset += table_size; | 1195 | 30.7k | s.htree_index += 1; | 1196 | | } | 1197 | 46.3k | if group_index == 0 { | 1198 | 26.0k | let _ = mem::replace(&mut s.literal_hgroup.codes, | 1199 | 26.0k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); | 1200 | 26.0k | let _ = mem::replace(&mut s.literal_hgroup.htrees, | 1201 | 26.0k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); | 1202 | 26.0k | } else if group_index == 1 { | 1203 | 10.5k | let _ = mem::replace(&mut s.insert_copy_hgroup.codes, | 1204 | 10.5k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); | 1205 | 10.5k | let _ = mem::replace(&mut s.insert_copy_hgroup.htrees, | 1206 | 10.5k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); | 1207 | 10.5k | } else { | 1208 | 9.79k | let _ = mem::replace(&mut s.distance_hgroup.codes, | 1209 | 9.79k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); | 1210 | 9.79k | let _ = mem::replace(&mut s.distance_hgroup.htrees, | 1211 | 9.79k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); | 1212 | 9.79k | } | 1213 | 46.3k | if let BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS = result { | 1214 | 21.7k | s.substate_tree_group = BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_NONE | 1215 | 24.5k | } | 1216 | 46.3k | result | 1217 | 46.3k | } |
brotli_decompressor::decode::HuffmanTreeGroupDecode::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1128 | 51.5k | fn HuffmanTreeGroupDecode<AllocU8: alloc::Allocator<u8>, | 1129 | 51.5k | AllocU32: alloc::Allocator<u32>, | 1130 | 51.5k | AllocHC: alloc::Allocator<HuffmanCode>> | 1131 | 51.5k | (group_index: i32, | 1132 | 51.5k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1133 | 51.5k | input: &[u8]) | 1134 | 51.5k | -> BrotliDecoderErrorCode { | 1135 | | let mut hcodes: AllocHC::AllocatedMemory; | 1136 | | let mut htrees: AllocU32::AllocatedMemory; | 1137 | | let alphabet_size: u16; | 1138 | | let group_num_htrees: u16; | 1139 | | let group_max_symbol; | 1140 | 51.5k | if group_index == 0 { | 1141 | 27.0k | hcodes = mem::replace(&mut s.literal_hgroup.codes, | 1142 | 27.0k | AllocHC::AllocatedMemory::default()); | 1143 | 27.0k | htrees = mem::replace(&mut s.literal_hgroup.htrees, | 1144 | 27.0k | AllocU32::AllocatedMemory::default()); | 1145 | 27.0k | group_num_htrees = s.literal_hgroup.num_htrees; | 1146 | 27.0k | alphabet_size = s.literal_hgroup.alphabet_size; | 1147 | 27.0k | group_max_symbol = s.literal_hgroup.max_symbol; | 1148 | 27.0k | } else if group_index == 1 { | 1149 | 12.9k | hcodes = mem::replace(&mut s.insert_copy_hgroup.codes, | 1150 | 12.9k | AllocHC::AllocatedMemory::default()); | 1151 | 12.9k | htrees = mem::replace(&mut s.insert_copy_hgroup.htrees, | 1152 | 12.9k | AllocU32::AllocatedMemory::default()); | 1153 | 12.9k | group_num_htrees = s.insert_copy_hgroup.num_htrees; | 1154 | 12.9k | alphabet_size = s.insert_copy_hgroup.alphabet_size; | 1155 | 12.9k | group_max_symbol = s.insert_copy_hgroup.max_symbol; | 1156 | 12.9k | } else { | 1157 | 11.5k | if group_index != 2 { | 1158 | 0 | let ret = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; | 1159 | 0 | SaveErrorCode!(s, ret); | 1160 | 0 | return ret; | 1161 | 11.5k | } | 1162 | 11.5k | hcodes = mem::replace(&mut s.distance_hgroup.codes, | 1163 | 11.5k | AllocHC::AllocatedMemory::default()); | 1164 | 11.5k | htrees = mem::replace(&mut s.distance_hgroup.htrees, | 1165 | 11.5k | AllocU32::AllocatedMemory::default()); | 1166 | 11.5k | group_num_htrees = s.distance_hgroup.num_htrees; | 1167 | 11.5k | alphabet_size = s.distance_hgroup.alphabet_size; | 1168 | 11.5k | group_max_symbol = s.distance_hgroup.max_symbol; | 1169 | | } | 1170 | 51.5k | match s.substate_tree_group { | 1171 | 36.2k | BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_NONE => { | 1172 | 36.2k | s.htree_next_offset = 0; | 1173 | 36.2k | s.htree_index = 0; | 1174 | 36.2k | s.substate_tree_group = BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_LOOP; | 1175 | 36.2k | } | 1176 | 15.3k | BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_LOOP => {} | 1177 | | } | 1178 | 51.5k | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1179 | 66.5k | for htree_iter in | 1180 | 51.5k | fast_mut!((htrees.slice_mut())[s.htree_index as usize ; (group_num_htrees as usize)]) | 1181 | 51.5k | .iter_mut() { | 1182 | 66.5k | let mut table_size: u32 = 0; | 1183 | 66.5k | result = ReadHuffmanCode(u32::from(alphabet_size), u32::from(group_max_symbol), | 1184 | 66.5k | hcodes.slice_mut(), | 1185 | 66.5k | s.htree_next_offset as usize, | 1186 | 66.5k | Some(&mut table_size), | 1187 | 66.5k | &mut s, | 1188 | 66.5k | input); | 1189 | 66.5k | match result { | 1190 | 42.5k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1191 | 24.0k | _ => break, // break and return the result code | 1192 | | } | 1193 | 42.5k | *htree_iter = s.htree_next_offset; | 1194 | 42.5k | s.htree_next_offset += table_size; | 1195 | 42.5k | s.htree_index += 1; | 1196 | | } | 1197 | 51.5k | if group_index == 0 { | 1198 | 27.0k | let _ = mem::replace(&mut s.literal_hgroup.codes, | 1199 | 27.0k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); | 1200 | 27.0k | let _ = mem::replace(&mut s.literal_hgroup.htrees, | 1201 | 27.0k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); | 1202 | 27.0k | } else if group_index == 1 { | 1203 | 12.9k | let _ = mem::replace(&mut s.insert_copy_hgroup.codes, | 1204 | 12.9k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); | 1205 | 12.9k | let _ = mem::replace(&mut s.insert_copy_hgroup.htrees, | 1206 | 12.9k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); | 1207 | 12.9k | } else { | 1208 | 11.5k | let _ = mem::replace(&mut s.distance_hgroup.codes, | 1209 | 11.5k | mem::replace(&mut hcodes, AllocHC::AllocatedMemory::default())); | 1210 | 11.5k | let _ = mem::replace(&mut s.distance_hgroup.htrees, | 1211 | 11.5k | mem::replace(&mut htrees, AllocU32::AllocatedMemory::default())); | 1212 | 11.5k | } | 1213 | 51.5k | if let BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS = result { | 1214 | 27.5k | s.substate_tree_group = BrotliRunningTreeGroupState::BROTLI_STATE_TREE_GROUP_NONE | 1215 | 24.0k | } | 1216 | 51.5k | result | 1217 | 51.5k | } |
|
1218 | | #[allow(dead_code)] |
1219 | 0 | pub fn lg_window_size(first_byte: u8, second_byte: u8) -> Result<(u8, u8), ()> { |
1220 | 0 | if first_byte & 1 == 0 { |
1221 | 0 | return Ok((16, 1)); |
1222 | 0 | } |
1223 | 0 | match first_byte & 15 { |
1224 | 0 | 0x3 => return Ok((18, 4)), |
1225 | 0 | 0x5 => return Ok((19, 4)), |
1226 | 0 | 0x7 => return Ok((20, 4)), |
1227 | 0 | 0x9 => return Ok((21, 4)), |
1228 | 0 | 0xb => return Ok((22, 4)), |
1229 | 0 | 0xd => return Ok((23, 4)), |
1230 | 0 | 0xf => return Ok((24, 4)), |
1231 | 0 | _ => match first_byte & 127 { |
1232 | 0 | 0x71 => return Ok((15, 7)), |
1233 | 0 | 0x61 => return Ok((14, 7)), |
1234 | 0 | 0x51 => return Ok((13, 7)), |
1235 | 0 | 0x41 => return Ok((12, 7)), |
1236 | 0 | 0x31 => return Ok((11, 7)), |
1237 | 0 | 0x21 => return Ok((10, 7)), |
1238 | 0 | 0x1 => return Ok((17, 7)), |
1239 | 0 | _ => {}, |
1240 | | } |
1241 | | } |
1242 | 0 | if (first_byte & 0x80) != 0 { |
1243 | 0 | return Err(()); |
1244 | 0 | } |
1245 | 0 | let ret = second_byte & 0x3f; |
1246 | 0 | if ret < 10 || ret > 30 { |
1247 | 0 | return Err(()); |
1248 | 0 | } |
1249 | 0 | Ok((ret, 14)) |
1250 | | |
1251 | 0 | } |
1252 | | |
1253 | | |
1254 | 113k | fn bzero(data: &mut [u8]) { |
1255 | 20.2M | for iter in data.iter_mut() { |
1256 | 20.2M | *iter = 0; |
1257 | 20.2M | } |
1258 | 113k | } |
1259 | | |
1260 | | |
1261 | | // Decodes a context map. |
1262 | | // Decoding is done in 4 phases: |
1263 | | // 1) Read auxiliary information (6..16 bits) and allocate memory. |
1264 | | // In case of trivial context map, decoding is finished at this phase. |
1265 | | // 2) Decode Huffman table using ReadHuffmanCode function. |
1266 | | // This table will be used for reading context map items. |
1267 | | // 3) Read context map items; "0" values could be run-length encoded. |
1268 | | // 4) Optionally, apply InverseMoveToFront transform to the resulting map. |
1269 | | // |
1270 | 317k | fn DecodeContextMapInner<AllocU8: alloc::Allocator<u8>, |
1271 | 317k | AllocU32: alloc::Allocator<u32>, |
1272 | 317k | AllocHC: alloc::Allocator<HuffmanCode>> |
1273 | 317k | (context_map_size: u32, |
1274 | 317k | num_htrees: &mut u32, |
1275 | 317k | context_map_arg: &mut AllocU8::AllocatedMemory, |
1276 | 317k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1277 | 317k | input: &[u8]) |
1278 | 317k | -> BrotliDecoderErrorCode { |
1279 | | |
1280 | | let mut result; |
1281 | | loop { |
1282 | 488k | match s.substate_context_map { |
1283 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_NONE => { |
1284 | 185k | result = DecodeVarLenUint8(&mut s.substate_decode_uint8, &mut s.br, num_htrees, input); |
1285 | 185k | match result { |
1286 | 161k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
1287 | 24.3k | _ => return result, |
1288 | | } |
1289 | 161k | (*num_htrees) += 1; |
1290 | 161k | s.context_index = 0; |
1291 | | BROTLI_LOG_UINT!(context_map_size); |
1292 | | BROTLI_LOG_UINT!(*num_htrees); |
1293 | 161k | *context_map_arg = s.alloc_u8.alloc_cell(context_map_size as usize); |
1294 | 161k | if (context_map_arg.slice().len() < context_map_size as usize) { |
1295 | 0 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP; |
1296 | 161k | } |
1297 | 161k | if (*num_htrees <= 1) { |
1298 | | // This happens automatically but we do it to retain C++ similarity: |
1299 | 113k | bzero(context_map_arg.slice_mut()); // necessary if we compiler with unsafe feature flag |
1300 | 113k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
1301 | 47.4k | } |
1302 | 47.4k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_READ_PREFIX; |
1303 | | // No break, continue to next state. |
1304 | | } |
1305 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_READ_PREFIX => { |
1306 | 60.1k | let mut bits: u32 = 0; |
1307 | | // In next stage ReadHuffmanCode uses at least 4 bits, so it is safe |
1308 | | // to peek 4 bits ahead. |
1309 | 60.1k | if (!bit_reader::BrotliSafeGetBits(&mut s.br, 5, &mut bits, input)) { |
1310 | 12.8k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
1311 | 47.2k | } |
1312 | 47.2k | if ((bits & 1) != 0) { |
1313 | 21.7k | // Use RLE for zeroes. |
1314 | 21.7k | s.max_run_length_prefix = (bits >> 1) + 1; |
1315 | 21.7k | bit_reader::BrotliDropBits(&mut s.br, 5); |
1316 | 25.5k | } else { |
1317 | 25.5k | s.max_run_length_prefix = 0; |
1318 | 25.5k | bit_reader::BrotliDropBits(&mut s.br, 1); |
1319 | 25.5k | } |
1320 | | BROTLI_LOG_UINT!(s.max_run_length_prefix); |
1321 | 47.2k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_HUFFMAN; |
1322 | | // No break, continue to next state. |
1323 | | } |
1324 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_HUFFMAN => { |
1325 | | |
1326 | 118k | let mut local_context_map_table = mem::replace(&mut s.context_map_table, |
1327 | 118k | AllocHC::AllocatedMemory::default()); |
1328 | 118k | let alphabet_size = *num_htrees + s.max_run_length_prefix; |
1329 | 118k | result = ReadHuffmanCode(alphabet_size, alphabet_size, |
1330 | 118k | &mut local_context_map_table.slice_mut(), |
1331 | 118k | 0, |
1332 | 118k | None, |
1333 | 118k | &mut s, |
1334 | 118k | input); |
1335 | 118k | let _ = mem::replace(&mut s.context_map_table, |
1336 | 118k | mem::replace(&mut local_context_map_table, |
1337 | 118k | AllocHC::AllocatedMemory::default())); |
1338 | 118k | match result { |
1339 | 39.2k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
1340 | 78.7k | _ => return result, |
1341 | | } |
1342 | 39.2k | s.code = 0xFFFF; |
1343 | 39.2k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_DECODE; |
1344 | | // No break, continue to next state. |
1345 | | } |
1346 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_DECODE => { |
1347 | 71.7k | let mut context_index: u32 = s.context_index; |
1348 | 71.7k | let max_run_length_prefix: u32 = s.max_run_length_prefix; |
1349 | 71.7k | let context_map = &mut context_map_arg.slice_mut(); |
1350 | 71.7k | let mut code: u32 = s.code; |
1351 | 71.7k | let mut rleCodeGoto = (code != 0xFFFF); |
1352 | 3.71M | while (rleCodeGoto || context_index < context_map_size) { |
1353 | 3.68M | if !rleCodeGoto { |
1354 | 3.67M | if (!SafeReadSymbol(s.context_map_table.slice(), &mut s.br, &mut code, input)) { |
1355 | 27.3k | s.code = 0xFFFF; |
1356 | 27.3k | s.context_index = context_index; |
1357 | 27.3k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
1358 | 3.64M | } |
1359 | | BROTLI_LOG_UINT!(code); |
1360 | | |
1361 | 3.64M | if code == 0 { |
1362 | 852k | fast_mut!((context_map)[context_index as usize]) = 0; |
1363 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); |
1364 | 852k | context_index += 1; |
1365 | 852k | continue; |
1366 | 2.79M | } |
1367 | 2.79M | if code > max_run_length_prefix { |
1368 | 2.62M | fast_mut!((context_map)[context_index as usize]) = |
1369 | 2.62M | (code - max_run_length_prefix) as u8; |
1370 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); |
1371 | 2.62M | context_index += 1; |
1372 | 2.62M | continue; |
1373 | 172k | } |
1374 | 5.86k | } |
1375 | 178k | rleCodeGoto = false; // <- this was a goto beforehand... now we have reached label |
1376 | | // we are treated like everyday citizens from this point forth |
1377 | | { |
1378 | 178k | let mut reps: u32 = 0; |
1379 | 178k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, code, &mut reps, input)) { |
1380 | 6.14k | s.code = code; |
1381 | 6.14k | s.context_index = context_index; |
1382 | 6.14k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
1383 | 172k | } |
1384 | 172k | reps += 1u32 << code; |
1385 | | BROTLI_LOG_UINT!(reps); |
1386 | 172k | if (context_index + reps > context_map_size) { |
1387 | 1.34k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT; |
1388 | 170k | } |
1389 | | loop { |
1390 | 489k | fast_mut!((context_map)[context_index as usize]) = 0; |
1391 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); |
1392 | 489k | context_index += 1; |
1393 | 489k | reps -= 1; |
1394 | 489k | if reps == 0 { |
1395 | 170k | break; |
1396 | 319k | } |
1397 | | } |
1398 | | } |
1399 | | } |
1400 | | // No break, continue to next state. |
1401 | 36.9k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM; |
1402 | | } |
1403 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM => { |
1404 | 53.0k | let mut bits: u32 = 0; |
1405 | 53.0k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input)) { |
1406 | 16.1k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM; |
1407 | 16.1k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
1408 | 36.8k | } |
1409 | 36.8k | if (bits != 0) { |
1410 | 27.5k | if let Ok(ref mut mtf) = s.mtf_or_error_string { |
1411 | 27.5k | InverseMoveToFrontTransform(context_map_arg.slice_mut(), |
1412 | 27.5k | context_map_size, |
1413 | 27.5k | mtf, |
1414 | 27.5k | &mut s.mtf_upper_bound); |
1415 | 27.5k | } else { |
1416 | | // the error state is stored here--we can't make it this deep with an active error |
1417 | 0 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; |
1418 | | } |
1419 | 9.33k | } |
1420 | 36.8k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_NONE; |
1421 | 36.8k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
1422 | | } |
1423 | | } |
1424 | | } |
1425 | | // unreachable!(); (compiler will error if it's reachable due to the unit return type) |
1426 | 317k | } brotli_decompressor::decode::DecodeContextMapInner::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1270 | 217k | fn DecodeContextMapInner<AllocU8: alloc::Allocator<u8>, | 1271 | 217k | AllocU32: alloc::Allocator<u32>, | 1272 | 217k | AllocHC: alloc::Allocator<HuffmanCode>> | 1273 | 217k | (context_map_size: u32, | 1274 | 217k | num_htrees: &mut u32, | 1275 | 217k | context_map_arg: &mut AllocU8::AllocatedMemory, | 1276 | 217k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1277 | 217k | input: &[u8]) | 1278 | 217k | -> BrotliDecoderErrorCode { | 1279 | | | 1280 | | let mut result; | 1281 | | loop { | 1282 | 302k | match s.substate_context_map { | 1283 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_NONE => { | 1284 | 105k | result = DecodeVarLenUint8(&mut s.substate_decode_uint8, &mut s.br, num_htrees, input); | 1285 | 105k | match result { | 1286 | 92.6k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1287 | 13.2k | _ => return result, | 1288 | | } | 1289 | 92.6k | (*num_htrees) += 1; | 1290 | 92.6k | s.context_index = 0; | 1291 | | BROTLI_LOG_UINT!(context_map_size); | 1292 | | BROTLI_LOG_UINT!(*num_htrees); | 1293 | 92.6k | *context_map_arg = s.alloc_u8.alloc_cell(context_map_size as usize); | 1294 | 92.6k | if (context_map_arg.slice().len() < context_map_size as usize) { | 1295 | 0 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP; | 1296 | 92.6k | } | 1297 | 92.6k | if (*num_htrees <= 1) { | 1298 | | // This happens automatically but we do it to retain C++ similarity: | 1299 | 69.4k | bzero(context_map_arg.slice_mut()); // necessary if we compiler with unsafe feature flag | 1300 | 69.4k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1301 | 23.2k | } | 1302 | 23.2k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_READ_PREFIX; | 1303 | | // No break, continue to next state. | 1304 | | } | 1305 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_READ_PREFIX => { | 1306 | 33.6k | let mut bits: u32 = 0; | 1307 | | // In next stage ReadHuffmanCode uses at least 4 bits, so it is safe | 1308 | | // to peek 4 bits ahead. | 1309 | 33.6k | if (!bit_reader::BrotliSafeGetBits(&mut s.br, 5, &mut bits, input)) { | 1310 | 10.4k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1311 | 23.1k | } | 1312 | 23.1k | if ((bits & 1) != 0) { | 1313 | 11.4k | // Use RLE for zeroes. | 1314 | 11.4k | s.max_run_length_prefix = (bits >> 1) + 1; | 1315 | 11.4k | bit_reader::BrotliDropBits(&mut s.br, 5); | 1316 | 11.7k | } else { | 1317 | 11.7k | s.max_run_length_prefix = 0; | 1318 | 11.7k | bit_reader::BrotliDropBits(&mut s.br, 1); | 1319 | 11.7k | } | 1320 | | BROTLI_LOG_UINT!(s.max_run_length_prefix); | 1321 | 23.1k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_HUFFMAN; | 1322 | | // No break, continue to next state. | 1323 | | } | 1324 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_HUFFMAN => { | 1325 | | | 1326 | 88.3k | let mut local_context_map_table = mem::replace(&mut s.context_map_table, | 1327 | 88.3k | AllocHC::AllocatedMemory::default()); | 1328 | 88.3k | let alphabet_size = *num_htrees + s.max_run_length_prefix; | 1329 | 88.3k | result = ReadHuffmanCode(alphabet_size, alphabet_size, | 1330 | 88.3k | &mut local_context_map_table.slice_mut(), | 1331 | 88.3k | 0, | 1332 | 88.3k | None, | 1333 | 88.3k | &mut s, | 1334 | 88.3k | input); | 1335 | 88.3k | let _ = mem::replace(&mut s.context_map_table, | 1336 | 88.3k | mem::replace(&mut local_context_map_table, | 1337 | 88.3k | AllocHC::AllocatedMemory::default())); | 1338 | 88.3k | match result { | 1339 | 19.9k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1340 | 68.4k | _ => return result, | 1341 | | } | 1342 | 19.9k | s.code = 0xFFFF; | 1343 | 19.9k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_DECODE; | 1344 | | // No break, continue to next state. | 1345 | | } | 1346 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_DECODE => { | 1347 | 40.7k | let mut context_index: u32 = s.context_index; | 1348 | 40.7k | let max_run_length_prefix: u32 = s.max_run_length_prefix; | 1349 | 40.7k | let context_map = &mut context_map_arg.slice_mut(); | 1350 | 40.7k | let mut code: u32 = s.code; | 1351 | 40.7k | let mut rleCodeGoto = (code != 0xFFFF); | 1352 | 1.52M | while (rleCodeGoto || context_index < context_map_size) { | 1353 | 1.50M | if !rleCodeGoto { | 1354 | 1.49M | if (!SafeReadSymbol(s.context_map_table.slice(), &mut s.br, &mut code, input)) { | 1355 | 16.1k | s.code = 0xFFFF; | 1356 | 16.1k | s.context_index = context_index; | 1357 | 16.1k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1358 | 1.48M | } | 1359 | | BROTLI_LOG_UINT!(code); | 1360 | | | 1361 | 1.48M | if code == 0 { | 1362 | 155k | fast_mut!((context_map)[context_index as usize]) = 0; | 1363 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); | 1364 | 155k | context_index += 1; | 1365 | 155k | continue; | 1366 | 1.32M | } | 1367 | 1.32M | if code > max_run_length_prefix { | 1368 | 1.25M | fast_mut!((context_map)[context_index as usize]) = | 1369 | 1.25M | (code - max_run_length_prefix) as u8; | 1370 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); | 1371 | 1.25M | context_index += 1; | 1372 | 1.25M | continue; | 1373 | 71.4k | } | 1374 | 5.02k | } | 1375 | 76.4k | rleCodeGoto = false; // <- this was a goto beforehand... now we have reached label | 1376 | | // we are treated like everyday citizens from this point forth | 1377 | | { | 1378 | 76.4k | let mut reps: u32 = 0; | 1379 | 76.4k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, code, &mut reps, input)) { | 1380 | 5.28k | s.code = code; | 1381 | 5.28k | s.context_index = context_index; | 1382 | 5.28k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1383 | 71.1k | } | 1384 | 71.1k | reps += 1u32 << code; | 1385 | | BROTLI_LOG_UINT!(reps); | 1386 | 71.1k | if (context_index + reps > context_map_size) { | 1387 | 501 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT; | 1388 | 70.6k | } | 1389 | | loop { | 1390 | 215k | fast_mut!((context_map)[context_index as usize]) = 0; | 1391 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); | 1392 | 215k | context_index += 1; | 1393 | 215k | reps -= 1; | 1394 | 215k | if reps == 0 { | 1395 | 70.6k | break; | 1396 | 144k | } | 1397 | | } | 1398 | | } | 1399 | | } | 1400 | | // No break, continue to next state. | 1401 | 18.7k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM; | 1402 | | } | 1403 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM => { | 1404 | 33.6k | let mut bits: u32 = 0; | 1405 | 33.6k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input)) { | 1406 | 14.9k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM; | 1407 | 14.9k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1408 | 18.7k | } | 1409 | 18.7k | if (bits != 0) { | 1410 | 14.4k | if let Ok(ref mut mtf) = s.mtf_or_error_string { | 1411 | 14.4k | InverseMoveToFrontTransform(context_map_arg.slice_mut(), | 1412 | 14.4k | context_map_size, | 1413 | 14.4k | mtf, | 1414 | 14.4k | &mut s.mtf_upper_bound); | 1415 | 14.4k | } else { | 1416 | | // the error state is stored here--we can't make it this deep with an active error | 1417 | 0 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; | 1418 | | } | 1419 | 4.23k | } | 1420 | 18.7k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_NONE; | 1421 | 18.7k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1422 | | } | 1423 | | } | 1424 | | } | 1425 | | // unreachable!(); (compiler will error if it's reachable due to the unit return type) | 1426 | 217k | } |
Unexecuted instantiation: brotli_decompressor::decode::DecodeContextMapInner::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::DecodeContextMapInner::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::DecodeContextMapInner::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1270 | 46.2k | fn DecodeContextMapInner<AllocU8: alloc::Allocator<u8>, | 1271 | 46.2k | AllocU32: alloc::Allocator<u32>, | 1272 | 46.2k | AllocHC: alloc::Allocator<HuffmanCode>> | 1273 | 46.2k | (context_map_size: u32, | 1274 | 46.2k | num_htrees: &mut u32, | 1275 | 46.2k | context_map_arg: &mut AllocU8::AllocatedMemory, | 1276 | 46.2k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1277 | 46.2k | input: &[u8]) | 1278 | 46.2k | -> BrotliDecoderErrorCode { | 1279 | | | 1280 | | let mut result; | 1281 | | loop { | 1282 | 80.8k | match s.substate_context_map { | 1283 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_NONE => { | 1284 | 32.1k | result = DecodeVarLenUint8(&mut s.substate_decode_uint8, &mut s.br, num_htrees, input); | 1285 | 32.1k | match result { | 1286 | 30.7k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1287 | 1.43k | _ => return result, | 1288 | | } | 1289 | 30.7k | (*num_htrees) += 1; | 1290 | 30.7k | s.context_index = 0; | 1291 | | BROTLI_LOG_UINT!(context_map_size); | 1292 | | BROTLI_LOG_UINT!(*num_htrees); | 1293 | 30.7k | *context_map_arg = s.alloc_u8.alloc_cell(context_map_size as usize); | 1294 | 30.7k | if (context_map_arg.slice().len() < context_map_size as usize) { | 1295 | 0 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP; | 1296 | 30.7k | } | 1297 | 30.7k | if (*num_htrees <= 1) { | 1298 | | // This happens automatically but we do it to retain C++ similarity: | 1299 | 20.3k | bzero(context_map_arg.slice_mut()); // necessary if we compiler with unsafe feature flag | 1300 | 20.3k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1301 | 10.3k | } | 1302 | 10.3k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_READ_PREFIX; | 1303 | | // No break, continue to next state. | 1304 | | } | 1305 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_READ_PREFIX => { | 1306 | 12.0k | let mut bits: u32 = 0; | 1307 | | // In next stage ReadHuffmanCode uses at least 4 bits, so it is safe | 1308 | | // to peek 4 bits ahead. | 1309 | 12.0k | if (!bit_reader::BrotliSafeGetBits(&mut s.br, 5, &mut bits, input)) { | 1310 | 1.78k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1311 | 10.2k | } | 1312 | 10.2k | if ((bits & 1) != 0) { | 1313 | 5.22k | // Use RLE for zeroes. | 1314 | 5.22k | s.max_run_length_prefix = (bits >> 1) + 1; | 1315 | 5.22k | bit_reader::BrotliDropBits(&mut s.br, 5); | 1316 | 5.22k | } else { | 1317 | 5.01k | s.max_run_length_prefix = 0; | 1318 | 5.01k | bit_reader::BrotliDropBits(&mut s.br, 1); | 1319 | 5.01k | } | 1320 | | BROTLI_LOG_UINT!(s.max_run_length_prefix); | 1321 | 10.2k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_HUFFMAN; | 1322 | | // No break, continue to next state. | 1323 | | } | 1324 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_HUFFMAN => { | 1325 | | | 1326 | 13.0k | let mut local_context_map_table = mem::replace(&mut s.context_map_table, | 1327 | 13.0k | AllocHC::AllocatedMemory::default()); | 1328 | 13.0k | let alphabet_size = *num_htrees + s.max_run_length_prefix; | 1329 | 13.0k | result = ReadHuffmanCode(alphabet_size, alphabet_size, | 1330 | 13.0k | &mut local_context_map_table.slice_mut(), | 1331 | 13.0k | 0, | 1332 | 13.0k | None, | 1333 | 13.0k | &mut s, | 1334 | 13.0k | input); | 1335 | 13.0k | let _ = mem::replace(&mut s.context_map_table, | 1336 | 13.0k | mem::replace(&mut local_context_map_table, | 1337 | 13.0k | AllocHC::AllocatedMemory::default())); | 1338 | 13.0k | match result { | 1339 | 7.33k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1340 | 5.72k | _ => return result, | 1341 | | } | 1342 | 7.33k | s.code = 0xFFFF; | 1343 | 7.33k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_DECODE; | 1344 | | // No break, continue to next state. | 1345 | | } | 1346 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_DECODE => { | 1347 | 16.3k | let mut context_index: u32 = s.context_index; | 1348 | 16.3k | let max_run_length_prefix: u32 = s.max_run_length_prefix; | 1349 | 16.3k | let context_map = &mut context_map_arg.slice_mut(); | 1350 | 16.3k | let mut code: u32 = s.code; | 1351 | 16.3k | let mut rleCodeGoto = (code != 0xFFFF); | 1352 | 1.56M | while (rleCodeGoto || context_index < context_map_size) { | 1353 | 1.56M | if !rleCodeGoto { | 1354 | 1.55M | if (!SafeReadSymbol(s.context_map_table.slice(), &mut s.br, &mut code, input)) { | 1355 | 9.03k | s.code = 0xFFFF; | 1356 | 9.03k | s.context_index = context_index; | 1357 | 9.03k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1358 | 1.55M | } | 1359 | | BROTLI_LOG_UINT!(code); | 1360 | | | 1361 | 1.55M | if code == 0 { | 1362 | 603k | fast_mut!((context_map)[context_index as usize]) = 0; | 1363 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); | 1364 | 603k | context_index += 1; | 1365 | 603k | continue; | 1366 | 947k | } | 1367 | 947k | if code > max_run_length_prefix { | 1368 | 885k | fast_mut!((context_map)[context_index as usize]) = | 1369 | 885k | (code - max_run_length_prefix) as u8; | 1370 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); | 1371 | 885k | context_index += 1; | 1372 | 885k | continue; | 1373 | 62.6k | } | 1374 | 255 | } | 1375 | 62.8k | rleCodeGoto = false; // <- this was a goto beforehand... now we have reached label | 1376 | | // we are treated like everyday citizens from this point forth | 1377 | | { | 1378 | 62.8k | let mut reps: u32 = 0; | 1379 | 62.8k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, code, &mut reps, input)) { | 1380 | 262 | s.code = code; | 1381 | 262 | s.context_index = context_index; | 1382 | 262 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1383 | 62.6k | } | 1384 | 62.6k | reps += 1u32 << code; | 1385 | | BROTLI_LOG_UINT!(reps); | 1386 | 62.6k | if (context_index + reps > context_map_size) { | 1387 | 329 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT; | 1388 | 62.2k | } | 1389 | | loop { | 1390 | 184k | fast_mut!((context_map)[context_index as usize]) = 0; | 1391 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); | 1392 | 184k | context_index += 1; | 1393 | 184k | reps -= 1; | 1394 | 184k | if reps == 0 { | 1395 | 62.2k | break; | 1396 | 122k | } | 1397 | | } | 1398 | | } | 1399 | | } | 1400 | | // No break, continue to next state. | 1401 | 6.72k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM; | 1402 | | } | 1403 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM => { | 1404 | 7.28k | let mut bits: u32 = 0; | 1405 | 7.28k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input)) { | 1406 | 568 | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM; | 1407 | 568 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1408 | 6.71k | } | 1409 | 6.71k | if (bits != 0) { | 1410 | 4.59k | if let Ok(ref mut mtf) = s.mtf_or_error_string { | 1411 | 4.59k | InverseMoveToFrontTransform(context_map_arg.slice_mut(), | 1412 | 4.59k | context_map_size, | 1413 | 4.59k | mtf, | 1414 | 4.59k | &mut s.mtf_upper_bound); | 1415 | 4.59k | } else { | 1416 | | // the error state is stored here--we can't make it this deep with an active error | 1417 | 0 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; | 1418 | | } | 1419 | 2.12k | } | 1420 | 6.71k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_NONE; | 1421 | 6.71k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1422 | | } | 1423 | | } | 1424 | | } | 1425 | | // unreachable!(); (compiler will error if it's reachable due to the unit return type) | 1426 | 46.2k | } |
brotli_decompressor::decode::DecodeContextMapInner::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1270 | 54.0k | fn DecodeContextMapInner<AllocU8: alloc::Allocator<u8>, | 1271 | 54.0k | AllocU32: alloc::Allocator<u32>, | 1272 | 54.0k | AllocHC: alloc::Allocator<HuffmanCode>> | 1273 | 54.0k | (context_map_size: u32, | 1274 | 54.0k | num_htrees: &mut u32, | 1275 | 54.0k | context_map_arg: &mut AllocU8::AllocatedMemory, | 1276 | 54.0k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1277 | 54.0k | input: &[u8]) | 1278 | 54.0k | -> BrotliDecoderErrorCode { | 1279 | | | 1280 | | let mut result; | 1281 | | loop { | 1282 | 105k | match s.substate_context_map { | 1283 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_NONE => { | 1284 | 47.4k | result = DecodeVarLenUint8(&mut s.substate_decode_uint8, &mut s.br, num_htrees, input); | 1285 | 47.4k | match result { | 1286 | 37.7k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1287 | 9.65k | _ => return result, | 1288 | | } | 1289 | 37.7k | (*num_htrees) += 1; | 1290 | 37.7k | s.context_index = 0; | 1291 | | BROTLI_LOG_UINT!(context_map_size); | 1292 | | BROTLI_LOG_UINT!(*num_htrees); | 1293 | 37.7k | *context_map_arg = s.alloc_u8.alloc_cell(context_map_size as usize); | 1294 | 37.7k | if (context_map_arg.slice().len() < context_map_size as usize) { | 1295 | 0 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP; | 1296 | 37.7k | } | 1297 | 37.7k | if (*num_htrees <= 1) { | 1298 | | // This happens automatically but we do it to retain C++ similarity: | 1299 | 23.9k | bzero(context_map_arg.slice_mut()); // necessary if we compiler with unsafe feature flag | 1300 | 23.9k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1301 | 13.8k | } | 1302 | 13.8k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_READ_PREFIX; | 1303 | | // No break, continue to next state. | 1304 | | } | 1305 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_READ_PREFIX => { | 1306 | 14.4k | let mut bits: u32 = 0; | 1307 | | // In next stage ReadHuffmanCode uses at least 4 bits, so it is safe | 1308 | | // to peek 4 bits ahead. | 1309 | 14.4k | if (!bit_reader::BrotliSafeGetBits(&mut s.br, 5, &mut bits, input)) { | 1310 | 657 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1311 | 13.8k | } | 1312 | 13.8k | if ((bits & 1) != 0) { | 1313 | 5.09k | // Use RLE for zeroes. | 1314 | 5.09k | s.max_run_length_prefix = (bits >> 1) + 1; | 1315 | 5.09k | bit_reader::BrotliDropBits(&mut s.br, 5); | 1316 | 8.72k | } else { | 1317 | 8.72k | s.max_run_length_prefix = 0; | 1318 | 8.72k | bit_reader::BrotliDropBits(&mut s.br, 1); | 1319 | 8.72k | } | 1320 | | BROTLI_LOG_UINT!(s.max_run_length_prefix); | 1321 | 13.8k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_HUFFMAN; | 1322 | | // No break, continue to next state. | 1323 | | } | 1324 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_HUFFMAN => { | 1325 | | | 1326 | 16.6k | let mut local_context_map_table = mem::replace(&mut s.context_map_table, | 1327 | 16.6k | AllocHC::AllocatedMemory::default()); | 1328 | 16.6k | let alphabet_size = *num_htrees + s.max_run_length_prefix; | 1329 | 16.6k | result = ReadHuffmanCode(alphabet_size, alphabet_size, | 1330 | 16.6k | &mut local_context_map_table.slice_mut(), | 1331 | 16.6k | 0, | 1332 | 16.6k | None, | 1333 | 16.6k | &mut s, | 1334 | 16.6k | input); | 1335 | 16.6k | let _ = mem::replace(&mut s.context_map_table, | 1336 | 16.6k | mem::replace(&mut local_context_map_table, | 1337 | 16.6k | AllocHC::AllocatedMemory::default())); | 1338 | 16.6k | match result { | 1339 | 12.0k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1340 | 4.59k | _ => return result, | 1341 | | } | 1342 | 12.0k | s.code = 0xFFFF; | 1343 | 12.0k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_DECODE; | 1344 | | // No break, continue to next state. | 1345 | | } | 1346 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_DECODE => { | 1347 | 14.6k | let mut context_index: u32 = s.context_index; | 1348 | 14.6k | let max_run_length_prefix: u32 = s.max_run_length_prefix; | 1349 | 14.6k | let context_map = &mut context_map_arg.slice_mut(); | 1350 | 14.6k | let mut code: u32 = s.code; | 1351 | 14.6k | let mut rleCodeGoto = (code != 0xFFFF); | 1352 | 630k | while (rleCodeGoto || context_index < context_map_size) { | 1353 | 618k | if !rleCodeGoto { | 1354 | 618k | if (!SafeReadSymbol(s.context_map_table.slice(), &mut s.br, &mut code, input)) { | 1355 | 2.08k | s.code = 0xFFFF; | 1356 | 2.08k | s.context_index = context_index; | 1357 | 2.08k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1358 | 616k | } | 1359 | | BROTLI_LOG_UINT!(code); | 1360 | | | 1361 | 616k | if code == 0 { | 1362 | 93.1k | fast_mut!((context_map)[context_index as usize]) = 0; | 1363 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); | 1364 | 93.1k | context_index += 1; | 1365 | 93.1k | continue; | 1366 | 522k | } | 1367 | 522k | if code > max_run_length_prefix { | 1368 | 484k | fast_mut!((context_map)[context_index as usize]) = | 1369 | 484k | (code - max_run_length_prefix) as u8; | 1370 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); | 1371 | 484k | context_index += 1; | 1372 | 484k | continue; | 1373 | 38.3k | } | 1374 | 581 | } | 1375 | 38.9k | rleCodeGoto = false; // <- this was a goto beforehand... now we have reached label | 1376 | | // we are treated like everyday citizens from this point forth | 1377 | | { | 1378 | 38.9k | let mut reps: u32 = 0; | 1379 | 38.9k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, code, &mut reps, input)) { | 1380 | 598 | s.code = code; | 1381 | 598 | s.context_index = context_index; | 1382 | 598 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1383 | 38.3k | } | 1384 | 38.3k | reps += 1u32 << code; | 1385 | | BROTLI_LOG_UINT!(reps); | 1386 | 38.3k | if (context_index + reps > context_map_size) { | 1387 | 512 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT; | 1388 | 37.7k | } | 1389 | | loop { | 1390 | 89.6k | fast_mut!((context_map)[context_index as usize]) = 0; | 1391 | | BROTLI_LOG_ARRAY_INDEX!(context_map, context_index as usize); | 1392 | 89.6k | context_index += 1; | 1393 | 89.6k | reps -= 1; | 1394 | 89.6k | if reps == 0 { | 1395 | 37.7k | break; | 1396 | 51.8k | } | 1397 | | } | 1398 | | } | 1399 | | } | 1400 | | // No break, continue to next state. | 1401 | 11.4k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM; | 1402 | | } | 1403 | | BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM => { | 1404 | 12.0k | let mut bits: u32 = 0; | 1405 | 12.0k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 1, &mut bits, input)) { | 1406 | 602 | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_TRANSFORM; | 1407 | 602 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1408 | 11.4k | } | 1409 | 11.4k | if (bits != 0) { | 1410 | 8.46k | if let Ok(ref mut mtf) = s.mtf_or_error_string { | 1411 | 8.46k | InverseMoveToFrontTransform(context_map_arg.slice_mut(), | 1412 | 8.46k | context_map_size, | 1413 | 8.46k | mtf, | 1414 | 8.46k | &mut s.mtf_upper_bound); | 1415 | 8.46k | } else { | 1416 | | // the error state is stored here--we can't make it this deep with an active error | 1417 | 0 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; | 1418 | | } | 1419 | 2.98k | } | 1420 | 11.4k | s.substate_context_map = BrotliRunningContextMapState::BROTLI_STATE_CONTEXT_MAP_NONE; | 1421 | 11.4k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1422 | | } | 1423 | | } | 1424 | | } | 1425 | | // unreachable!(); (compiler will error if it's reachable due to the unit return type) | 1426 | 54.0k | } |
|
1427 | | |
1428 | 317k | fn DecodeContextMap<AllocU8: alloc::Allocator<u8>, |
1429 | 317k | AllocU32: alloc::Allocator<u32>, |
1430 | 317k | AllocHC: alloc::Allocator<HuffmanCode>> |
1431 | 317k | (context_map_size: usize, |
1432 | 317k | is_dist_context_map: bool, |
1433 | 317k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1434 | 317k | input: &[u8]) |
1435 | 317k | -> BrotliDecoderErrorCode { |
1436 | | |
1437 | 317k | match s.state { |
1438 | 166k | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1 => assert_eq!(is_dist_context_map, false), |
1439 | 150k | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2 => assert_eq!(is_dist_context_map, true), |
1440 | 0 | _ => unreachable!(), |
1441 | | } |
1442 | 317k | let (mut num_htrees, mut context_map_arg) = if is_dist_context_map { |
1443 | 150k | (s.num_dist_htrees, mem::replace(&mut s.dist_context_map, AllocU8::AllocatedMemory::default())) |
1444 | | } else { |
1445 | 166k | (s.num_literal_htrees, mem::replace(&mut s.context_map, AllocU8::AllocatedMemory::default())) |
1446 | | }; |
1447 | | |
1448 | 317k | let retval = DecodeContextMapInner(context_map_size as u32, |
1449 | 317k | &mut num_htrees, |
1450 | 317k | &mut context_map_arg, |
1451 | 317k | &mut s, |
1452 | 317k | input); |
1453 | 317k | if is_dist_context_map { |
1454 | 150k | s.num_dist_htrees = num_htrees; |
1455 | 150k | let _ = mem::replace(&mut s.dist_context_map, |
1456 | 150k | mem::replace(&mut context_map_arg, AllocU8::AllocatedMemory::default())); |
1457 | 166k | } else { |
1458 | 166k | s.num_literal_htrees = num_htrees; |
1459 | 166k | let _ = mem::replace(&mut s.context_map, |
1460 | 166k | mem::replace(&mut context_map_arg, AllocU8::AllocatedMemory::default())); |
1461 | 166k | } |
1462 | 317k | retval |
1463 | 317k | } brotli_decompressor::decode::DecodeContextMap::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1428 | 217k | fn DecodeContextMap<AllocU8: alloc::Allocator<u8>, | 1429 | 217k | AllocU32: alloc::Allocator<u32>, | 1430 | 217k | AllocHC: alloc::Allocator<HuffmanCode>> | 1431 | 217k | (context_map_size: usize, | 1432 | 217k | is_dist_context_map: bool, | 1433 | 217k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1434 | 217k | input: &[u8]) | 1435 | 217k | -> BrotliDecoderErrorCode { | 1436 | | | 1437 | 217k | match s.state { | 1438 | 112k | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1 => assert_eq!(is_dist_context_map, false), | 1439 | 104k | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2 => assert_eq!(is_dist_context_map, true), | 1440 | 0 | _ => unreachable!(), | 1441 | | } | 1442 | 217k | let (mut num_htrees, mut context_map_arg) = if is_dist_context_map { | 1443 | 104k | (s.num_dist_htrees, mem::replace(&mut s.dist_context_map, AllocU8::AllocatedMemory::default())) | 1444 | | } else { | 1445 | 112k | (s.num_literal_htrees, mem::replace(&mut s.context_map, AllocU8::AllocatedMemory::default())) | 1446 | | }; | 1447 | | | 1448 | 217k | let retval = DecodeContextMapInner(context_map_size as u32, | 1449 | 217k | &mut num_htrees, | 1450 | 217k | &mut context_map_arg, | 1451 | 217k | &mut s, | 1452 | 217k | input); | 1453 | 217k | if is_dist_context_map { | 1454 | 104k | s.num_dist_htrees = num_htrees; | 1455 | 104k | let _ = mem::replace(&mut s.dist_context_map, | 1456 | 104k | mem::replace(&mut context_map_arg, AllocU8::AllocatedMemory::default())); | 1457 | 112k | } else { | 1458 | 112k | s.num_literal_htrees = num_htrees; | 1459 | 112k | let _ = mem::replace(&mut s.context_map, | 1460 | 112k | mem::replace(&mut context_map_arg, AllocU8::AllocatedMemory::default())); | 1461 | 112k | } | 1462 | 217k | retval | 1463 | 217k | } |
Unexecuted instantiation: brotli_decompressor::decode::DecodeContextMap::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::DecodeContextMap::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::DecodeContextMap::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1428 | 46.2k | fn DecodeContextMap<AllocU8: alloc::Allocator<u8>, | 1429 | 46.2k | AllocU32: alloc::Allocator<u32>, | 1430 | 46.2k | AllocHC: alloc::Allocator<HuffmanCode>> | 1431 | 46.2k | (context_map_size: usize, | 1432 | 46.2k | is_dist_context_map: bool, | 1433 | 46.2k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1434 | 46.2k | input: &[u8]) | 1435 | 46.2k | -> BrotliDecoderErrorCode { | 1436 | | | 1437 | 46.2k | match s.state { | 1438 | 29.1k | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1 => assert_eq!(is_dist_context_map, false), | 1439 | 17.0k | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2 => assert_eq!(is_dist_context_map, true), | 1440 | 0 | _ => unreachable!(), | 1441 | | } | 1442 | 46.2k | let (mut num_htrees, mut context_map_arg) = if is_dist_context_map { | 1443 | 17.0k | (s.num_dist_htrees, mem::replace(&mut s.dist_context_map, AllocU8::AllocatedMemory::default())) | 1444 | | } else { | 1445 | 29.1k | (s.num_literal_htrees, mem::replace(&mut s.context_map, AllocU8::AllocatedMemory::default())) | 1446 | | }; | 1447 | | | 1448 | 46.2k | let retval = DecodeContextMapInner(context_map_size as u32, | 1449 | 46.2k | &mut num_htrees, | 1450 | 46.2k | &mut context_map_arg, | 1451 | 46.2k | &mut s, | 1452 | 46.2k | input); | 1453 | 46.2k | if is_dist_context_map { | 1454 | 17.0k | s.num_dist_htrees = num_htrees; | 1455 | 17.0k | let _ = mem::replace(&mut s.dist_context_map, | 1456 | 17.0k | mem::replace(&mut context_map_arg, AllocU8::AllocatedMemory::default())); | 1457 | 29.1k | } else { | 1458 | 29.1k | s.num_literal_htrees = num_htrees; | 1459 | 29.1k | let _ = mem::replace(&mut s.context_map, | 1460 | 29.1k | mem::replace(&mut context_map_arg, AllocU8::AllocatedMemory::default())); | 1461 | 29.1k | } | 1462 | 46.2k | retval | 1463 | 46.2k | } |
brotli_decompressor::decode::DecodeContextMap::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1428 | 54.0k | fn DecodeContextMap<AllocU8: alloc::Allocator<u8>, | 1429 | 54.0k | AllocU32: alloc::Allocator<u32>, | 1430 | 54.0k | AllocHC: alloc::Allocator<HuffmanCode>> | 1431 | 54.0k | (context_map_size: usize, | 1432 | 54.0k | is_dist_context_map: bool, | 1433 | 54.0k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1434 | 54.0k | input: &[u8]) | 1435 | 54.0k | -> BrotliDecoderErrorCode { | 1436 | | | 1437 | 54.0k | match s.state { | 1438 | 25.0k | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1 => assert_eq!(is_dist_context_map, false), | 1439 | 29.0k | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2 => assert_eq!(is_dist_context_map, true), | 1440 | 0 | _ => unreachable!(), | 1441 | | } | 1442 | 54.0k | let (mut num_htrees, mut context_map_arg) = if is_dist_context_map { | 1443 | 29.0k | (s.num_dist_htrees, mem::replace(&mut s.dist_context_map, AllocU8::AllocatedMemory::default())) | 1444 | | } else { | 1445 | 25.0k | (s.num_literal_htrees, mem::replace(&mut s.context_map, AllocU8::AllocatedMemory::default())) | 1446 | | }; | 1447 | | | 1448 | 54.0k | let retval = DecodeContextMapInner(context_map_size as u32, | 1449 | 54.0k | &mut num_htrees, | 1450 | 54.0k | &mut context_map_arg, | 1451 | 54.0k | &mut s, | 1452 | 54.0k | input); | 1453 | 54.0k | if is_dist_context_map { | 1454 | 29.0k | s.num_dist_htrees = num_htrees; | 1455 | 29.0k | let _ = mem::replace(&mut s.dist_context_map, | 1456 | 29.0k | mem::replace(&mut context_map_arg, AllocU8::AllocatedMemory::default())); | 1457 | 29.0k | } else { | 1458 | 25.0k | s.num_literal_htrees = num_htrees; | 1459 | 25.0k | let _ = mem::replace(&mut s.context_map, | 1460 | 25.0k | mem::replace(&mut context_map_arg, AllocU8::AllocatedMemory::default())); | 1461 | 25.0k | } | 1462 | 54.0k | retval | 1463 | 54.0k | } |
|
1464 | | |
1465 | | // Decodes a command or literal and updates block type ringbuffer. |
1466 | | // Reads 3..54 bits. |
1467 | 10.8M | fn DecodeBlockTypeAndLength< |
1468 | 10.8M | AllocHC : alloc::Allocator<HuffmanCode>> (safe : bool, |
1469 | 10.8M | s : &mut BlockTypeAndLengthState<AllocHC>, |
1470 | 10.8M | br : &mut bit_reader::BrotliBitReader, |
1471 | 10.8M | tree_type : i32, |
1472 | 10.8M | input : &[u8]) -> bool { |
1473 | 10.8M | let max_block_type = fast!((s.num_block_types)[tree_type as usize]); |
1474 | 10.8M | let tree_offset = tree_type as usize * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize; |
1475 | | |
1476 | 10.8M | let mut block_type: u32 = 0; |
1477 | 10.8M | if max_block_type <= 1 { |
1478 | 3 | return false; |
1479 | 10.8M | } |
1480 | | // Read 0..15 + 3..39 bits |
1481 | 10.8M | if (!safe) { |
1482 | 10.5M | block_type = ReadSymbol(fast_slice!((s.block_type_trees)[tree_offset;]), br, input); |
1483 | 10.5M | fast_mut!((s.block_length)[tree_type as usize]) = |
1484 | 10.5M | ReadBlockLength(fast_slice!((s.block_len_trees)[tree_offset;]), br, input); |
1485 | 10.5M | } else { |
1486 | 373k | let memento = bit_reader::BrotliBitReaderSaveState(br); |
1487 | 373k | if (!SafeReadSymbol(fast_slice!((s.block_type_trees)[tree_offset;]), |
1488 | 373k | br, |
1489 | 373k | &mut block_type, |
1490 | 373k | input)) { |
1491 | 11.7k | return false; |
1492 | 361k | } |
1493 | 361k | let mut block_length_out: u32 = 0; |
1494 | | |
1495 | 361k | let index_ret = SafeReadBlockLengthIndex(&s.substate_read_block_length, |
1496 | 361k | s.block_length_index, |
1497 | 361k | fast_slice!((s.block_len_trees)[tree_offset;]), |
1498 | 361k | br, |
1499 | 361k | input); |
1500 | 361k | if !SafeReadBlockLengthFromIndex(s, br, &mut block_length_out, index_ret, input) { |
1501 | 60.7k | s.substate_read_block_length = |
1502 | 60.7k | BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_NONE; |
1503 | 60.7k | bit_reader::BrotliBitReaderRestoreState(br, &memento); |
1504 | 60.7k | return false; |
1505 | 300k | } |
1506 | 300k | fast_mut!((s.block_length)[tree_type as usize]) = block_length_out; |
1507 | | } |
1508 | 10.8M | let ringbuffer: &mut [u32] = &mut fast_mut!((s.block_type_rb)[tree_type as usize * 2;]); |
1509 | 10.8M | if (block_type == 1) { |
1510 | 3.11M | block_type = fast!((ringbuffer)[1]) + 1; |
1511 | 7.70M | } else if (block_type == 0) { |
1512 | 7.48M | block_type = fast!((ringbuffer)[0]); |
1513 | 7.48M | } else { |
1514 | 223k | block_type -= 2; |
1515 | 223k | } |
1516 | 10.8M | if (block_type >= max_block_type) { |
1517 | 1.48M | block_type -= max_block_type; |
1518 | 9.33M | } |
1519 | 10.8M | fast_mut!((ringbuffer)[0]) = fast!((ringbuffer)[1]); |
1520 | 10.8M | fast_mut!((ringbuffer)[1]) = block_type; |
1521 | 10.8M | true |
1522 | 10.8M | } brotli_decompressor::decode::DecodeBlockTypeAndLength::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1467 | 1.50M | fn DecodeBlockTypeAndLength< | 1468 | 1.50M | AllocHC : alloc::Allocator<HuffmanCode>> (safe : bool, | 1469 | 1.50M | s : &mut BlockTypeAndLengthState<AllocHC>, | 1470 | 1.50M | br : &mut bit_reader::BrotliBitReader, | 1471 | 1.50M | tree_type : i32, | 1472 | 1.50M | input : &[u8]) -> bool { | 1473 | 1.50M | let max_block_type = fast!((s.num_block_types)[tree_type as usize]); | 1474 | 1.50M | let tree_offset = tree_type as usize * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize; | 1475 | | | 1476 | 1.50M | let mut block_type: u32 = 0; | 1477 | 1.50M | if max_block_type <= 1 { | 1478 | 3 | return false; | 1479 | 1.50M | } | 1480 | | // Read 0..15 + 3..39 bits | 1481 | 1.50M | if (!safe) { | 1482 | 1.28M | block_type = ReadSymbol(fast_slice!((s.block_type_trees)[tree_offset;]), br, input); | 1483 | 1.28M | fast_mut!((s.block_length)[tree_type as usize]) = | 1484 | 1.28M | ReadBlockLength(fast_slice!((s.block_len_trees)[tree_offset;]), br, input); | 1485 | 1.28M | } else { | 1486 | 223k | let memento = bit_reader::BrotliBitReaderSaveState(br); | 1487 | 223k | if (!SafeReadSymbol(fast_slice!((s.block_type_trees)[tree_offset;]), | 1488 | 223k | br, | 1489 | 223k | &mut block_type, | 1490 | 223k | input)) { | 1491 | 5.59k | return false; | 1492 | 217k | } | 1493 | 217k | let mut block_length_out: u32 = 0; | 1494 | | | 1495 | 217k | let index_ret = SafeReadBlockLengthIndex(&s.substate_read_block_length, | 1496 | 217k | s.block_length_index, | 1497 | 217k | fast_slice!((s.block_len_trees)[tree_offset;]), | 1498 | 217k | br, | 1499 | 217k | input); | 1500 | 217k | if !SafeReadBlockLengthFromIndex(s, br, &mut block_length_out, index_ret, input) { | 1501 | 41.7k | s.substate_read_block_length = | 1502 | 41.7k | BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_NONE; | 1503 | 41.7k | bit_reader::BrotliBitReaderRestoreState(br, &memento); | 1504 | 41.7k | return false; | 1505 | 176k | } | 1506 | 176k | fast_mut!((s.block_length)[tree_type as usize]) = block_length_out; | 1507 | | } | 1508 | 1.45M | let ringbuffer: &mut [u32] = &mut fast_mut!((s.block_type_rb)[tree_type as usize * 2;]); | 1509 | 1.45M | if (block_type == 1) { | 1510 | 123k | block_type = fast!((ringbuffer)[1]) + 1; | 1511 | 1.33M | } else if (block_type == 0) { | 1512 | 1.25M | block_type = fast!((ringbuffer)[0]); | 1513 | 1.25M | } else { | 1514 | 78.8k | block_type -= 2; | 1515 | 78.8k | } | 1516 | 1.45M | if (block_type >= max_block_type) { | 1517 | 26.4k | block_type -= max_block_type; | 1518 | 1.43M | } | 1519 | 1.45M | fast_mut!((ringbuffer)[0]) = fast!((ringbuffer)[1]); | 1520 | 1.45M | fast_mut!((ringbuffer)[1]) = block_type; | 1521 | 1.45M | true | 1522 | 1.50M | } |
Unexecuted instantiation: brotli_decompressor::decode::DecodeBlockTypeAndLength::<alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::DecodeBlockTypeAndLength::<alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::DecodeBlockTypeAndLength::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1467 | 9.15M | fn DecodeBlockTypeAndLength< | 1468 | 9.15M | AllocHC : alloc::Allocator<HuffmanCode>> (safe : bool, | 1469 | 9.15M | s : &mut BlockTypeAndLengthState<AllocHC>, | 1470 | 9.15M | br : &mut bit_reader::BrotliBitReader, | 1471 | 9.15M | tree_type : i32, | 1472 | 9.15M | input : &[u8]) -> bool { | 1473 | 9.15M | let max_block_type = fast!((s.num_block_types)[tree_type as usize]); | 1474 | 9.15M | let tree_offset = tree_type as usize * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize; | 1475 | | | 1476 | 9.15M | let mut block_type: u32 = 0; | 1477 | 9.15M | if max_block_type <= 1 { | 1478 | 0 | return false; | 1479 | 9.15M | } | 1480 | | // Read 0..15 + 3..39 bits | 1481 | 9.15M | if (!safe) { | 1482 | 9.08M | block_type = ReadSymbol(fast_slice!((s.block_type_trees)[tree_offset;]), br, input); | 1483 | 9.08M | fast_mut!((s.block_length)[tree_type as usize]) = | 1484 | 9.08M | ReadBlockLength(fast_slice!((s.block_len_trees)[tree_offset;]), br, input); | 1485 | 9.08M | } else { | 1486 | 68.2k | let memento = bit_reader::BrotliBitReaderSaveState(br); | 1487 | 68.2k | if (!SafeReadSymbol(fast_slice!((s.block_type_trees)[tree_offset;]), | 1488 | 68.2k | br, | 1489 | 68.2k | &mut block_type, | 1490 | 68.2k | input)) { | 1491 | 1.35k | return false; | 1492 | 66.8k | } | 1493 | 66.8k | let mut block_length_out: u32 = 0; | 1494 | | | 1495 | 66.8k | let index_ret = SafeReadBlockLengthIndex(&s.substate_read_block_length, | 1496 | 66.8k | s.block_length_index, | 1497 | 66.8k | fast_slice!((s.block_len_trees)[tree_offset;]), | 1498 | 66.8k | br, | 1499 | 66.8k | input); | 1500 | 66.8k | if !SafeReadBlockLengthFromIndex(s, br, &mut block_length_out, index_ret, input) { | 1501 | 3.88k | s.substate_read_block_length = | 1502 | 3.88k | BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_NONE; | 1503 | 3.88k | bit_reader::BrotliBitReaderRestoreState(br, &memento); | 1504 | 3.88k | return false; | 1505 | 62.9k | } | 1506 | 62.9k | fast_mut!((s.block_length)[tree_type as usize]) = block_length_out; | 1507 | | } | 1508 | 9.14M | let ringbuffer: &mut [u32] = &mut fast_mut!((s.block_type_rb)[tree_type as usize * 2;]); | 1509 | 9.14M | if (block_type == 1) { | 1510 | 2.94M | block_type = fast!((ringbuffer)[1]) + 1; | 1511 | 6.20M | } else if (block_type == 0) { | 1512 | 6.08M | block_type = fast!((ringbuffer)[0]); | 1513 | 6.08M | } else { | 1514 | 117k | block_type -= 2; | 1515 | 117k | } | 1516 | 9.14M | if (block_type >= max_block_type) { | 1517 | 1.45M | block_type -= max_block_type; | 1518 | 7.69M | } | 1519 | 9.14M | fast_mut!((ringbuffer)[0]) = fast!((ringbuffer)[1]); | 1520 | 9.14M | fast_mut!((ringbuffer)[1]) = block_type; | 1521 | 9.14M | true | 1522 | 9.15M | } |
brotli_decompressor::decode::DecodeBlockTypeAndLength::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1467 | 234k | fn DecodeBlockTypeAndLength< | 1468 | 234k | AllocHC : alloc::Allocator<HuffmanCode>> (safe : bool, | 1469 | 234k | s : &mut BlockTypeAndLengthState<AllocHC>, | 1470 | 234k | br : &mut bit_reader::BrotliBitReader, | 1471 | 234k | tree_type : i32, | 1472 | 234k | input : &[u8]) -> bool { | 1473 | 234k | let max_block_type = fast!((s.num_block_types)[tree_type as usize]); | 1474 | 234k | let tree_offset = tree_type as usize * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize; | 1475 | | | 1476 | 234k | let mut block_type: u32 = 0; | 1477 | 234k | if max_block_type <= 1 { | 1478 | 0 | return false; | 1479 | 234k | } | 1480 | | // Read 0..15 + 3..39 bits | 1481 | 234k | if (!safe) { | 1482 | 153k | block_type = ReadSymbol(fast_slice!((s.block_type_trees)[tree_offset;]), br, input); | 1483 | 153k | fast_mut!((s.block_length)[tree_type as usize]) = | 1484 | 153k | ReadBlockLength(fast_slice!((s.block_len_trees)[tree_offset;]), br, input); | 1485 | 153k | } else { | 1486 | 81.7k | let memento = bit_reader::BrotliBitReaderSaveState(br); | 1487 | 81.7k | if (!SafeReadSymbol(fast_slice!((s.block_type_trees)[tree_offset;]), | 1488 | 81.7k | br, | 1489 | 81.7k | &mut block_type, | 1490 | 81.7k | input)) { | 1491 | 4.76k | return false; | 1492 | 76.9k | } | 1493 | 76.9k | let mut block_length_out: u32 = 0; | 1494 | | | 1495 | 76.9k | let index_ret = SafeReadBlockLengthIndex(&s.substate_read_block_length, | 1496 | 76.9k | s.block_length_index, | 1497 | 76.9k | fast_slice!((s.block_len_trees)[tree_offset;]), | 1498 | 76.9k | br, | 1499 | 76.9k | input); | 1500 | 76.9k | if !SafeReadBlockLengthFromIndex(s, br, &mut block_length_out, index_ret, input) { | 1501 | 15.1k | s.substate_read_block_length = | 1502 | 15.1k | BrotliRunningReadBlockLengthState::BROTLI_STATE_READ_BLOCK_LENGTH_NONE; | 1503 | 15.1k | bit_reader::BrotliBitReaderRestoreState(br, &memento); | 1504 | 15.1k | return false; | 1505 | 61.8k | } | 1506 | 61.8k | fast_mut!((s.block_length)[tree_type as usize]) = block_length_out; | 1507 | | } | 1508 | 215k | let ringbuffer: &mut [u32] = &mut fast_mut!((s.block_type_rb)[tree_type as usize * 2;]); | 1509 | 215k | if (block_type == 1) { | 1510 | 45.5k | block_type = fast!((ringbuffer)[1]) + 1; | 1511 | 169k | } else if (block_type == 0) { | 1512 | 142k | block_type = fast!((ringbuffer)[0]); | 1513 | 142k | } else { | 1514 | 27.2k | block_type -= 2; | 1515 | 27.2k | } | 1516 | 215k | if (block_type >= max_block_type) { | 1517 | 5.69k | block_type -= max_block_type; | 1518 | 209k | } | 1519 | 215k | fast_mut!((ringbuffer)[0]) = fast!((ringbuffer)[1]); | 1520 | 215k | fast_mut!((ringbuffer)[1]) = block_type; | 1521 | 215k | true | 1522 | 234k | } |
|
1523 | 78.5k | fn DetectTrivialLiteralBlockTypes<AllocU8: alloc::Allocator<u8>, |
1524 | 78.5k | AllocU32: alloc::Allocator<u32>, |
1525 | 78.5k | AllocHC: alloc::Allocator<HuffmanCode>> |
1526 | 78.5k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { |
1527 | 628k | for iter in s.trivial_literal_contexts.iter_mut() { |
1528 | 628k | *iter = 0; |
1529 | 628k | } |
1530 | 78.5k | let mut i: usize = 0; |
1531 | 433k | while i < fast!((s.block_type_length_state.num_block_types)[0]) as usize { |
1532 | 354k | let offset = (i as usize) << kLiteralContextBits; |
1533 | 354k | let mut error = 0usize; |
1534 | 354k | let sample: usize = fast_slice!((s.context_map)[offset]) as usize; |
1535 | 354k | let mut j = 0usize; |
1536 | 6.02M | while j < ((1 as usize) << kLiteralContextBits) { |
1537 | 5.67M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; |
1538 | 5.67M | j += 1; |
1539 | 5.67M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; |
1540 | 5.67M | j += 1; |
1541 | 5.67M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; |
1542 | 5.67M | j += 1; |
1543 | 5.67M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; |
1544 | 5.67M | j += 1 |
1545 | | } |
1546 | 354k | if error == 0 { |
1547 | 309k | s.trivial_literal_contexts[i >> 5] |= ((1 as u32) << (i & 31)); |
1548 | 309k | } |
1549 | 354k | i += 1 |
1550 | | } |
1551 | 78.5k | } brotli_decompressor::decode::DetectTrivialLiteralBlockTypes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1523 | 45.6k | fn DetectTrivialLiteralBlockTypes<AllocU8: alloc::Allocator<u8>, | 1524 | 45.6k | AllocU32: alloc::Allocator<u32>, | 1525 | 45.6k | AllocHC: alloc::Allocator<HuffmanCode>> | 1526 | 45.6k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { | 1527 | 365k | for iter in s.trivial_literal_contexts.iter_mut() { | 1528 | 365k | *iter = 0; | 1529 | 365k | } | 1530 | 45.6k | let mut i: usize = 0; | 1531 | 164k | while i < fast!((s.block_type_length_state.num_block_types)[0]) as usize { | 1532 | 118k | let offset = (i as usize) << kLiteralContextBits; | 1533 | 118k | let mut error = 0usize; | 1534 | 118k | let sample: usize = fast_slice!((s.context_map)[offset]) as usize; | 1535 | 118k | let mut j = 0usize; | 1536 | 2.01M | while j < ((1 as usize) << kLiteralContextBits) { | 1537 | 1.89M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1538 | 1.89M | j += 1; | 1539 | 1.89M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1540 | 1.89M | j += 1; | 1541 | 1.89M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1542 | 1.89M | j += 1; | 1543 | 1.89M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1544 | 1.89M | j += 1 | 1545 | | } | 1546 | 118k | if error == 0 { | 1547 | 98.6k | s.trivial_literal_contexts[i >> 5] |= ((1 as u32) << (i & 31)); | 1548 | 98.6k | } | 1549 | 118k | i += 1 | 1550 | | } | 1551 | 45.6k | } |
Unexecuted instantiation: brotli_decompressor::decode::DetectTrivialLiteralBlockTypes::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::DetectTrivialLiteralBlockTypes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::DetectTrivialLiteralBlockTypes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1523 | 14.3k | fn DetectTrivialLiteralBlockTypes<AllocU8: alloc::Allocator<u8>, | 1524 | 14.3k | AllocU32: alloc::Allocator<u32>, | 1525 | 14.3k | AllocHC: alloc::Allocator<HuffmanCode>> | 1526 | 14.3k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { | 1527 | 114k | for iter in s.trivial_literal_contexts.iter_mut() { | 1528 | 114k | *iter = 0; | 1529 | 114k | } | 1530 | 14.3k | let mut i: usize = 0; | 1531 | 211k | while i < fast!((s.block_type_length_state.num_block_types)[0]) as usize { | 1532 | 197k | let offset = (i as usize) << kLiteralContextBits; | 1533 | 197k | let mut error = 0usize; | 1534 | 197k | let sample: usize = fast_slice!((s.context_map)[offset]) as usize; | 1535 | 197k | let mut j = 0usize; | 1536 | 3.35M | while j < ((1 as usize) << kLiteralContextBits) { | 1537 | 3.15M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1538 | 3.15M | j += 1; | 1539 | 3.15M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1540 | 3.15M | j += 1; | 1541 | 3.15M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1542 | 3.15M | j += 1; | 1543 | 3.15M | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1544 | 3.15M | j += 1 | 1545 | | } | 1546 | 197k | if error == 0 { | 1547 | 180k | s.trivial_literal_contexts[i >> 5] |= ((1 as u32) << (i & 31)); | 1548 | 180k | } | 1549 | 197k | i += 1 | 1550 | | } | 1551 | 14.3k | } |
brotli_decompressor::decode::DetectTrivialLiteralBlockTypes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1523 | 18.5k | fn DetectTrivialLiteralBlockTypes<AllocU8: alloc::Allocator<u8>, | 1524 | 18.5k | AllocU32: alloc::Allocator<u32>, | 1525 | 18.5k | AllocHC: alloc::Allocator<HuffmanCode>> | 1526 | 18.5k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { | 1527 | 148k | for iter in s.trivial_literal_contexts.iter_mut() { | 1528 | 148k | *iter = 0; | 1529 | 148k | } | 1530 | 18.5k | let mut i: usize = 0; | 1531 | 57.5k | while i < fast!((s.block_type_length_state.num_block_types)[0]) as usize { | 1532 | 38.9k | let offset = (i as usize) << kLiteralContextBits; | 1533 | 38.9k | let mut error = 0usize; | 1534 | 38.9k | let sample: usize = fast_slice!((s.context_map)[offset]) as usize; | 1535 | 38.9k | let mut j = 0usize; | 1536 | 662k | while j < ((1 as usize) << kLiteralContextBits) { | 1537 | 623k | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1538 | 623k | j += 1; | 1539 | 623k | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1540 | 623k | j += 1; | 1541 | 623k | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1542 | 623k | j += 1; | 1543 | 623k | error |= fast_slice!((s.context_map)[offset + j]) as usize ^ sample; | 1544 | 623k | j += 1 | 1545 | | } | 1546 | 38.9k | if error == 0 { | 1547 | 30.9k | s.trivial_literal_contexts[i >> 5] |= ((1 as u32) << (i & 31)); | 1548 | 30.9k | } | 1549 | 38.9k | i += 1 | 1550 | | } | 1551 | 18.5k | } |
|
1552 | 9.69M | fn PrepareLiteralDecoding<AllocU8: alloc::Allocator<u8>, |
1553 | 9.69M | AllocU32: alloc::Allocator<u32>, |
1554 | 9.69M | AllocHC: alloc::Allocator<HuffmanCode>> |
1555 | 9.69M | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { |
1556 | | |
1557 | | let context_offset: u32; |
1558 | 9.69M | let block_type = fast!((s.block_type_length_state.block_type_rb)[1]) as usize; |
1559 | 9.69M | context_offset = (block_type << kLiteralContextBits) as u32; |
1560 | 9.69M | s.context_map_slice_index = context_offset as usize; |
1561 | 9.69M | let trivial = fast!((s.trivial_literal_contexts)[block_type >> 5]); |
1562 | 9.69M | s.trivial_literal_context = ((trivial >> (block_type & 31)) & 1) as i32; |
1563 | | |
1564 | 9.69M | s.literal_htree_index = fast_slice!((s.context_map)[s.context_map_slice_index]); |
1565 | | // s.literal_htree = fast!((s.literal_hgroup.htrees)[s.literal_htree_index]); // redundant |
1566 | 9.69M | let context_mode_index = fast!((s.context_modes.slice())[block_type]) & 3; |
1567 | 9.69M | s.context_lookup = &kContextLookup[context_mode_index as usize]; |
1568 | 9.69M | } brotli_decompressor::decode::PrepareLiteralDecoding::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1552 | 1.33M | fn PrepareLiteralDecoding<AllocU8: alloc::Allocator<u8>, | 1553 | 1.33M | AllocU32: alloc::Allocator<u32>, | 1554 | 1.33M | AllocHC: alloc::Allocator<HuffmanCode>> | 1555 | 1.33M | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { | 1556 | | | 1557 | | let context_offset: u32; | 1558 | 1.33M | let block_type = fast!((s.block_type_length_state.block_type_rb)[1]) as usize; | 1559 | 1.33M | context_offset = (block_type << kLiteralContextBits) as u32; | 1560 | 1.33M | s.context_map_slice_index = context_offset as usize; | 1561 | 1.33M | let trivial = fast!((s.trivial_literal_contexts)[block_type >> 5]); | 1562 | 1.33M | s.trivial_literal_context = ((trivial >> (block_type & 31)) & 1) as i32; | 1563 | | | 1564 | 1.33M | s.literal_htree_index = fast_slice!((s.context_map)[s.context_map_slice_index]); | 1565 | | // s.literal_htree = fast!((s.literal_hgroup.htrees)[s.literal_htree_index]); // redundant | 1566 | 1.33M | let context_mode_index = fast!((s.context_modes.slice())[block_type]) & 3; | 1567 | 1.33M | s.context_lookup = &kContextLookup[context_mode_index as usize]; | 1568 | 1.33M | } |
Unexecuted instantiation: brotli_decompressor::decode::PrepareLiteralDecoding::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::PrepareLiteralDecoding::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::PrepareLiteralDecoding::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1552 | 8.20M | fn PrepareLiteralDecoding<AllocU8: alloc::Allocator<u8>, | 1553 | 8.20M | AllocU32: alloc::Allocator<u32>, | 1554 | 8.20M | AllocHC: alloc::Allocator<HuffmanCode>> | 1555 | 8.20M | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { | 1556 | | | 1557 | | let context_offset: u32; | 1558 | 8.20M | let block_type = fast!((s.block_type_length_state.block_type_rb)[1]) as usize; | 1559 | 8.20M | context_offset = (block_type << kLiteralContextBits) as u32; | 1560 | 8.20M | s.context_map_slice_index = context_offset as usize; | 1561 | 8.20M | let trivial = fast!((s.trivial_literal_contexts)[block_type >> 5]); | 1562 | 8.20M | s.trivial_literal_context = ((trivial >> (block_type & 31)) & 1) as i32; | 1563 | | | 1564 | 8.20M | s.literal_htree_index = fast_slice!((s.context_map)[s.context_map_slice_index]); | 1565 | | // s.literal_htree = fast!((s.literal_hgroup.htrees)[s.literal_htree_index]); // redundant | 1566 | 8.20M | let context_mode_index = fast!((s.context_modes.slice())[block_type]) & 3; | 1567 | 8.20M | s.context_lookup = &kContextLookup[context_mode_index as usize]; | 1568 | 8.20M | } |
brotli_decompressor::decode::PrepareLiteralDecoding::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1552 | 153k | fn PrepareLiteralDecoding<AllocU8: alloc::Allocator<u8>, | 1553 | 153k | AllocU32: alloc::Allocator<u32>, | 1554 | 153k | AllocHC: alloc::Allocator<HuffmanCode>> | 1555 | 153k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { | 1556 | | | 1557 | | let context_offset: u32; | 1558 | 153k | let block_type = fast!((s.block_type_length_state.block_type_rb)[1]) as usize; | 1559 | 153k | context_offset = (block_type << kLiteralContextBits) as u32; | 1560 | 153k | s.context_map_slice_index = context_offset as usize; | 1561 | 153k | let trivial = fast!((s.trivial_literal_contexts)[block_type >> 5]); | 1562 | 153k | s.trivial_literal_context = ((trivial >> (block_type & 31)) & 1) as i32; | 1563 | | | 1564 | 153k | s.literal_htree_index = fast_slice!((s.context_map)[s.context_map_slice_index]); | 1565 | | // s.literal_htree = fast!((s.literal_hgroup.htrees)[s.literal_htree_index]); // redundant | 1566 | 153k | let context_mode_index = fast!((s.context_modes.slice())[block_type]) & 3; | 1567 | 153k | s.context_lookup = &kContextLookup[context_mode_index as usize]; | 1568 | 153k | } |
|
1569 | | |
1570 | | // Decodes the block ty |
1571 | | // pe and updates the state for literal context. |
1572 | | // Reads 3..54 bits. |
1573 | 9.68M | fn DecodeLiteralBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, |
1574 | 9.68M | AllocU32: alloc::Allocator<u32>, |
1575 | 9.68M | AllocHC: alloc::Allocator<HuffmanCode>> |
1576 | 9.68M | (safe: bool, |
1577 | 9.68M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1578 | 9.68M | input: &[u8]) |
1579 | 9.68M | -> bool { |
1580 | | |
1581 | 9.68M | if !DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 0, input) { |
1582 | 29.5k | return false; |
1583 | 9.65M | } |
1584 | 9.65M | PrepareLiteralDecoding(s); |
1585 | 9.65M | true |
1586 | 9.68M | } brotli_decompressor::decode::DecodeLiteralBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1573 | 1.33M | fn DecodeLiteralBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, | 1574 | 1.33M | AllocU32: alloc::Allocator<u32>, | 1575 | 1.33M | AllocHC: alloc::Allocator<HuffmanCode>> | 1576 | 1.33M | (safe: bool, | 1577 | 1.33M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1578 | 1.33M | input: &[u8]) | 1579 | 1.33M | -> bool { | 1580 | | | 1581 | 1.33M | if !DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 0, input) { | 1582 | 21.1k | return false; | 1583 | 1.31M | } | 1584 | 1.31M | PrepareLiteralDecoding(s); | 1585 | 1.31M | true | 1586 | 1.33M | } |
Unexecuted instantiation: brotli_decompressor::decode::DecodeLiteralBlockSwitchInternal::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::DecodeLiteralBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::DecodeLiteralBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1573 | 8.20M | fn DecodeLiteralBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, | 1574 | 8.20M | AllocU32: alloc::Allocator<u32>, | 1575 | 8.20M | AllocHC: alloc::Allocator<HuffmanCode>> | 1576 | 8.20M | (safe: bool, | 1577 | 8.20M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1578 | 8.20M | input: &[u8]) | 1579 | 8.20M | -> bool { | 1580 | | | 1581 | 8.20M | if !DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 0, input) { | 1582 | 4.78k | return false; | 1583 | 8.19M | } | 1584 | 8.19M | PrepareLiteralDecoding(s); | 1585 | 8.19M | true | 1586 | 8.20M | } |
brotli_decompressor::decode::DecodeLiteralBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1573 | 148k | fn DecodeLiteralBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, | 1574 | 148k | AllocU32: alloc::Allocator<u32>, | 1575 | 148k | AllocHC: alloc::Allocator<HuffmanCode>> | 1576 | 148k | (safe: bool, | 1577 | 148k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1578 | 148k | input: &[u8]) | 1579 | 148k | -> bool { | 1580 | | | 1581 | 148k | if !DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 0, input) { | 1582 | 3.64k | return false; | 1583 | 145k | } | 1584 | 145k | PrepareLiteralDecoding(s); | 1585 | 145k | true | 1586 | 148k | } |
|
1587 | | // fn DecodeLiteralBlockSwitch< |
1588 | | // 'a, |
1589 | | // AllocU8 : alloc::Allocator<u8>, |
1590 | | // AllocU32 : alloc::Allocator<u32>, |
1591 | | // AllocHC : alloc::Allocator<HuffmanCode>> (safe : bool, |
1592 | | // mut s : &mut BrotliState<AllocU8, AllocU32, AllocHC>) { |
1593 | | // DecodeLiteralBlockSwitchInternal(false, s); |
1594 | | // } |
1595 | | // |
1596 | | // fn SafeDecodeLiteralBlockSwitch< |
1597 | | // 'a, |
1598 | | // AllocU8 : alloc::Allocator<u8>, |
1599 | | // AllocU32 : alloc::Allocator<u32>, |
1600 | | // AllocHC : alloc::Allocator<HuffmanCode>> (safe : bool, |
1601 | | // mut s : &mut BrotliState<AllocU8, AllocU32, AllocHC>) -> bool { |
1602 | | // return DecodeLiteralBlockSwitchInternal(true, s); |
1603 | | // } |
1604 | | // |
1605 | | // Block switch for insert/copy length. |
1606 | | // Reads 3..54 bits. |
1607 | 751k | fn DecodeCommandBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, |
1608 | 751k | AllocU32: alloc::Allocator<u32>, |
1609 | 751k | AllocHC: alloc::Allocator<HuffmanCode>> |
1610 | 751k | (safe: bool, |
1611 | 751k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1612 | 751k | input: &[u8]) |
1613 | 751k | -> bool { |
1614 | 751k | if (!DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 1, input)) { |
1615 | 664 | return false; |
1616 | 751k | } |
1617 | 751k | s.htree_command_index = fast!((s.block_type_length_state.block_type_rb)[3]) as u16; |
1618 | 751k | true |
1619 | 751k | } brotli_decompressor::decode::DecodeCommandBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1607 | 27.7k | fn DecodeCommandBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, | 1608 | 27.7k | AllocU32: alloc::Allocator<u32>, | 1609 | 27.7k | AllocHC: alloc::Allocator<HuffmanCode>> | 1610 | 27.7k | (safe: bool, | 1611 | 27.7k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1612 | 27.7k | input: &[u8]) | 1613 | 27.7k | -> bool { | 1614 | 27.7k | if (!DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 1, input)) { | 1615 | 342 | return false; | 1616 | 27.3k | } | 1617 | 27.3k | s.htree_command_index = fast!((s.block_type_length_state.block_type_rb)[3]) as u16; | 1618 | 27.3k | true | 1619 | 27.7k | } |
Unexecuted instantiation: brotli_decompressor::decode::DecodeCommandBlockSwitchInternal::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::DecodeCommandBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::DecodeCommandBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1607 | 723k | fn DecodeCommandBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, | 1608 | 723k | AllocU32: alloc::Allocator<u32>, | 1609 | 723k | AllocHC: alloc::Allocator<HuffmanCode>> | 1610 | 723k | (safe: bool, | 1611 | 723k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1612 | 723k | input: &[u8]) | 1613 | 723k | -> bool { | 1614 | 723k | if (!DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 1, input)) { | 1615 | 235 | return false; | 1616 | 723k | } | 1617 | 723k | s.htree_command_index = fast!((s.block_type_length_state.block_type_rb)[3]) as u16; | 1618 | 723k | true | 1619 | 723k | } |
brotli_decompressor::decode::DecodeCommandBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1607 | 833 | fn DecodeCommandBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, | 1608 | 833 | AllocU32: alloc::Allocator<u32>, | 1609 | 833 | AllocHC: alloc::Allocator<HuffmanCode>> | 1610 | 833 | (safe: bool, | 1611 | 833 | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1612 | 833 | input: &[u8]) | 1613 | 833 | -> bool { | 1614 | 833 | if (!DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 1, input)) { | 1615 | 87 | return false; | 1616 | 746 | } | 1617 | 746 | s.htree_command_index = fast!((s.block_type_length_state.block_type_rb)[3]) as u16; | 1618 | 746 | true | 1619 | 833 | } |
|
1620 | | |
1621 | | #[allow(dead_code)] |
1622 | 0 | fn DecodeCommandBlockSwitch<AllocU8: alloc::Allocator<u8>, |
1623 | 0 | AllocU32: alloc::Allocator<u32>, |
1624 | 0 | AllocHC: alloc::Allocator<HuffmanCode>> |
1625 | 0 | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1626 | 0 | input: &[u8]) { |
1627 | 0 | DecodeCommandBlockSwitchInternal(false, s, input); |
1628 | 0 | } |
1629 | | #[allow(dead_code)] |
1630 | 0 | fn SafeDecodeCommandBlockSwitch<AllocU8: alloc::Allocator<u8>, |
1631 | 0 | AllocU32: alloc::Allocator<u32>, |
1632 | 0 | AllocHC: alloc::Allocator<HuffmanCode>> |
1633 | 0 | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1634 | 0 | input: &[u8]) |
1635 | 0 | -> bool { |
1636 | 0 | DecodeCommandBlockSwitchInternal(true, s, input) |
1637 | 0 | } |
1638 | | |
1639 | | // Block switch for distance codes. |
1640 | | // Reads 3..54 bits. |
1641 | 457k | fn DecodeDistanceBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, |
1642 | 457k | AllocU32: alloc::Allocator<u32>, |
1643 | 457k | AllocHC: alloc::Allocator<HuffmanCode>> |
1644 | 457k | (safe: bool, |
1645 | 457k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1646 | 457k | input: &[u8]) |
1647 | 457k | -> bool { |
1648 | 457k | if (!DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 2, input)) { |
1649 | 42.2k | return false; |
1650 | 415k | } |
1651 | 415k | s.dist_context_map_slice_index = |
1652 | 415k | (fast!((s.block_type_length_state.block_type_rb)[5]) << kDistanceContextBits) as usize; |
1653 | 415k | s.dist_htree_index = fast_slice!((s.dist_context_map)[s.dist_context_map_slice_index |
1654 | 415k | + s.distance_context as usize]); |
1655 | 415k | true |
1656 | 457k | } brotli_decompressor::decode::DecodeDistanceBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1641 | 143k | fn DecodeDistanceBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, | 1642 | 143k | AllocU32: alloc::Allocator<u32>, | 1643 | 143k | AllocHC: alloc::Allocator<HuffmanCode>> | 1644 | 143k | (safe: bool, | 1645 | 143k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1646 | 143k | input: &[u8]) | 1647 | 143k | -> bool { | 1648 | 143k | if (!DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 2, input)) { | 1649 | 25.7k | return false; | 1650 | 117k | } | 1651 | 117k | s.dist_context_map_slice_index = | 1652 | 117k | (fast!((s.block_type_length_state.block_type_rb)[5]) << kDistanceContextBits) as usize; | 1653 | 117k | s.dist_htree_index = fast_slice!((s.dist_context_map)[s.dist_context_map_slice_index | 1654 | 117k | + s.distance_context as usize]); | 1655 | 117k | true | 1656 | 143k | } |
Unexecuted instantiation: brotli_decompressor::decode::DecodeDistanceBlockSwitchInternal::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::DecodeDistanceBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::DecodeDistanceBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1641 | 229k | fn DecodeDistanceBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, | 1642 | 229k | AllocU32: alloc::Allocator<u32>, | 1643 | 229k | AllocHC: alloc::Allocator<HuffmanCode>> | 1644 | 229k | (safe: bool, | 1645 | 229k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1646 | 229k | input: &[u8]) | 1647 | 229k | -> bool { | 1648 | 229k | if (!DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 2, input)) { | 1649 | 226 | return false; | 1650 | 229k | } | 1651 | 229k | s.dist_context_map_slice_index = | 1652 | 229k | (fast!((s.block_type_length_state.block_type_rb)[5]) << kDistanceContextBits) as usize; | 1653 | 229k | s.dist_htree_index = fast_slice!((s.dist_context_map)[s.dist_context_map_slice_index | 1654 | 229k | + s.distance_context as usize]); | 1655 | 229k | true | 1656 | 229k | } |
brotli_decompressor::decode::DecodeDistanceBlockSwitchInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1641 | 85.2k | fn DecodeDistanceBlockSwitchInternal<AllocU8: alloc::Allocator<u8>, | 1642 | 85.2k | AllocU32: alloc::Allocator<u32>, | 1643 | 85.2k | AllocHC: alloc::Allocator<HuffmanCode>> | 1644 | 85.2k | (safe: bool, | 1645 | 85.2k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1646 | 85.2k | input: &[u8]) | 1647 | 85.2k | -> bool { | 1648 | 85.2k | if (!DecodeBlockTypeAndLength(safe, &mut s.block_type_length_state, &mut s.br, 2, input)) { | 1649 | 16.1k | return false; | 1650 | 69.0k | } | 1651 | 69.0k | s.dist_context_map_slice_index = | 1652 | 69.0k | (fast!((s.block_type_length_state.block_type_rb)[5]) << kDistanceContextBits) as usize; | 1653 | 69.0k | s.dist_htree_index = fast_slice!((s.dist_context_map)[s.dist_context_map_slice_index | 1654 | 69.0k | + s.distance_context as usize]); | 1655 | 69.0k | true | 1656 | 85.2k | } |
|
1657 | | |
1658 | | #[allow(dead_code)] |
1659 | 0 | fn DecodeDistanceBlockSwitch<AllocU8: alloc::Allocator<u8>, |
1660 | 0 | AllocU32: alloc::Allocator<u32>, |
1661 | 0 | AllocHC: alloc::Allocator<HuffmanCode>> |
1662 | 0 | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1663 | 0 | input: &[u8]) { |
1664 | 0 | DecodeDistanceBlockSwitchInternal(false, s, input); |
1665 | 0 | } |
1666 | | |
1667 | | #[allow(dead_code)] |
1668 | 0 | fn SafeDecodeDistanceBlockSwitch<AllocU8: alloc::Allocator<u8>, |
1669 | 0 | AllocU32: alloc::Allocator<u32>, |
1670 | 0 | AllocHC: alloc::Allocator<HuffmanCode>> |
1671 | 0 | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1672 | 0 | input: &[u8]) |
1673 | 0 | -> bool { |
1674 | 0 | DecodeDistanceBlockSwitchInternal(true, s, input) |
1675 | 0 | } |
1676 | | |
1677 | 2.72M | fn UnwrittenBytes<AllocU8: alloc::Allocator<u8>, |
1678 | 2.72M | AllocU32: alloc::Allocator<u32>, |
1679 | 2.72M | AllocHC: alloc::Allocator<HuffmanCode>> ( |
1680 | 2.72M | s: &BrotliState<AllocU8, AllocU32, AllocHC>, |
1681 | 2.72M | wrap: bool, |
1682 | 2.72M | ) -> usize { |
1683 | 2.72M | let pos = if wrap && s.pos > s.ringbuffer_size { |
1684 | 132k | s.ringbuffer_size as usize |
1685 | | } else { |
1686 | 2.59M | s.pos as usize |
1687 | | }; |
1688 | 2.72M | let partial_pos_rb = (s.rb_roundtrips as usize * s.ringbuffer_size as usize) + pos as usize; |
1689 | 2.72M | (partial_pos_rb - s.partial_pos_out) as usize |
1690 | 2.72M | } brotli_decompressor::decode::UnwrittenBytes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1677 | 2.04M | fn UnwrittenBytes<AllocU8: alloc::Allocator<u8>, | 1678 | 2.04M | AllocU32: alloc::Allocator<u32>, | 1679 | 2.04M | AllocHC: alloc::Allocator<HuffmanCode>> ( | 1680 | 2.04M | s: &BrotliState<AllocU8, AllocU32, AllocHC>, | 1681 | 2.04M | wrap: bool, | 1682 | 2.04M | ) -> usize { | 1683 | 2.04M | let pos = if wrap && s.pos > s.ringbuffer_size { | 1684 | 129k | s.ringbuffer_size as usize | 1685 | | } else { | 1686 | 1.91M | s.pos as usize | 1687 | | }; | 1688 | 2.04M | let partial_pos_rb = (s.rb_roundtrips as usize * s.ringbuffer_size as usize) + pos as usize; | 1689 | 2.04M | (partial_pos_rb - s.partial_pos_out) as usize | 1690 | 2.04M | } |
Unexecuted instantiation: brotli_decompressor::decode::UnwrittenBytes::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::UnwrittenBytes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::UnwrittenBytes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1677 | 202k | fn UnwrittenBytes<AllocU8: alloc::Allocator<u8>, | 1678 | 202k | AllocU32: alloc::Allocator<u32>, | 1679 | 202k | AllocHC: alloc::Allocator<HuffmanCode>> ( | 1680 | 202k | s: &BrotliState<AllocU8, AllocU32, AllocHC>, | 1681 | 202k | wrap: bool, | 1682 | 202k | ) -> usize { | 1683 | 202k | let pos = if wrap && s.pos > s.ringbuffer_size { | 1684 | 0 | s.ringbuffer_size as usize | 1685 | | } else { | 1686 | 202k | s.pos as usize | 1687 | | }; | 1688 | 202k | let partial_pos_rb = (s.rb_roundtrips as usize * s.ringbuffer_size as usize) + pos as usize; | 1689 | 202k | (partial_pos_rb - s.partial_pos_out) as usize | 1690 | 202k | } |
brotli_decompressor::decode::UnwrittenBytes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1677 | 482k | fn UnwrittenBytes<AllocU8: alloc::Allocator<u8>, | 1678 | 482k | AllocU32: alloc::Allocator<u32>, | 1679 | 482k | AllocHC: alloc::Allocator<HuffmanCode>> ( | 1680 | 482k | s: &BrotliState<AllocU8, AllocU32, AllocHC>, | 1681 | 482k | wrap: bool, | 1682 | 482k | ) -> usize { | 1683 | 482k | let pos = if wrap && s.pos > s.ringbuffer_size { | 1684 | 2.66k | s.ringbuffer_size as usize | 1685 | | } else { | 1686 | 479k | s.pos as usize | 1687 | | }; | 1688 | 482k | let partial_pos_rb = (s.rb_roundtrips as usize * s.ringbuffer_size as usize) + pos as usize; | 1689 | 482k | (partial_pos_rb - s.partial_pos_out) as usize | 1690 | 482k | } |
|
1691 | 2.72M | fn WriteRingBuffer<'a, |
1692 | 2.72M | AllocU8: alloc::Allocator<u8>, |
1693 | 2.72M | AllocU32: alloc::Allocator<u32>, |
1694 | 2.72M | AllocHC: alloc::Allocator<HuffmanCode>>( |
1695 | 2.72M | available_out: &mut usize, |
1696 | 2.72M | opt_output: Option<&mut [u8]>, |
1697 | 2.72M | output_offset: &mut usize, |
1698 | 2.72M | total_out: &mut usize, |
1699 | 2.72M | force: bool, |
1700 | 2.72M | s: &'a mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1701 | 2.72M | ) -> (BrotliDecoderErrorCode, &'a [u8]) { |
1702 | 2.72M | let to_write = UnwrittenBytes(s, true); |
1703 | 2.72M | let mut num_written = *available_out as usize; |
1704 | 2.72M | if (num_written > to_write) { |
1705 | 602k | num_written = to_write; |
1706 | 2.12M | } |
1707 | 2.72M | if (s.meta_block_remaining_len < 0) { |
1708 | 4.84k | return (BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1, &[]); |
1709 | 2.72M | } |
1710 | 2.72M | let start_index = (s.partial_pos_out & s.ringbuffer_mask as usize) as usize; |
1711 | 2.72M | let start = fast_slice!((s.ringbuffer)[start_index ; start_index + num_written as usize]); |
1712 | 2.72M | if let Some(output) = opt_output { |
1713 | 2.72M | fast_mut!((output)[*output_offset ; *output_offset + num_written as usize]) |
1714 | 2.72M | .clone_from_slice(start); |
1715 | 2.72M | } |
1716 | 2.72M | *output_offset += num_written; |
1717 | 2.72M | *available_out -= num_written; |
1718 | | BROTLI_LOG_UINT!(to_write); |
1719 | | BROTLI_LOG_UINT!(num_written); |
1720 | 2.72M | s.partial_pos_out += num_written as usize; |
1721 | 2.72M | *total_out = s.partial_pos_out; |
1722 | 2.72M | if (num_written < to_write) { |
1723 | 2.05M | if s.ringbuffer_size == (1 << s.window_bits) || force { |
1724 | 2.05M | return (BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_OUTPUT, &[]); |
1725 | | } else { |
1726 | 0 | return (BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS, start); |
1727 | | } |
1728 | 661k | } |
1729 | 661k | if (s.ringbuffer_size == (1 << s.window_bits) && |
1730 | 609k | s.pos >= s.ringbuffer_size) { |
1731 | 352k | s.pos -= s.ringbuffer_size; |
1732 | 352k | s.rb_roundtrips += 1; |
1733 | 352k | s.should_wrap_ringbuffer = s.pos != 0; |
1734 | 352k | } |
1735 | 661k | (BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS, start) |
1736 | 2.72M | } brotli_decompressor::decode::WriteRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1691 | 2.04M | fn WriteRingBuffer<'a, | 1692 | 2.04M | AllocU8: alloc::Allocator<u8>, | 1693 | 2.04M | AllocU32: alloc::Allocator<u32>, | 1694 | 2.04M | AllocHC: alloc::Allocator<HuffmanCode>>( | 1695 | 2.04M | available_out: &mut usize, | 1696 | 2.04M | opt_output: Option<&mut [u8]>, | 1697 | 2.04M | output_offset: &mut usize, | 1698 | 2.04M | total_out: &mut usize, | 1699 | 2.04M | force: bool, | 1700 | 2.04M | s: &'a mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1701 | 2.04M | ) -> (BrotliDecoderErrorCode, &'a [u8]) { | 1702 | 2.04M | let to_write = UnwrittenBytes(s, true); | 1703 | 2.04M | let mut num_written = *available_out as usize; | 1704 | 2.04M | if (num_written > to_write) { | 1705 | 398k | num_written = to_write; | 1706 | 1.64M | } | 1707 | 2.04M | if (s.meta_block_remaining_len < 0) { | 1708 | 3.14k | return (BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1, &[]); | 1709 | 2.03M | } | 1710 | 2.03M | let start_index = (s.partial_pos_out & s.ringbuffer_mask as usize) as usize; | 1711 | 2.03M | let start = fast_slice!((s.ringbuffer)[start_index ; start_index + num_written as usize]); | 1712 | 2.03M | if let Some(output) = opt_output { | 1713 | 2.03M | fast_mut!((output)[*output_offset ; *output_offset + num_written as usize]) | 1714 | 2.03M | .clone_from_slice(start); | 1715 | 2.03M | } | 1716 | 2.03M | *output_offset += num_written; | 1717 | 2.03M | *available_out -= num_written; | 1718 | | BROTLI_LOG_UINT!(to_write); | 1719 | | BROTLI_LOG_UINT!(num_written); | 1720 | 2.03M | s.partial_pos_out += num_written as usize; | 1721 | 2.03M | *total_out = s.partial_pos_out; | 1722 | 2.03M | if (num_written < to_write) { | 1723 | 1.59M | if s.ringbuffer_size == (1 << s.window_bits) || force { | 1724 | 1.59M | return (BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_OUTPUT, &[]); | 1725 | | } else { | 1726 | 0 | return (BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS, start); | 1727 | | } | 1728 | 445k | } | 1729 | 445k | if (s.ringbuffer_size == (1 << s.window_bits) && | 1730 | 404k | s.pos >= s.ringbuffer_size) { | 1731 | 311k | s.pos -= s.ringbuffer_size; | 1732 | 311k | s.rb_roundtrips += 1; | 1733 | 311k | s.should_wrap_ringbuffer = s.pos != 0; | 1734 | 311k | } | 1735 | 445k | (BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS, start) | 1736 | 2.04M | } |
Unexecuted instantiation: brotli_decompressor::decode::WriteRingBuffer::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::WriteRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::WriteRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1691 | 202k | fn WriteRingBuffer<'a, | 1692 | 202k | AllocU8: alloc::Allocator<u8>, | 1693 | 202k | AllocU32: alloc::Allocator<u32>, | 1694 | 202k | AllocHC: alloc::Allocator<HuffmanCode>>( | 1695 | 202k | available_out: &mut usize, | 1696 | 202k | opt_output: Option<&mut [u8]>, | 1697 | 202k | output_offset: &mut usize, | 1698 | 202k | total_out: &mut usize, | 1699 | 202k | force: bool, | 1700 | 202k | s: &'a mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1701 | 202k | ) -> (BrotliDecoderErrorCode, &'a [u8]) { | 1702 | 202k | let to_write = UnwrittenBytes(s, true); | 1703 | 202k | let mut num_written = *available_out as usize; | 1704 | 202k | if (num_written > to_write) { | 1705 | 123k | num_written = to_write; | 1706 | 123k | } | 1707 | 202k | if (s.meta_block_remaining_len < 0) { | 1708 | 997 | return (BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1, &[]); | 1709 | 201k | } | 1710 | 201k | let start_index = (s.partial_pos_out & s.ringbuffer_mask as usize) as usize; | 1711 | 201k | let start = fast_slice!((s.ringbuffer)[start_index ; start_index + num_written as usize]); | 1712 | 201k | if let Some(output) = opt_output { | 1713 | 201k | fast_mut!((output)[*output_offset ; *output_offset + num_written as usize]) | 1714 | 201k | .clone_from_slice(start); | 1715 | 201k | } | 1716 | 201k | *output_offset += num_written; | 1717 | 201k | *available_out -= num_written; | 1718 | | BROTLI_LOG_UINT!(to_write); | 1719 | | BROTLI_LOG_UINT!(num_written); | 1720 | 201k | s.partial_pos_out += num_written as usize; | 1721 | 201k | *total_out = s.partial_pos_out; | 1722 | 201k | if (num_written < to_write) { | 1723 | 73.3k | if s.ringbuffer_size == (1 << s.window_bits) || force { | 1724 | 73.3k | return (BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_OUTPUT, &[]); | 1725 | | } else { | 1726 | 0 | return (BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS, start); | 1727 | | } | 1728 | 128k | } | 1729 | 128k | if (s.ringbuffer_size == (1 << s.window_bits) && | 1730 | 124k | s.pos >= s.ringbuffer_size) { | 1731 | 24.9k | s.pos -= s.ringbuffer_size; | 1732 | 24.9k | s.rb_roundtrips += 1; | 1733 | 24.9k | s.should_wrap_ringbuffer = s.pos != 0; | 1734 | 103k | } | 1735 | 128k | (BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS, start) | 1736 | 202k | } |
brotli_decompressor::decode::WriteRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1691 | 482k | fn WriteRingBuffer<'a, | 1692 | 482k | AllocU8: alloc::Allocator<u8>, | 1693 | 482k | AllocU32: alloc::Allocator<u32>, | 1694 | 482k | AllocHC: alloc::Allocator<HuffmanCode>>( | 1695 | 482k | available_out: &mut usize, | 1696 | 482k | opt_output: Option<&mut [u8]>, | 1697 | 482k | output_offset: &mut usize, | 1698 | 482k | total_out: &mut usize, | 1699 | 482k | force: bool, | 1700 | 482k | s: &'a mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1701 | 482k | ) -> (BrotliDecoderErrorCode, &'a [u8]) { | 1702 | 482k | let to_write = UnwrittenBytes(s, true); | 1703 | 482k | let mut num_written = *available_out as usize; | 1704 | 482k | if (num_written > to_write) { | 1705 | 80.8k | num_written = to_write; | 1706 | 401k | } | 1707 | 482k | if (s.meta_block_remaining_len < 0) { | 1708 | 701 | return (BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1, &[]); | 1709 | 481k | } | 1710 | 481k | let start_index = (s.partial_pos_out & s.ringbuffer_mask as usize) as usize; | 1711 | 481k | let start = fast_slice!((s.ringbuffer)[start_index ; start_index + num_written as usize]); | 1712 | 481k | if let Some(output) = opt_output { | 1713 | 481k | fast_mut!((output)[*output_offset ; *output_offset + num_written as usize]) | 1714 | 481k | .clone_from_slice(start); | 1715 | 481k | } | 1716 | 481k | *output_offset += num_written; | 1717 | 481k | *available_out -= num_written; | 1718 | | BROTLI_LOG_UINT!(to_write); | 1719 | | BROTLI_LOG_UINT!(num_written); | 1720 | 481k | s.partial_pos_out += num_written as usize; | 1721 | 481k | *total_out = s.partial_pos_out; | 1722 | 481k | if (num_written < to_write) { | 1723 | 393k | if s.ringbuffer_size == (1 << s.window_bits) || force { | 1724 | 393k | return (BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_OUTPUT, &[]); | 1725 | | } else { | 1726 | 0 | return (BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS, start); | 1727 | | } | 1728 | 87.6k | } | 1729 | 87.6k | if (s.ringbuffer_size == (1 << s.window_bits) && | 1730 | 80.2k | s.pos >= s.ringbuffer_size) { | 1731 | 16.8k | s.pos -= s.ringbuffer_size; | 1732 | 16.8k | s.rb_roundtrips += 1; | 1733 | 16.8k | s.should_wrap_ringbuffer = s.pos != 0; | 1734 | 70.7k | } | 1735 | 87.6k | (BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS, start) | 1736 | 482k | } |
|
1737 | | |
1738 | 332k | fn WrapRingBuffer<AllocU8: alloc::Allocator<u8>, |
1739 | 332k | AllocU32: alloc::Allocator<u32>, |
1740 | 332k | AllocHC: alloc::Allocator<HuffmanCode>>( |
1741 | 332k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1742 | 332k | ) { |
1743 | 332k | if s.should_wrap_ringbuffer { |
1744 | 101k | let (ring_buffer_start, ring_buffer_end) = s.ringbuffer.slice_mut().split_at_mut(s.ringbuffer_size as usize); |
1745 | 101k | let pos = s.pos as usize; |
1746 | 101k | ring_buffer_start.split_at_mut(pos).0.clone_from_slice(ring_buffer_end.split_at(pos).0); |
1747 | 101k | s.should_wrap_ringbuffer = false; |
1748 | 230k | } |
1749 | | |
1750 | 332k | } brotli_decompressor::decode::WrapRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1738 | 308k | fn WrapRingBuffer<AllocU8: alloc::Allocator<u8>, | 1739 | 308k | AllocU32: alloc::Allocator<u32>, | 1740 | 308k | AllocHC: alloc::Allocator<HuffmanCode>>( | 1741 | 308k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1742 | 308k | ) { | 1743 | 308k | if s.should_wrap_ringbuffer { | 1744 | 101k | let (ring_buffer_start, ring_buffer_end) = s.ringbuffer.slice_mut().split_at_mut(s.ringbuffer_size as usize); | 1745 | 101k | let pos = s.pos as usize; | 1746 | 101k | ring_buffer_start.split_at_mut(pos).0.clone_from_slice(ring_buffer_end.split_at(pos).0); | 1747 | 101k | s.should_wrap_ringbuffer = false; | 1748 | 207k | } | 1749 | | | 1750 | 308k | } |
Unexecuted instantiation: brotli_decompressor::decode::WrapRingBuffer::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::WrapRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::WrapRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1738 | 7.65k | fn WrapRingBuffer<AllocU8: alloc::Allocator<u8>, | 1739 | 7.65k | AllocU32: alloc::Allocator<u32>, | 1740 | 7.65k | AllocHC: alloc::Allocator<HuffmanCode>>( | 1741 | 7.65k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1742 | 7.65k | ) { | 1743 | 7.65k | if s.should_wrap_ringbuffer { | 1744 | 0 | let (ring_buffer_start, ring_buffer_end) = s.ringbuffer.slice_mut().split_at_mut(s.ringbuffer_size as usize); | 1745 | 0 | let pos = s.pos as usize; | 1746 | 0 | ring_buffer_start.split_at_mut(pos).0.clone_from_slice(ring_buffer_end.split_at(pos).0); | 1747 | 0 | s.should_wrap_ringbuffer = false; | 1748 | 7.65k | } | 1749 | | | 1750 | 7.65k | } |
brotli_decompressor::decode::WrapRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1738 | 16.4k | fn WrapRingBuffer<AllocU8: alloc::Allocator<u8>, | 1739 | 16.4k | AllocU32: alloc::Allocator<u32>, | 1740 | 16.4k | AllocHC: alloc::Allocator<HuffmanCode>>( | 1741 | 16.4k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1742 | 16.4k | ) { | 1743 | 16.4k | if s.should_wrap_ringbuffer { | 1744 | 525 | let (ring_buffer_start, ring_buffer_end) = s.ringbuffer.slice_mut().split_at_mut(s.ringbuffer_size as usize); | 1745 | 525 | let pos = s.pos as usize; | 1746 | 525 | ring_buffer_start.split_at_mut(pos).0.clone_from_slice(ring_buffer_end.split_at(pos).0); | 1747 | 525 | s.should_wrap_ringbuffer = false; | 1748 | 15.9k | } | 1749 | | | 1750 | 16.4k | } |
|
1751 | | |
1752 | 139k | fn CopyUncompressedBlockToOutput<AllocU8: alloc::Allocator<u8>, |
1753 | 139k | AllocU32: alloc::Allocator<u32>, |
1754 | 139k | AllocHC: alloc::Allocator<HuffmanCode>> |
1755 | 139k | (mut available_out: &mut usize, |
1756 | 139k | mut output: &mut [u8], |
1757 | 139k | mut output_offset: &mut usize, |
1758 | 139k | mut total_out: &mut usize, |
1759 | 139k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1760 | 139k | input: &[u8]) |
1761 | 139k | -> BrotliDecoderErrorCode { |
1762 | | // State machine |
1763 | | loop { |
1764 | 179k | match s.substate_uncompressed { |
1765 | | BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_NONE => { |
1766 | 153k | let mut nbytes = bit_reader::BrotliGetRemainingBytes(&s.br) as i32; |
1767 | 153k | if (nbytes > s.meta_block_remaining_len) { |
1768 | 4.19k | nbytes = s.meta_block_remaining_len; |
1769 | 149k | } |
1770 | 153k | if (s.pos + nbytes > s.ringbuffer_size) { |
1771 | 19.9k | nbytes = s.ringbuffer_size - s.pos; |
1772 | 133k | } |
1773 | | // Copy remaining bytes from s.br.buf_ to ringbuffer. |
1774 | 153k | bit_reader::BrotliCopyBytes(fast_mut!((s.ringbuffer.slice_mut())[s.pos as usize;]), |
1775 | 153k | &mut s.br, |
1776 | 153k | nbytes as u32, |
1777 | 153k | input); |
1778 | 153k | s.pos += nbytes; |
1779 | 153k | s.meta_block_remaining_len -= nbytes; |
1780 | 153k | if s.pos < (1 << s.window_bits) { |
1781 | 133k | if (s.meta_block_remaining_len == 0) { |
1782 | 3.29k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
1783 | 130k | } |
1784 | 130k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
1785 | 19.9k | } |
1786 | 19.9k | s.substate_uncompressed = BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_WRITE; |
1787 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; |
1788 | | // No break, continue to next state by going aroudn the loop |
1789 | | } |
1790 | | BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_WRITE => { |
1791 | 26.2k | let (result, _) = WriteRingBuffer(&mut available_out, |
1792 | 26.2k | Some(&mut output), |
1793 | 26.2k | &mut output_offset, |
1794 | 26.2k | &mut total_out, |
1795 | 26.2k | false, |
1796 | 26.2k | &mut s); |
1797 | 26.2k | match result { |
1798 | 19.9k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
1799 | 6.22k | _ => return result, |
1800 | | } |
1801 | 19.9k | if s.ringbuffer_size == 1 << s.window_bits { |
1802 | 19.9k | s.max_distance = s.max_backward_distance; |
1803 | 19.9k | } |
1804 | 19.9k | s.substate_uncompressed = BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_NONE; |
1805 | | } |
1806 | | } |
1807 | | } |
1808 | 139k | } brotli_decompressor::decode::CopyUncompressedBlockToOutput::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1752 | 100k | fn CopyUncompressedBlockToOutput<AllocU8: alloc::Allocator<u8>, | 1753 | 100k | AllocU32: alloc::Allocator<u32>, | 1754 | 100k | AllocHC: alloc::Allocator<HuffmanCode>> | 1755 | 100k | (mut available_out: &mut usize, | 1756 | 100k | mut output: &mut [u8], | 1757 | 100k | mut output_offset: &mut usize, | 1758 | 100k | mut total_out: &mut usize, | 1759 | 100k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1760 | 100k | input: &[u8]) | 1761 | 100k | -> BrotliDecoderErrorCode { | 1762 | | // State machine | 1763 | | loop { | 1764 | 104k | match s.substate_uncompressed { | 1765 | | BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_NONE => { | 1766 | 101k | let mut nbytes = bit_reader::BrotliGetRemainingBytes(&s.br) as i32; | 1767 | 101k | if (nbytes > s.meta_block_remaining_len) { | 1768 | 2.25k | nbytes = s.meta_block_remaining_len; | 1769 | 99.6k | } | 1770 | 101k | if (s.pos + nbytes > s.ringbuffer_size) { | 1771 | 2.25k | nbytes = s.ringbuffer_size - s.pos; | 1772 | 99.6k | } | 1773 | | // Copy remaining bytes from s.br.buf_ to ringbuffer. | 1774 | 101k | bit_reader::BrotliCopyBytes(fast_mut!((s.ringbuffer.slice_mut())[s.pos as usize;]), | 1775 | 101k | &mut s.br, | 1776 | 101k | nbytes as u32, | 1777 | 101k | input); | 1778 | 101k | s.pos += nbytes; | 1779 | 101k | s.meta_block_remaining_len -= nbytes; | 1780 | 101k | if s.pos < (1 << s.window_bits) { | 1781 | 99.6k | if (s.meta_block_remaining_len == 0) { | 1782 | 2.26k | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1783 | 97.3k | } | 1784 | 97.3k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1785 | 2.26k | } | 1786 | 2.26k | s.substate_uncompressed = BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_WRITE; | 1787 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; | 1788 | | // No break, continue to next state by going aroudn the loop | 1789 | | } | 1790 | | BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_WRITE => { | 1791 | 2.84k | let (result, _) = WriteRingBuffer(&mut available_out, | 1792 | 2.84k | Some(&mut output), | 1793 | 2.84k | &mut output_offset, | 1794 | 2.84k | &mut total_out, | 1795 | 2.84k | false, | 1796 | 2.84k | &mut s); | 1797 | 2.84k | match result { | 1798 | 2.26k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1799 | 580 | _ => return result, | 1800 | | } | 1801 | 2.26k | if s.ringbuffer_size == 1 << s.window_bits { | 1802 | 2.26k | s.max_distance = s.max_backward_distance; | 1803 | 2.26k | } | 1804 | 2.26k | s.substate_uncompressed = BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_NONE; | 1805 | | } | 1806 | | } | 1807 | | } | 1808 | 100k | } |
Unexecuted instantiation: brotli_decompressor::decode::CopyUncompressedBlockToOutput::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::CopyUncompressedBlockToOutput::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::CopyUncompressedBlockToOutput::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1752 | 12.2k | fn CopyUncompressedBlockToOutput<AllocU8: alloc::Allocator<u8>, | 1753 | 12.2k | AllocU32: alloc::Allocator<u32>, | 1754 | 12.2k | AllocHC: alloc::Allocator<HuffmanCode>> | 1755 | 12.2k | (mut available_out: &mut usize, | 1756 | 12.2k | mut output: &mut [u8], | 1757 | 12.2k | mut output_offset: &mut usize, | 1758 | 12.2k | mut total_out: &mut usize, | 1759 | 12.2k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1760 | 12.2k | input: &[u8]) | 1761 | 12.2k | -> BrotliDecoderErrorCode { | 1762 | | // State machine | 1763 | | loop { | 1764 | 46.8k | match s.substate_uncompressed { | 1765 | | BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_NONE => { | 1766 | 26.1k | let mut nbytes = bit_reader::BrotliGetRemainingBytes(&s.br) as i32; | 1767 | 26.1k | if (nbytes > s.meta_block_remaining_len) { | 1768 | 1.34k | nbytes = s.meta_block_remaining_len; | 1769 | 24.7k | } | 1770 | 26.1k | if (s.pos + nbytes > s.ringbuffer_size) { | 1771 | 17.2k | nbytes = s.ringbuffer_size - s.pos; | 1772 | 17.2k | } | 1773 | | // Copy remaining bytes from s.br.buf_ to ringbuffer. | 1774 | 26.1k | bit_reader::BrotliCopyBytes(fast_mut!((s.ringbuffer.slice_mut())[s.pos as usize;]), | 1775 | 26.1k | &mut s.br, | 1776 | 26.1k | nbytes as u32, | 1777 | 26.1k | input); | 1778 | 26.1k | s.pos += nbytes; | 1779 | 26.1k | s.meta_block_remaining_len -= nbytes; | 1780 | 26.1k | if s.pos < (1 << s.window_bits) { | 1781 | 8.85k | if (s.meta_block_remaining_len == 0) { | 1782 | 438 | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1783 | 8.41k | } | 1784 | 8.41k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1785 | 17.2k | } | 1786 | 17.2k | s.substate_uncompressed = BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_WRITE; | 1787 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; | 1788 | | // No break, continue to next state by going aroudn the loop | 1789 | | } | 1790 | | BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_WRITE => { | 1791 | 20.7k | let (result, _) = WriteRingBuffer(&mut available_out, | 1792 | 20.7k | Some(&mut output), | 1793 | 20.7k | &mut output_offset, | 1794 | 20.7k | &mut total_out, | 1795 | 20.7k | false, | 1796 | 20.7k | &mut s); | 1797 | 20.7k | match result { | 1798 | 17.2k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1799 | 3.42k | _ => return result, | 1800 | | } | 1801 | 17.2k | if s.ringbuffer_size == 1 << s.window_bits { | 1802 | 17.2k | s.max_distance = s.max_backward_distance; | 1803 | 17.2k | } | 1804 | 17.2k | s.substate_uncompressed = BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_NONE; | 1805 | | } | 1806 | | } | 1807 | | } | 1808 | 12.2k | } |
brotli_decompressor::decode::CopyUncompressedBlockToOutput::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1752 | 27.1k | fn CopyUncompressedBlockToOutput<AllocU8: alloc::Allocator<u8>, | 1753 | 27.1k | AllocU32: alloc::Allocator<u32>, | 1754 | 27.1k | AllocHC: alloc::Allocator<HuffmanCode>> | 1755 | 27.1k | (mut available_out: &mut usize, | 1756 | 27.1k | mut output: &mut [u8], | 1757 | 27.1k | mut output_offset: &mut usize, | 1758 | 27.1k | mut total_out: &mut usize, | 1759 | 27.1k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1760 | 27.1k | input: &[u8]) | 1761 | 27.1k | -> BrotliDecoderErrorCode { | 1762 | | // State machine | 1763 | | loop { | 1764 | 27.9k | match s.substate_uncompressed { | 1765 | | BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_NONE => { | 1766 | 25.3k | let mut nbytes = bit_reader::BrotliGetRemainingBytes(&s.br) as i32; | 1767 | 25.3k | if (nbytes > s.meta_block_remaining_len) { | 1768 | 597 | nbytes = s.meta_block_remaining_len; | 1769 | 24.7k | } | 1770 | 25.3k | if (s.pos + nbytes > s.ringbuffer_size) { | 1771 | 435 | nbytes = s.ringbuffer_size - s.pos; | 1772 | 24.8k | } | 1773 | | // Copy remaining bytes from s.br.buf_ to ringbuffer. | 1774 | 25.3k | bit_reader::BrotliCopyBytes(fast_mut!((s.ringbuffer.slice_mut())[s.pos as usize;]), | 1775 | 25.3k | &mut s.br, | 1776 | 25.3k | nbytes as u32, | 1777 | 25.3k | input); | 1778 | 25.3k | s.pos += nbytes; | 1779 | 25.3k | s.meta_block_remaining_len -= nbytes; | 1780 | 25.3k | if s.pos < (1 << s.window_bits) { | 1781 | 24.8k | if (s.meta_block_remaining_len == 0) { | 1782 | 598 | return BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 1783 | 24.3k | } | 1784 | 24.3k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1785 | 435 | } | 1786 | 435 | s.substate_uncompressed = BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_WRITE; | 1787 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; | 1788 | | // No break, continue to next state by going aroudn the loop | 1789 | | } | 1790 | | BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_WRITE => { | 1791 | 2.64k | let (result, _) = WriteRingBuffer(&mut available_out, | 1792 | 2.64k | Some(&mut output), | 1793 | 2.64k | &mut output_offset, | 1794 | 2.64k | &mut total_out, | 1795 | 2.64k | false, | 1796 | 2.64k | &mut s); | 1797 | 2.64k | match result { | 1798 | 435 | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 1799 | 2.21k | _ => return result, | 1800 | | } | 1801 | 435 | if s.ringbuffer_size == 1 << s.window_bits { | 1802 | 435 | s.max_distance = s.max_backward_distance; | 1803 | 435 | } | 1804 | 435 | s.substate_uncompressed = BrotliRunningUncompressedState::BROTLI_STATE_UNCOMPRESSED_NONE; | 1805 | | } | 1806 | | } | 1807 | | } | 1808 | 27.1k | } |
|
1809 | | |
1810 | 95.7k | fn BrotliAllocateRingBuffer<AllocU8: alloc::Allocator<u8>, |
1811 | 95.7k | AllocU32: alloc::Allocator<u32>, |
1812 | 95.7k | AllocHC: alloc::Allocator<HuffmanCode>> |
1813 | 95.7k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1814 | 95.7k | input: &[u8]) |
1815 | 95.7k | -> bool { |
1816 | | // We need the slack region for the following reasons: |
1817 | | // - doing up to two 16-byte copies for fast backward copying |
1818 | | // - inserting transformed dictionary word (5 prefix + 24 base + 8 suffix) |
1819 | | const kRingBufferWriteAheadSlack: i32 = 42; |
1820 | 95.7k | let mut is_last = s.is_last_metablock; |
1821 | 95.7k | s.ringbuffer_size = 1 << s.window_bits; |
1822 | | |
1823 | 95.7k | if (s.is_uncompressed != 0) { |
1824 | 5.45k | let next_block_header = |
1825 | 5.45k | bit_reader::BrotliPeekByte(&mut s.br, s.meta_block_remaining_len as u32, input); |
1826 | 5.45k | if (next_block_header != -1) && |
1827 | | // Peek succeeded |
1828 | 3.22k | ((next_block_header & 3) == 3) { |
1829 | 1.28k | // ISLAST and ISEMPTY |
1830 | 1.28k | is_last = 1; |
1831 | 4.17k | } |
1832 | 90.2k | } |
1833 | 95.7k | let max_dict_size = s.ringbuffer_size as usize - 16; |
1834 | | { |
1835 | 95.7k | let custom_dict = if s.custom_dict_size as usize > max_dict_size { |
1836 | 0 | let cd = fast_slice!((s.custom_dict)[(s.custom_dict_size as usize - max_dict_size); s.custom_dict_size as usize]); |
1837 | 0 | s.custom_dict_size = max_dict_size as isize; |
1838 | 0 | cd |
1839 | | } else { |
1840 | 95.7k | fast_slice!((s.custom_dict)[0; s.custom_dict_size as usize]) |
1841 | | }; |
1842 | | |
1843 | | // We need at least 2 bytes of ring buffer size to get the last two |
1844 | | // bytes for context from there |
1845 | 95.7k | if (is_last != 0) { |
1846 | 237k | while (s.ringbuffer_size as isize >= (s.custom_dict_size + s.meta_block_remaining_len as isize + 16) * 2 && s.ringbuffer_size as isize > 32) { |
1847 | 201k | s.ringbuffer_size >>= 1; |
1848 | 201k | } |
1849 | 59.8k | } |
1850 | 95.7k | if s.ringbuffer_size > (1 << s.window_bits) { |
1851 | 0 | s.ringbuffer_size = (1 << s.window_bits); |
1852 | 95.7k | } |
1853 | | |
1854 | 95.7k | s.ringbuffer_mask = s.ringbuffer_size - 1; |
1855 | 95.7k | s.ringbuffer = s.alloc_u8 |
1856 | 95.7k | .alloc_cell((s.ringbuffer_size as usize + kRingBufferWriteAheadSlack as usize + |
1857 | 95.7k | kBrotliMaxDictionaryWordLength as usize)); |
1858 | 95.7k | if (s.ringbuffer.slice().len() == 0) { |
1859 | 0 | return false; |
1860 | 95.7k | } |
1861 | 95.7k | fast_mut!((s.ringbuffer.slice_mut())[s.ringbuffer_size as usize - 1]) = 0; |
1862 | 95.7k | fast_mut!((s.ringbuffer.slice_mut())[s.ringbuffer_size as usize - 2]) = 0; |
1863 | 95.7k | if custom_dict.len() != 0 { |
1864 | 0 | let offset = ((-s.custom_dict_size) & s.ringbuffer_mask as isize) as usize; |
1865 | 0 | fast_mut!((s.ringbuffer.slice_mut())[offset ; offset + s.custom_dict_size as usize]).clone_from_slice(custom_dict); |
1866 | 95.7k | } |
1867 | | } |
1868 | 95.7k | if s.custom_dict.slice().len() != 0 { |
1869 | 0 | s.alloc_u8.free_cell(core::mem::replace(&mut s.custom_dict, |
1870 | 0 | AllocU8::AllocatedMemory::default())); |
1871 | 95.7k | } |
1872 | 95.7k | true |
1873 | 95.7k | } brotli_decompressor::decode::BrotliAllocateRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1810 | 52.3k | fn BrotliAllocateRingBuffer<AllocU8: alloc::Allocator<u8>, | 1811 | 52.3k | AllocU32: alloc::Allocator<u32>, | 1812 | 52.3k | AllocHC: alloc::Allocator<HuffmanCode>> | 1813 | 52.3k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1814 | 52.3k | input: &[u8]) | 1815 | 52.3k | -> bool { | 1816 | | // We need the slack region for the following reasons: | 1817 | | // - doing up to two 16-byte copies for fast backward copying | 1818 | | // - inserting transformed dictionary word (5 prefix + 24 base + 8 suffix) | 1819 | | const kRingBufferWriteAheadSlack: i32 = 42; | 1820 | 52.3k | let mut is_last = s.is_last_metablock; | 1821 | 52.3k | s.ringbuffer_size = 1 << s.window_bits; | 1822 | | | 1823 | 52.3k | if (s.is_uncompressed != 0) { | 1824 | 3.20k | let next_block_header = | 1825 | 3.20k | bit_reader::BrotliPeekByte(&mut s.br, s.meta_block_remaining_len as u32, input); | 1826 | 3.20k | if (next_block_header != -1) && | 1827 | | // Peek succeeded | 1828 | 2.24k | ((next_block_header & 3) == 3) { | 1829 | 473 | // ISLAST and ISEMPTY | 1830 | 473 | is_last = 1; | 1831 | 2.73k | } | 1832 | 49.1k | } | 1833 | 52.3k | let max_dict_size = s.ringbuffer_size as usize - 16; | 1834 | | { | 1835 | 52.3k | let custom_dict = if s.custom_dict_size as usize > max_dict_size { | 1836 | 0 | let cd = fast_slice!((s.custom_dict)[(s.custom_dict_size as usize - max_dict_size); s.custom_dict_size as usize]); | 1837 | 0 | s.custom_dict_size = max_dict_size as isize; | 1838 | 0 | cd | 1839 | | } else { | 1840 | 52.3k | fast_slice!((s.custom_dict)[0; s.custom_dict_size as usize]) | 1841 | | }; | 1842 | | | 1843 | | // We need at least 2 bytes of ring buffer size to get the last two | 1844 | | // bytes for context from there | 1845 | 52.3k | if (is_last != 0) { | 1846 | 192k | while (s.ringbuffer_size as isize >= (s.custom_dict_size + s.meta_block_remaining_len as isize + 16) * 2 && s.ringbuffer_size as isize > 32) { | 1847 | 165k | s.ringbuffer_size >>= 1; | 1848 | 165k | } | 1849 | 25.1k | } | 1850 | 52.3k | if s.ringbuffer_size > (1 << s.window_bits) { | 1851 | 0 | s.ringbuffer_size = (1 << s.window_bits); | 1852 | 52.3k | } | 1853 | | | 1854 | 52.3k | s.ringbuffer_mask = s.ringbuffer_size - 1; | 1855 | 52.3k | s.ringbuffer = s.alloc_u8 | 1856 | 52.3k | .alloc_cell((s.ringbuffer_size as usize + kRingBufferWriteAheadSlack as usize + | 1857 | 52.3k | kBrotliMaxDictionaryWordLength as usize)); | 1858 | 52.3k | if (s.ringbuffer.slice().len() == 0) { | 1859 | 0 | return false; | 1860 | 52.3k | } | 1861 | 52.3k | fast_mut!((s.ringbuffer.slice_mut())[s.ringbuffer_size as usize - 1]) = 0; | 1862 | 52.3k | fast_mut!((s.ringbuffer.slice_mut())[s.ringbuffer_size as usize - 2]) = 0; | 1863 | 52.3k | if custom_dict.len() != 0 { | 1864 | 0 | let offset = ((-s.custom_dict_size) & s.ringbuffer_mask as isize) as usize; | 1865 | 0 | fast_mut!((s.ringbuffer.slice_mut())[offset ; offset + s.custom_dict_size as usize]).clone_from_slice(custom_dict); | 1866 | 52.3k | } | 1867 | | } | 1868 | 52.3k | if s.custom_dict.slice().len() != 0 { | 1869 | 0 | s.alloc_u8.free_cell(core::mem::replace(&mut s.custom_dict, | 1870 | 0 | AllocU8::AllocatedMemory::default())); | 1871 | 52.3k | } | 1872 | 52.3k | true | 1873 | 52.3k | } |
Unexecuted instantiation: brotli_decompressor::decode::BrotliAllocateRingBuffer::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::BrotliAllocateRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::BrotliAllocateRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1810 | 23.8k | fn BrotliAllocateRingBuffer<AllocU8: alloc::Allocator<u8>, | 1811 | 23.8k | AllocU32: alloc::Allocator<u32>, | 1812 | 23.8k | AllocHC: alloc::Allocator<HuffmanCode>> | 1813 | 23.8k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1814 | 23.8k | input: &[u8]) | 1815 | 23.8k | -> bool { | 1816 | | // We need the slack region for the following reasons: | 1817 | | // - doing up to two 16-byte copies for fast backward copying | 1818 | | // - inserting transformed dictionary word (5 prefix + 24 base + 8 suffix) | 1819 | | const kRingBufferWriteAheadSlack: i32 = 42; | 1820 | 23.8k | let mut is_last = s.is_last_metablock; | 1821 | 23.8k | s.ringbuffer_size = 1 << s.window_bits; | 1822 | | | 1823 | 23.8k | if (s.is_uncompressed != 0) { | 1824 | 1.25k | let next_block_header = | 1825 | 1.25k | bit_reader::BrotliPeekByte(&mut s.br, s.meta_block_remaining_len as u32, input); | 1826 | 1.25k | if (next_block_header != -1) && | 1827 | | // Peek succeeded | 1828 | 402 | ((next_block_header & 3) == 3) { | 1829 | 369 | // ISLAST and ISEMPTY | 1830 | 369 | is_last = 1; | 1831 | 886 | } | 1832 | 22.5k | } | 1833 | 23.8k | let max_dict_size = s.ringbuffer_size as usize - 16; | 1834 | | { | 1835 | 23.8k | let custom_dict = if s.custom_dict_size as usize > max_dict_size { | 1836 | 0 | let cd = fast_slice!((s.custom_dict)[(s.custom_dict_size as usize - max_dict_size); s.custom_dict_size as usize]); | 1837 | 0 | s.custom_dict_size = max_dict_size as isize; | 1838 | 0 | cd | 1839 | | } else { | 1840 | 23.8k | fast_slice!((s.custom_dict)[0; s.custom_dict_size as usize]) | 1841 | | }; | 1842 | | | 1843 | | // We need at least 2 bytes of ring buffer size to get the last two | 1844 | | // bytes for context from there | 1845 | 23.8k | if (is_last != 0) { | 1846 | 15.5k | while (s.ringbuffer_size as isize >= (s.custom_dict_size + s.meta_block_remaining_len as isize + 16) * 2 && s.ringbuffer_size as isize > 32) { | 1847 | 10.7k | s.ringbuffer_size >>= 1; | 1848 | 10.7k | } | 1849 | 18.9k | } | 1850 | 23.8k | if s.ringbuffer_size > (1 << s.window_bits) { | 1851 | 0 | s.ringbuffer_size = (1 << s.window_bits); | 1852 | 23.8k | } | 1853 | | | 1854 | 23.8k | s.ringbuffer_mask = s.ringbuffer_size - 1; | 1855 | 23.8k | s.ringbuffer = s.alloc_u8 | 1856 | 23.8k | .alloc_cell((s.ringbuffer_size as usize + kRingBufferWriteAheadSlack as usize + | 1857 | 23.8k | kBrotliMaxDictionaryWordLength as usize)); | 1858 | 23.8k | if (s.ringbuffer.slice().len() == 0) { | 1859 | 0 | return false; | 1860 | 23.8k | } | 1861 | 23.8k | fast_mut!((s.ringbuffer.slice_mut())[s.ringbuffer_size as usize - 1]) = 0; | 1862 | 23.8k | fast_mut!((s.ringbuffer.slice_mut())[s.ringbuffer_size as usize - 2]) = 0; | 1863 | 23.8k | if custom_dict.len() != 0 { | 1864 | 0 | let offset = ((-s.custom_dict_size) & s.ringbuffer_mask as isize) as usize; | 1865 | 0 | fast_mut!((s.ringbuffer.slice_mut())[offset ; offset + s.custom_dict_size as usize]).clone_from_slice(custom_dict); | 1866 | 23.8k | } | 1867 | | } | 1868 | 23.8k | if s.custom_dict.slice().len() != 0 { | 1869 | 0 | s.alloc_u8.free_cell(core::mem::replace(&mut s.custom_dict, | 1870 | 0 | AllocU8::AllocatedMemory::default())); | 1871 | 23.8k | } | 1872 | 23.8k | true | 1873 | 23.8k | } |
brotli_decompressor::decode::BrotliAllocateRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1810 | 19.5k | fn BrotliAllocateRingBuffer<AllocU8: alloc::Allocator<u8>, | 1811 | 19.5k | AllocU32: alloc::Allocator<u32>, | 1812 | 19.5k | AllocHC: alloc::Allocator<HuffmanCode>> | 1813 | 19.5k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1814 | 19.5k | input: &[u8]) | 1815 | 19.5k | -> bool { | 1816 | | // We need the slack region for the following reasons: | 1817 | | // - doing up to two 16-byte copies for fast backward copying | 1818 | | // - inserting transformed dictionary word (5 prefix + 24 base + 8 suffix) | 1819 | | const kRingBufferWriteAheadSlack: i32 = 42; | 1820 | 19.5k | let mut is_last = s.is_last_metablock; | 1821 | 19.5k | s.ringbuffer_size = 1 << s.window_bits; | 1822 | | | 1823 | 19.5k | if (s.is_uncompressed != 0) { | 1824 | 998 | let next_block_header = | 1825 | 998 | bit_reader::BrotliPeekByte(&mut s.br, s.meta_block_remaining_len as u32, input); | 1826 | 998 | if (next_block_header != -1) && | 1827 | | // Peek succeeded | 1828 | 581 | ((next_block_header & 3) == 3) { | 1829 | 440 | // ISLAST and ISEMPTY | 1830 | 440 | is_last = 1; | 1831 | 558 | } | 1832 | 18.5k | } | 1833 | 19.5k | let max_dict_size = s.ringbuffer_size as usize - 16; | 1834 | | { | 1835 | 19.5k | let custom_dict = if s.custom_dict_size as usize > max_dict_size { | 1836 | 0 | let cd = fast_slice!((s.custom_dict)[(s.custom_dict_size as usize - max_dict_size); s.custom_dict_size as usize]); | 1837 | 0 | s.custom_dict_size = max_dict_size as isize; | 1838 | 0 | cd | 1839 | | } else { | 1840 | 19.5k | fast_slice!((s.custom_dict)[0; s.custom_dict_size as usize]) | 1841 | | }; | 1842 | | | 1843 | | // We need at least 2 bytes of ring buffer size to get the last two | 1844 | | // bytes for context from there | 1845 | 19.5k | if (is_last != 0) { | 1846 | 29.5k | while (s.ringbuffer_size as isize >= (s.custom_dict_size + s.meta_block_remaining_len as isize + 16) * 2 && s.ringbuffer_size as isize > 32) { | 1847 | 25.7k | s.ringbuffer_size >>= 1; | 1848 | 25.7k | } | 1849 | 15.7k | } | 1850 | 19.5k | if s.ringbuffer_size > (1 << s.window_bits) { | 1851 | 0 | s.ringbuffer_size = (1 << s.window_bits); | 1852 | 19.5k | } | 1853 | | | 1854 | 19.5k | s.ringbuffer_mask = s.ringbuffer_size - 1; | 1855 | 19.5k | s.ringbuffer = s.alloc_u8 | 1856 | 19.5k | .alloc_cell((s.ringbuffer_size as usize + kRingBufferWriteAheadSlack as usize + | 1857 | 19.5k | kBrotliMaxDictionaryWordLength as usize)); | 1858 | 19.5k | if (s.ringbuffer.slice().len() == 0) { | 1859 | 0 | return false; | 1860 | 19.5k | } | 1861 | 19.5k | fast_mut!((s.ringbuffer.slice_mut())[s.ringbuffer_size as usize - 1]) = 0; | 1862 | 19.5k | fast_mut!((s.ringbuffer.slice_mut())[s.ringbuffer_size as usize - 2]) = 0; | 1863 | 19.5k | if custom_dict.len() != 0 { | 1864 | 0 | let offset = ((-s.custom_dict_size) & s.ringbuffer_mask as isize) as usize; | 1865 | 0 | fast_mut!((s.ringbuffer.slice_mut())[offset ; offset + s.custom_dict_size as usize]).clone_from_slice(custom_dict); | 1866 | 19.5k | } | 1867 | | } | 1868 | 19.5k | if s.custom_dict.slice().len() != 0 { | 1869 | 0 | s.alloc_u8.free_cell(core::mem::replace(&mut s.custom_dict, | 1870 | 0 | AllocU8::AllocatedMemory::default())); | 1871 | 19.5k | } | 1872 | 19.5k | true | 1873 | 19.5k | } |
|
1874 | | |
1875 | | // Reads 1..256 2-bit context modes. |
1876 | 91.9k | pub fn ReadContextModes<AllocU8: alloc::Allocator<u8>, |
1877 | 91.9k | AllocU32: alloc::Allocator<u32>, |
1878 | 91.9k | AllocHC: alloc::Allocator<HuffmanCode>> |
1879 | 91.9k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1880 | 91.9k | input: &[u8]) |
1881 | 91.9k | -> BrotliDecoderErrorCode { |
1882 | | |
1883 | 91.9k | let mut i: i32 = s.loop_counter; |
1884 | | |
1885 | 453k | for context_mode_iter in fast_mut!((s.context_modes.slice_mut())[i as usize ; |
1886 | 91.9k | (s.block_type_length_state.num_block_types[0] |
1887 | 91.9k | as usize)]) |
1888 | 91.9k | .iter_mut() { |
1889 | 453k | let mut bits: u32 = 0; |
1890 | 453k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input)) { |
1891 | 6.72k | mark_unlikely(); |
1892 | 6.72k | s.loop_counter = i; |
1893 | 6.72k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
1894 | 446k | } |
1895 | 446k | *context_mode_iter = bits as u8; |
1896 | | BROTLI_LOG_UINT!(i); |
1897 | 446k | i += 1; |
1898 | | } |
1899 | 85.2k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS |
1900 | 91.9k | } brotli_decompressor::decode::ReadContextModes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1876 | 53.7k | pub fn ReadContextModes<AllocU8: alloc::Allocator<u8>, | 1877 | 53.7k | AllocU32: alloc::Allocator<u32>, | 1878 | 53.7k | AllocHC: alloc::Allocator<HuffmanCode>> | 1879 | 53.7k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1880 | 53.7k | input: &[u8]) | 1881 | 53.7k | -> BrotliDecoderErrorCode { | 1882 | | | 1883 | 53.7k | let mut i: i32 = s.loop_counter; | 1884 | | | 1885 | 140k | for context_mode_iter in fast_mut!((s.context_modes.slice_mut())[i as usize ; | 1886 | 53.7k | (s.block_type_length_state.num_block_types[0] | 1887 | 53.7k | as usize)]) | 1888 | 53.7k | .iter_mut() { | 1889 | 140k | let mut bits: u32 = 0; | 1890 | 140k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input)) { | 1891 | 4.56k | mark_unlikely(); | 1892 | 4.56k | s.loop_counter = i; | 1893 | 4.56k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1894 | 135k | } | 1895 | 135k | *context_mode_iter = bits as u8; | 1896 | | BROTLI_LOG_UINT!(i); | 1897 | 135k | i += 1; | 1898 | | } | 1899 | 49.2k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 1900 | 53.7k | } |
Unexecuted instantiation: brotli_decompressor::decode::ReadContextModes::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::ReadContextModes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::ReadContextModes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1876 | 18.6k | pub fn ReadContextModes<AllocU8: alloc::Allocator<u8>, | 1877 | 18.6k | AllocU32: alloc::Allocator<u32>, | 1878 | 18.6k | AllocHC: alloc::Allocator<HuffmanCode>> | 1879 | 18.6k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1880 | 18.6k | input: &[u8]) | 1881 | 18.6k | -> BrotliDecoderErrorCode { | 1882 | | | 1883 | 18.6k | let mut i: i32 = s.loop_counter; | 1884 | | | 1885 | 272k | for context_mode_iter in fast_mut!((s.context_modes.slice_mut())[i as usize ; | 1886 | 18.6k | (s.block_type_length_state.num_block_types[0] | 1887 | 18.6k | as usize)]) | 1888 | 18.6k | .iter_mut() { | 1889 | 272k | let mut bits: u32 = 0; | 1890 | 272k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input)) { | 1891 | 1.81k | mark_unlikely(); | 1892 | 1.81k | s.loop_counter = i; | 1893 | 1.81k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1894 | 270k | } | 1895 | 270k | *context_mode_iter = bits as u8; | 1896 | | BROTLI_LOG_UINT!(i); | 1897 | 270k | i += 1; | 1898 | | } | 1899 | 16.8k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 1900 | 18.6k | } |
brotli_decompressor::decode::ReadContextModes::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1876 | 19.5k | pub fn ReadContextModes<AllocU8: alloc::Allocator<u8>, | 1877 | 19.5k | AllocU32: alloc::Allocator<u32>, | 1878 | 19.5k | AllocHC: alloc::Allocator<HuffmanCode>> | 1879 | 19.5k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1880 | 19.5k | input: &[u8]) | 1881 | 19.5k | -> BrotliDecoderErrorCode { | 1882 | | | 1883 | 19.5k | let mut i: i32 = s.loop_counter; | 1884 | | | 1885 | 40.9k | for context_mode_iter in fast_mut!((s.context_modes.slice_mut())[i as usize ; | 1886 | 19.5k | (s.block_type_length_state.num_block_types[0] | 1887 | 19.5k | as usize)]) | 1888 | 19.5k | .iter_mut() { | 1889 | 40.9k | let mut bits: u32 = 0; | 1890 | 40.9k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 2, &mut bits, input)) { | 1891 | 343 | mark_unlikely(); | 1892 | 343 | s.loop_counter = i; | 1893 | 343 | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 1894 | 40.6k | } | 1895 | 40.6k | *context_mode_iter = bits as u8; | 1896 | | BROTLI_LOG_UINT!(i); | 1897 | 40.6k | i += 1; | 1898 | | } | 1899 | 19.1k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | 1900 | 19.5k | } |
|
1901 | | |
1902 | 144M | pub fn TakeDistanceFromRingBuffer<AllocU8: alloc::Allocator<u8>, |
1903 | 144M | AllocU32: alloc::Allocator<u32>, |
1904 | 144M | AllocHC: alloc::Allocator<HuffmanCode>> |
1905 | 144M | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { |
1906 | 144M | if (s.distance_code == 0) { |
1907 | 2.25M | s.dist_rb_idx -= 1; |
1908 | 2.25M | s.distance_code = fast!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]); |
1909 | 2.25M | s.distance_context = 1; |
1910 | 2.25M | } else { |
1911 | 142M | let distance_code = s.distance_code << 1; |
1912 | | // kDistanceShortCodeIndexOffset has 2-bit values from LSB: |
1913 | | // 3, 2, 1, 0, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 |
1914 | | const kDistanceShortCodeIndexOffset: u32 = 0xaaafff1b; |
1915 | | // kDistanceShortCodeValueOffset has 2-bit values from LSB: |
1916 | | // -0, 0,-0, 0,-1, 1,-2, 2,-3, 3,-1, 1,-2, 2,-3, 3 |
1917 | | const kDistanceShortCodeValueOffset: u32 = 0xfa5fa500; |
1918 | 142M | let mut v = (s.dist_rb_idx as i32 + |
1919 | 142M | (kDistanceShortCodeIndexOffset as i32 >> |
1920 | 142M | distance_code as i32)) as i32 & 0x3; |
1921 | 142M | s.distance_code = fast!((s.dist_rb)[v as usize]); |
1922 | 142M | v = (kDistanceShortCodeValueOffset >> distance_code) as i32 & 0x3; |
1923 | 142M | if ((distance_code & 0x3) != 0) { |
1924 | 107M | s.distance_code += v; |
1925 | 107M | } else { |
1926 | 35.6M | s.distance_code -= v; |
1927 | 35.6M | if (s.distance_code <= 0) { |
1928 | 4.89k | // A huge distance will cause a BROTLI_FAILURE() soon. |
1929 | 4.89k | // This is a little faster than failing here. |
1930 | 4.89k | s.distance_code = 0x7fffffff; |
1931 | 35.6M | } |
1932 | | } |
1933 | | } |
1934 | 144M | } brotli_decompressor::decode::TakeDistanceFromRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1902 | 103M | pub fn TakeDistanceFromRingBuffer<AllocU8: alloc::Allocator<u8>, | 1903 | 103M | AllocU32: alloc::Allocator<u32>, | 1904 | 103M | AllocHC: alloc::Allocator<HuffmanCode>> | 1905 | 103M | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { | 1906 | 103M | if (s.distance_code == 0) { | 1907 | 418k | s.dist_rb_idx -= 1; | 1908 | 418k | s.distance_code = fast!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]); | 1909 | 418k | s.distance_context = 1; | 1910 | 418k | } else { | 1911 | 102M | let distance_code = s.distance_code << 1; | 1912 | | // kDistanceShortCodeIndexOffset has 2-bit values from LSB: | 1913 | | // 3, 2, 1, 0, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 | 1914 | | const kDistanceShortCodeIndexOffset: u32 = 0xaaafff1b; | 1915 | | // kDistanceShortCodeValueOffset has 2-bit values from LSB: | 1916 | | // -0, 0,-0, 0,-1, 1,-2, 2,-3, 3,-1, 1,-2, 2,-3, 3 | 1917 | | const kDistanceShortCodeValueOffset: u32 = 0xfa5fa500; | 1918 | 102M | let mut v = (s.dist_rb_idx as i32 + | 1919 | 102M | (kDistanceShortCodeIndexOffset as i32 >> | 1920 | 102M | distance_code as i32)) as i32 & 0x3; | 1921 | 102M | s.distance_code = fast!((s.dist_rb)[v as usize]); | 1922 | 102M | v = (kDistanceShortCodeValueOffset >> distance_code) as i32 & 0x3; | 1923 | 102M | if ((distance_code & 0x3) != 0) { | 1924 | 69.4M | s.distance_code += v; | 1925 | 69.4M | } else { | 1926 | 33.1M | s.distance_code -= v; | 1927 | 33.1M | if (s.distance_code <= 0) { | 1928 | 4.09k | // A huge distance will cause a BROTLI_FAILURE() soon. | 1929 | 4.09k | // This is a little faster than failing here. | 1930 | 4.09k | s.distance_code = 0x7fffffff; | 1931 | 33.1M | } | 1932 | | } | 1933 | | } | 1934 | 103M | } |
Unexecuted instantiation: brotli_decompressor::decode::TakeDistanceFromRingBuffer::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::TakeDistanceFromRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::TakeDistanceFromRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1902 | 2.59M | pub fn TakeDistanceFromRingBuffer<AllocU8: alloc::Allocator<u8>, | 1903 | 2.59M | AllocU32: alloc::Allocator<u32>, | 1904 | 2.59M | AllocHC: alloc::Allocator<HuffmanCode>> | 1905 | 2.59M | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { | 1906 | 2.59M | if (s.distance_code == 0) { | 1907 | 20.7k | s.dist_rb_idx -= 1; | 1908 | 20.7k | s.distance_code = fast!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]); | 1909 | 20.7k | s.distance_context = 1; | 1910 | 20.7k | } else { | 1911 | 2.57M | let distance_code = s.distance_code << 1; | 1912 | | // kDistanceShortCodeIndexOffset has 2-bit values from LSB: | 1913 | | // 3, 2, 1, 0, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 | 1914 | | const kDistanceShortCodeIndexOffset: u32 = 0xaaafff1b; | 1915 | | // kDistanceShortCodeValueOffset has 2-bit values from LSB: | 1916 | | // -0, 0,-0, 0,-1, 1,-2, 2,-3, 3,-1, 1,-2, 2,-3, 3 | 1917 | | const kDistanceShortCodeValueOffset: u32 = 0xfa5fa500; | 1918 | 2.57M | let mut v = (s.dist_rb_idx as i32 + | 1919 | 2.57M | (kDistanceShortCodeIndexOffset as i32 >> | 1920 | 2.57M | distance_code as i32)) as i32 & 0x3; | 1921 | 2.57M | s.distance_code = fast!((s.dist_rb)[v as usize]); | 1922 | 2.57M | v = (kDistanceShortCodeValueOffset >> distance_code) as i32 & 0x3; | 1923 | 2.57M | if ((distance_code & 0x3) != 0) { | 1924 | 1.98M | s.distance_code += v; | 1925 | 1.98M | } else { | 1926 | 586k | s.distance_code -= v; | 1927 | 586k | if (s.distance_code <= 0) { | 1928 | 233 | // A huge distance will cause a BROTLI_FAILURE() soon. | 1929 | 233 | // This is a little faster than failing here. | 1930 | 233 | s.distance_code = 0x7fffffff; | 1931 | 586k | } | 1932 | | } | 1933 | | } | 1934 | 2.59M | } |
brotli_decompressor::decode::TakeDistanceFromRingBuffer::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1902 | 39.2M | pub fn TakeDistanceFromRingBuffer<AllocU8: alloc::Allocator<u8>, | 1903 | 39.2M | AllocU32: alloc::Allocator<u32>, | 1904 | 39.2M | AllocHC: alloc::Allocator<HuffmanCode>> | 1905 | 39.2M | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) { | 1906 | 39.2M | if (s.distance_code == 0) { | 1907 | 1.81M | s.dist_rb_idx -= 1; | 1908 | 1.81M | s.distance_code = fast!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]); | 1909 | 1.81M | s.distance_context = 1; | 1910 | 1.81M | } else { | 1911 | 37.4M | let distance_code = s.distance_code << 1; | 1912 | | // kDistanceShortCodeIndexOffset has 2-bit values from LSB: | 1913 | | // 3, 2, 1, 0, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 | 1914 | | const kDistanceShortCodeIndexOffset: u32 = 0xaaafff1b; | 1915 | | // kDistanceShortCodeValueOffset has 2-bit values from LSB: | 1916 | | // -0, 0,-0, 0,-1, 1,-2, 2,-3, 3,-1, 1,-2, 2,-3, 3 | 1917 | | const kDistanceShortCodeValueOffset: u32 = 0xfa5fa500; | 1918 | 37.4M | let mut v = (s.dist_rb_idx as i32 + | 1919 | 37.4M | (kDistanceShortCodeIndexOffset as i32 >> | 1920 | 37.4M | distance_code as i32)) as i32 & 0x3; | 1921 | 37.4M | s.distance_code = fast!((s.dist_rb)[v as usize]); | 1922 | 37.4M | v = (kDistanceShortCodeValueOffset >> distance_code) as i32 & 0x3; | 1923 | 37.4M | if ((distance_code & 0x3) != 0) { | 1924 | 35.5M | s.distance_code += v; | 1925 | 35.5M | } else { | 1926 | 1.84M | s.distance_code -= v; | 1927 | 1.84M | if (s.distance_code <= 0) { | 1928 | 572 | // A huge distance will cause a BROTLI_FAILURE() soon. | 1929 | 572 | // This is a little faster than failing here. | 1930 | 572 | s.distance_code = 0x7fffffff; | 1931 | 1.83M | } | 1932 | | } | 1933 | | } | 1934 | 39.2M | } |
|
1935 | | |
1936 | 330M | pub fn SafeReadBits(br: &mut bit_reader::BrotliBitReader, |
1937 | 330M | n_bits: u32, |
1938 | 330M | val: &mut u32, |
1939 | 330M | input: &[u8]) |
1940 | 330M | -> bool { |
1941 | 330M | if (n_bits != 0) { |
1942 | 924k | bit_reader::BrotliSafeReadBits(br, n_bits, val, input) |
1943 | | } else { |
1944 | 329M | *val = 0; |
1945 | 329M | true |
1946 | | } |
1947 | 330M | } |
1948 | | |
1949 | | // Precondition: s.distance_code < 0 |
1950 | 158M | pub fn ReadDistanceInternal<AllocU8: alloc::Allocator<u8>, |
1951 | 158M | AllocU32: alloc::Allocator<u32>, |
1952 | 158M | AllocHC: alloc::Allocator<HuffmanCode>> |
1953 | 158M | (safe: bool, |
1954 | 158M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
1955 | 158M | input: &[u8], |
1956 | 158M | distance_hgroup: &[&[HuffmanCode]; 256]) |
1957 | 158M | -> bool { |
1958 | | let mut distval: i32; |
1959 | 158M | let mut memento = bit_reader::BrotliBitReaderState::default(); |
1960 | 158M | if (!safe) { |
1961 | 36.0M | s.distance_code = ReadSymbol(fast!((distance_hgroup)[s.dist_htree_index as usize]), |
1962 | 36.0M | &mut s.br, |
1963 | 36.0M | input) as i32; |
1964 | 36.0M | } else { |
1965 | 122M | let mut code: u32 = 0; |
1966 | 122M | memento = bit_reader::BrotliBitReaderSaveState(&s.br); |
1967 | 122M | if !SafeReadSymbol(fast!((distance_hgroup)[s.dist_htree_index as usize]), |
1968 | 122M | &mut s.br, |
1969 | 122M | &mut code, |
1970 | 122M | input) { |
1971 | 23.0k | return false; |
1972 | 122M | } |
1973 | 122M | s.distance_code = code as i32; |
1974 | | } |
1975 | | // Convert the distance code to the actual distance by possibly |
1976 | | // looking up past distances from the s.ringbuffer. |
1977 | 158M | s.distance_context = 0; |
1978 | 158M | if ((s.distance_code as u64 & 0xfffffffffffffff0) == 0) { |
1979 | 144M | TakeDistanceFromRingBuffer(s); |
1980 | 144M | fast_mut!((s.block_type_length_state.block_length)[2]) -= 1; |
1981 | 144M | return true; |
1982 | 13.3M | } |
1983 | 13.3M | distval = s.distance_code - s.num_direct_distance_codes as i32; |
1984 | 13.3M | if (distval >= 0) { |
1985 | | let nbits: u32; |
1986 | | let postfix: i32; |
1987 | | let offset: i32; |
1988 | 2.77M | if (!safe && (s.distance_postfix_bits == 0)) { |
1989 | 371k | nbits = (distval as u32 >> 1) + 1; |
1990 | 371k | offset = ((2 + (distval & 1)) << nbits) - 4; |
1991 | 371k | s.distance_code = (s.num_direct_distance_codes as i64 + offset as i64 + |
1992 | 371k | bit_reader::BrotliReadBits(&mut s.br, nbits, input) as i64) as i32; |
1993 | 371k | } else { |
1994 | | // This branch also works well when s.distance_postfix_bits == 0 |
1995 | 2.40M | let mut bits: u32 = 0; |
1996 | 2.40M | postfix = distval & s.distance_postfix_mask; |
1997 | 2.40M | distval >>= s.distance_postfix_bits; |
1998 | 2.40M | nbits = (distval as u32 >> 1) + 1; |
1999 | 2.40M | if (safe) { |
2000 | 237k | if (!SafeReadBits(&mut s.br, nbits, &mut bits, input)) { |
2001 | 58.2k | s.distance_code = -1; /* Restore precondition. */ |
2002 | 58.2k | bit_reader::BrotliBitReaderRestoreState(&mut s.br, &memento); |
2003 | 58.2k | return false; |
2004 | 178k | } |
2005 | 2.16M | } else { |
2006 | 2.16M | bits = bit_reader::BrotliReadBits(&mut s.br, nbits, input); |
2007 | 2.16M | } |
2008 | 2.34M | offset = (((distval & 1).wrapping_add(2)) << nbits).wrapping_sub(4); |
2009 | 2.34M | s.distance_code = ((i64::from(offset) + i64::from(bits)) << s.distance_postfix_bits).wrapping_add(i64::from(postfix)).wrapping_add(i64::from(s.num_direct_distance_codes)) as i32; |
2010 | | } |
2011 | 10.5M | } |
2012 | 13.2M | s.distance_code = s.distance_code.wrapping_sub(NUM_DISTANCE_SHORT_CODES as i32).wrapping_add(1); |
2013 | 13.2M | fast_mut!((s.block_type_length_state.block_length)[2]) -= 1; |
2014 | 13.2M | true |
2015 | 158M | } brotli_decompressor::decode::ReadDistanceInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1950 | 111M | pub fn ReadDistanceInternal<AllocU8: alloc::Allocator<u8>, | 1951 | 111M | AllocU32: alloc::Allocator<u32>, | 1952 | 111M | AllocHC: alloc::Allocator<HuffmanCode>> | 1953 | 111M | (safe: bool, | 1954 | 111M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1955 | 111M | input: &[u8], | 1956 | 111M | distance_hgroup: &[&[HuffmanCode]; 256]) | 1957 | 111M | -> bool { | 1958 | | let mut distval: i32; | 1959 | 111M | let mut memento = bit_reader::BrotliBitReaderState::default(); | 1960 | 111M | if (!safe) { | 1961 | 14.3M | s.distance_code = ReadSymbol(fast!((distance_hgroup)[s.dist_htree_index as usize]), | 1962 | 14.3M | &mut s.br, | 1963 | 14.3M | input) as i32; | 1964 | 14.3M | } else { | 1965 | 96.9M | let mut code: u32 = 0; | 1966 | 96.9M | memento = bit_reader::BrotliBitReaderSaveState(&s.br); | 1967 | 96.9M | if !SafeReadSymbol(fast!((distance_hgroup)[s.dist_htree_index as usize]), | 1968 | 96.9M | &mut s.br, | 1969 | 96.9M | &mut code, | 1970 | 96.9M | input) { | 1971 | 15.5k | return false; | 1972 | 96.9M | } | 1973 | 96.9M | s.distance_code = code as i32; | 1974 | | } | 1975 | | // Convert the distance code to the actual distance by possibly | 1976 | | // looking up past distances from the s.ringbuffer. | 1977 | 111M | s.distance_context = 0; | 1978 | 111M | if ((s.distance_code as u64 & 0xfffffffffffffff0) == 0) { | 1979 | 103M | TakeDistanceFromRingBuffer(s); | 1980 | 103M | fast_mut!((s.block_type_length_state.block_length)[2]) -= 1; | 1981 | 103M | return true; | 1982 | 8.24M | } | 1983 | 8.24M | distval = s.distance_code - s.num_direct_distance_codes as i32; | 1984 | 8.24M | if (distval >= 0) { | 1985 | | let nbits: u32; | 1986 | | let postfix: i32; | 1987 | | let offset: i32; | 1988 | 617k | if (!safe && (s.distance_postfix_bits == 0)) { | 1989 | 202k | nbits = (distval as u32 >> 1) + 1; | 1990 | 202k | offset = ((2 + (distval & 1)) << nbits) - 4; | 1991 | 202k | s.distance_code = (s.num_direct_distance_codes as i64 + offset as i64 + | 1992 | 202k | bit_reader::BrotliReadBits(&mut s.br, nbits, input) as i64) as i32; | 1993 | 202k | } else { | 1994 | | // This branch also works well when s.distance_postfix_bits == 0 | 1995 | 415k | let mut bits: u32 = 0; | 1996 | 415k | postfix = distval & s.distance_postfix_mask; | 1997 | 415k | distval >>= s.distance_postfix_bits; | 1998 | 415k | nbits = (distval as u32 >> 1) + 1; | 1999 | 415k | if (safe) { | 2000 | 126k | if (!SafeReadBits(&mut s.br, nbits, &mut bits, input)) { | 2001 | 44.0k | s.distance_code = -1; /* Restore precondition. */ | 2002 | 44.0k | bit_reader::BrotliBitReaderRestoreState(&mut s.br, &memento); | 2003 | 44.0k | return false; | 2004 | 82.0k | } | 2005 | 289k | } else { | 2006 | 289k | bits = bit_reader::BrotliReadBits(&mut s.br, nbits, input); | 2007 | 289k | } | 2008 | 371k | offset = (((distval & 1).wrapping_add(2)) << nbits).wrapping_sub(4); | 2009 | 371k | s.distance_code = ((i64::from(offset) + i64::from(bits)) << s.distance_postfix_bits).wrapping_add(i64::from(postfix)).wrapping_add(i64::from(s.num_direct_distance_codes)) as i32; | 2010 | | } | 2011 | 7.62M | } | 2012 | 8.19M | s.distance_code = s.distance_code.wrapping_sub(NUM_DISTANCE_SHORT_CODES as i32).wrapping_add(1); | 2013 | 8.19M | fast_mut!((s.block_type_length_state.block_length)[2]) -= 1; | 2014 | 8.19M | true | 2015 | 111M | } |
Unexecuted instantiation: brotli_decompressor::decode::ReadDistanceInternal::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::ReadDistanceInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::ReadDistanceInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1950 | 5.00M | pub fn ReadDistanceInternal<AllocU8: alloc::Allocator<u8>, | 1951 | 5.00M | AllocU32: alloc::Allocator<u32>, | 1952 | 5.00M | AllocHC: alloc::Allocator<HuffmanCode>> | 1953 | 5.00M | (safe: bool, | 1954 | 5.00M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1955 | 5.00M | input: &[u8], | 1956 | 5.00M | distance_hgroup: &[&[HuffmanCode]; 256]) | 1957 | 5.00M | -> bool { | 1958 | | let mut distval: i32; | 1959 | 5.00M | let mut memento = bit_reader::BrotliBitReaderState::default(); | 1960 | 5.00M | if (!safe) { | 1961 | 4.27M | s.distance_code = ReadSymbol(fast!((distance_hgroup)[s.dist_htree_index as usize]), | 1962 | 4.27M | &mut s.br, | 1963 | 4.27M | input) as i32; | 1964 | 4.27M | } else { | 1965 | 732k | let mut code: u32 = 0; | 1966 | 732k | memento = bit_reader::BrotliBitReaderSaveState(&s.br); | 1967 | 732k | if !SafeReadSymbol(fast!((distance_hgroup)[s.dist_htree_index as usize]), | 1968 | 732k | &mut s.br, | 1969 | 732k | &mut code, | 1970 | 732k | input) { | 1971 | 1.90k | return false; | 1972 | 730k | } | 1973 | 730k | s.distance_code = code as i32; | 1974 | | } | 1975 | | // Convert the distance code to the actual distance by possibly | 1976 | | // looking up past distances from the s.ringbuffer. | 1977 | 5.00M | s.distance_context = 0; | 1978 | 5.00M | if ((s.distance_code as u64 & 0xfffffffffffffff0) == 0) { | 1979 | 2.59M | TakeDistanceFromRingBuffer(s); | 1980 | 2.59M | fast_mut!((s.block_type_length_state.block_length)[2]) -= 1; | 1981 | 2.59M | return true; | 1982 | 2.40M | } | 1983 | 2.40M | distval = s.distance_code - s.num_direct_distance_codes as i32; | 1984 | 2.40M | if (distval >= 0) { | 1985 | | let nbits: u32; | 1986 | | let postfix: i32; | 1987 | | let offset: i32; | 1988 | 1.77M | if (!safe && (s.distance_postfix_bits == 0)) { | 1989 | 94.1k | nbits = (distval as u32 >> 1) + 1; | 1990 | 94.1k | offset = ((2 + (distval & 1)) << nbits) - 4; | 1991 | 94.1k | s.distance_code = (s.num_direct_distance_codes as i64 + offset as i64 + | 1992 | 94.1k | bit_reader::BrotliReadBits(&mut s.br, nbits, input) as i64) as i32; | 1993 | 94.1k | } else { | 1994 | | // This branch also works well when s.distance_postfix_bits == 0 | 1995 | 1.68M | let mut bits: u32 = 0; | 1996 | 1.68M | postfix = distval & s.distance_postfix_mask; | 1997 | 1.68M | distval >>= s.distance_postfix_bits; | 1998 | 1.68M | nbits = (distval as u32 >> 1) + 1; | 1999 | 1.68M | if (safe) { | 2000 | 64.3k | if (!SafeReadBits(&mut s.br, nbits, &mut bits, input)) { | 2001 | 5.47k | s.distance_code = -1; /* Restore precondition. */ | 2002 | 5.47k | bit_reader::BrotliBitReaderRestoreState(&mut s.br, &memento); | 2003 | 5.47k | return false; | 2004 | 58.9k | } | 2005 | 1.61M | } else { | 2006 | 1.61M | bits = bit_reader::BrotliReadBits(&mut s.br, nbits, input); | 2007 | 1.61M | } | 2008 | 1.67M | offset = (((distval & 1).wrapping_add(2)) << nbits).wrapping_sub(4); | 2009 | 1.67M | s.distance_code = ((i64::from(offset) + i64::from(bits)) << s.distance_postfix_bits).wrapping_add(i64::from(postfix)).wrapping_add(i64::from(s.num_direct_distance_codes)) as i32; | 2010 | | } | 2011 | 631k | } | 2012 | 2.40M | s.distance_code = s.distance_code.wrapping_sub(NUM_DISTANCE_SHORT_CODES as i32).wrapping_add(1); | 2013 | 2.40M | fast_mut!((s.block_type_length_state.block_length)[2]) -= 1; | 2014 | 2.40M | true | 2015 | 5.00M | } |
brotli_decompressor::decode::ReadDistanceInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 1950 | 41.9M | pub fn ReadDistanceInternal<AllocU8: alloc::Allocator<u8>, | 1951 | 41.9M | AllocU32: alloc::Allocator<u32>, | 1952 | 41.9M | AllocHC: alloc::Allocator<HuffmanCode>> | 1953 | 41.9M | (safe: bool, | 1954 | 41.9M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 1955 | 41.9M | input: &[u8], | 1956 | 41.9M | distance_hgroup: &[&[HuffmanCode]; 256]) | 1957 | 41.9M | -> bool { | 1958 | | let mut distval: i32; | 1959 | 41.9M | let mut memento = bit_reader::BrotliBitReaderState::default(); | 1960 | 41.9M | if (!safe) { | 1961 | 17.3M | s.distance_code = ReadSymbol(fast!((distance_hgroup)[s.dist_htree_index as usize]), | 1962 | 17.3M | &mut s.br, | 1963 | 17.3M | input) as i32; | 1964 | 17.3M | } else { | 1965 | 24.5M | let mut code: u32 = 0; | 1966 | 24.5M | memento = bit_reader::BrotliBitReaderSaveState(&s.br); | 1967 | 24.5M | if !SafeReadSymbol(fast!((distance_hgroup)[s.dist_htree_index as usize]), | 1968 | 24.5M | &mut s.br, | 1969 | 24.5M | &mut code, | 1970 | 24.5M | input) { | 1971 | 5.65k | return false; | 1972 | 24.5M | } | 1973 | 24.5M | s.distance_code = code as i32; | 1974 | | } | 1975 | | // Convert the distance code to the actual distance by possibly | 1976 | | // looking up past distances from the s.ringbuffer. | 1977 | 41.9M | s.distance_context = 0; | 1978 | 41.9M | if ((s.distance_code as u64 & 0xfffffffffffffff0) == 0) { | 1979 | 39.2M | TakeDistanceFromRingBuffer(s); | 1980 | 39.2M | fast_mut!((s.block_type_length_state.block_length)[2]) -= 1; | 1981 | 39.2M | return true; | 1982 | 2.66M | } | 1983 | 2.66M | distval = s.distance_code - s.num_direct_distance_codes as i32; | 1984 | 2.66M | if (distval >= 0) { | 1985 | | let nbits: u32; | 1986 | | let postfix: i32; | 1987 | | let offset: i32; | 1988 | 381k | if (!safe && (s.distance_postfix_bits == 0)) { | 1989 | 75.2k | nbits = (distval as u32 >> 1) + 1; | 1990 | 75.2k | offset = ((2 + (distval & 1)) << nbits) - 4; | 1991 | 75.2k | s.distance_code = (s.num_direct_distance_codes as i64 + offset as i64 + | 1992 | 75.2k | bit_reader::BrotliReadBits(&mut s.br, nbits, input) as i64) as i32; | 1993 | 75.2k | } else { | 1994 | | // This branch also works well when s.distance_postfix_bits == 0 | 1995 | 306k | let mut bits: u32 = 0; | 1996 | 306k | postfix = distval & s.distance_postfix_mask; | 1997 | 306k | distval >>= s.distance_postfix_bits; | 1998 | 306k | nbits = (distval as u32 >> 1) + 1; | 1999 | 306k | if (safe) { | 2000 | 46.7k | if (!SafeReadBits(&mut s.br, nbits, &mut bits, input)) { | 2001 | 8.73k | s.distance_code = -1; /* Restore precondition. */ | 2002 | 8.73k | bit_reader::BrotliBitReaderRestoreState(&mut s.br, &memento); | 2003 | 8.73k | return false; | 2004 | 38.0k | } | 2005 | 259k | } else { | 2006 | 259k | bits = bit_reader::BrotliReadBits(&mut s.br, nbits, input); | 2007 | 259k | } | 2008 | 297k | offset = (((distval & 1).wrapping_add(2)) << nbits).wrapping_sub(4); | 2009 | 297k | s.distance_code = ((i64::from(offset) + i64::from(bits)) << s.distance_postfix_bits).wrapping_add(i64::from(postfix)).wrapping_add(i64::from(s.num_direct_distance_codes)) as i32; | 2010 | | } | 2011 | 2.28M | } | 2012 | 2.65M | s.distance_code = s.distance_code.wrapping_sub(NUM_DISTANCE_SHORT_CODES as i32).wrapping_add(1); | 2013 | 2.65M | fast_mut!((s.block_type_length_state.block_length)[2]) -= 1; | 2014 | 2.65M | true | 2015 | 41.9M | } |
|
2016 | | |
2017 | | |
2018 | 222M | pub fn ReadCommandInternal<AllocU8: alloc::Allocator<u8>, |
2019 | 222M | AllocU32: alloc::Allocator<u32>, |
2020 | 222M | AllocHC: alloc::Allocator<HuffmanCode>> |
2021 | 222M | (safe: bool, |
2022 | 222M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
2023 | 222M | insert_length: &mut i32, |
2024 | 222M | input: &[u8], |
2025 | 222M | insert_copy_hgroup: &[&[HuffmanCode]; 256]) |
2026 | 222M | -> bool { |
2027 | 222M | let mut cmd_code: u32 = 0; |
2028 | 222M | let mut insert_len_extra: u32 = 0; |
2029 | 222M | let mut copy_length: u32 = 0; |
2030 | | let v: prefix::CmdLutElement; |
2031 | 222M | let mut memento = bit_reader::BrotliBitReaderState::default(); |
2032 | 222M | if (!safe) { |
2033 | 57.5M | cmd_code = ReadSymbol(fast!((insert_copy_hgroup)[s.htree_command_index as usize]), |
2034 | 57.5M | &mut s.br, |
2035 | 57.5M | input); |
2036 | 57.5M | } else { |
2037 | 165M | memento = bit_reader::BrotliBitReaderSaveState(&s.br); |
2038 | 165M | if (!SafeReadSymbol(fast!((insert_copy_hgroup)[s.htree_command_index as usize]), |
2039 | 165M | &mut s.br, |
2040 | 165M | &mut cmd_code, |
2041 | 165M | input)) { |
2042 | 17.3k | return false; |
2043 | 165M | } |
2044 | | } |
2045 | 222M | v = fast!((prefix::kCmdLut)[cmd_code as usize]); |
2046 | 222M | s.distance_code = v.distance_code as i32; |
2047 | 222M | s.distance_context = v.context as i32; |
2048 | 222M | s.dist_htree_index = fast_slice!((s.dist_context_map)[s.dist_context_map_slice_index |
2049 | 222M | + s.distance_context as usize]); |
2050 | 222M | *insert_length = v.insert_len_offset as i32; |
2051 | 222M | if (!safe) { |
2052 | 57.5M | if v.insert_len_extra_bits != 0 { |
2053 | 1.41M | mark_unlikely(); |
2054 | 1.41M | insert_len_extra = |
2055 | 1.41M | bit_reader::BrotliReadBits(&mut s.br, v.insert_len_extra_bits as u32, input); |
2056 | 56.1M | } |
2057 | 57.5M | copy_length = bit_reader::BrotliReadBits(&mut s.br, v.copy_len_extra_bits as u32, input); |
2058 | 165M | } else if (!SafeReadBits(&mut s.br, |
2059 | 165M | v.insert_len_extra_bits as u32, |
2060 | 165M | &mut insert_len_extra, |
2061 | 165M | input)) || |
2062 | 165M | (!SafeReadBits(&mut s.br, |
2063 | 165M | v.copy_len_extra_bits as u32, |
2064 | 165M | &mut copy_length, |
2065 | 165M | input)) { |
2066 | 135k | bit_reader::BrotliBitReaderRestoreState(&mut s.br, &memento); |
2067 | 135k | return false; |
2068 | 165M | } |
2069 | 222M | s.copy_length = copy_length as i32 + v.copy_len_offset as i32; |
2070 | 222M | fast_mut!((s.block_type_length_state.block_length)[1]) -= 1; |
2071 | 222M | *insert_length += insert_len_extra as i32; |
2072 | 222M | true |
2073 | 222M | } brotli_decompressor::decode::ReadCommandInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2018 | 138M | pub fn ReadCommandInternal<AllocU8: alloc::Allocator<u8>, | 2019 | 138M | AllocU32: alloc::Allocator<u32>, | 2020 | 138M | AllocHC: alloc::Allocator<HuffmanCode>> | 2021 | 138M | (safe: bool, | 2022 | 138M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2023 | 138M | insert_length: &mut i32, | 2024 | 138M | input: &[u8], | 2025 | 138M | insert_copy_hgroup: &[&[HuffmanCode]; 256]) | 2026 | 138M | -> bool { | 2027 | 138M | let mut cmd_code: u32 = 0; | 2028 | 138M | let mut insert_len_extra: u32 = 0; | 2029 | 138M | let mut copy_length: u32 = 0; | 2030 | | let v: prefix::CmdLutElement; | 2031 | 138M | let mut memento = bit_reader::BrotliBitReaderState::default(); | 2032 | 138M | if (!safe) { | 2033 | 17.5M | cmd_code = ReadSymbol(fast!((insert_copy_hgroup)[s.htree_command_index as usize]), | 2034 | 17.5M | &mut s.br, | 2035 | 17.5M | input); | 2036 | 17.5M | } else { | 2037 | 121M | memento = bit_reader::BrotliBitReaderSaveState(&s.br); | 2038 | 121M | if (!SafeReadSymbol(fast!((insert_copy_hgroup)[s.htree_command_index as usize]), | 2039 | 121M | &mut s.br, | 2040 | 121M | &mut cmd_code, | 2041 | 121M | input)) { | 2042 | 5.19k | return false; | 2043 | 121M | } | 2044 | | } | 2045 | 138M | v = fast!((prefix::kCmdLut)[cmd_code as usize]); | 2046 | 138M | s.distance_code = v.distance_code as i32; | 2047 | 138M | s.distance_context = v.context as i32; | 2048 | 138M | s.dist_htree_index = fast_slice!((s.dist_context_map)[s.dist_context_map_slice_index | 2049 | 138M | + s.distance_context as usize]); | 2050 | 138M | *insert_length = v.insert_len_offset as i32; | 2051 | 138M | if (!safe) { | 2052 | 17.5M | if v.insert_len_extra_bits != 0 { | 2053 | 504k | mark_unlikely(); | 2054 | 504k | insert_len_extra = | 2055 | 504k | bit_reader::BrotliReadBits(&mut s.br, v.insert_len_extra_bits as u32, input); | 2056 | 17.0M | } | 2057 | 17.5M | copy_length = bit_reader::BrotliReadBits(&mut s.br, v.copy_len_extra_bits as u32, input); | 2058 | 121M | } else if (!SafeReadBits(&mut s.br, | 2059 | 121M | v.insert_len_extra_bits as u32, | 2060 | 121M | &mut insert_len_extra, | 2061 | 121M | input)) || | 2062 | 121M | (!SafeReadBits(&mut s.br, | 2063 | 121M | v.copy_len_extra_bits as u32, | 2064 | 121M | &mut copy_length, | 2065 | 121M | input)) { | 2066 | 85.2k | bit_reader::BrotliBitReaderRestoreState(&mut s.br, &memento); | 2067 | 85.2k | return false; | 2068 | 121M | } | 2069 | 138M | s.copy_length = copy_length as i32 + v.copy_len_offset as i32; | 2070 | 138M | fast_mut!((s.block_type_length_state.block_length)[1]) -= 1; | 2071 | 138M | *insert_length += insert_len_extra as i32; | 2072 | 138M | true | 2073 | 138M | } |
Unexecuted instantiation: brotli_decompressor::decode::ReadCommandInternal::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::ReadCommandInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::ReadCommandInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2018 | 16.7M | pub fn ReadCommandInternal<AllocU8: alloc::Allocator<u8>, | 2019 | 16.7M | AllocU32: alloc::Allocator<u32>, | 2020 | 16.7M | AllocHC: alloc::Allocator<HuffmanCode>> | 2021 | 16.7M | (safe: bool, | 2022 | 16.7M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2023 | 16.7M | insert_length: &mut i32, | 2024 | 16.7M | input: &[u8], | 2025 | 16.7M | insert_copy_hgroup: &[&[HuffmanCode]; 256]) | 2026 | 16.7M | -> bool { | 2027 | 16.7M | let mut cmd_code: u32 = 0; | 2028 | 16.7M | let mut insert_len_extra: u32 = 0; | 2029 | 16.7M | let mut copy_length: u32 = 0; | 2030 | | let v: prefix::CmdLutElement; | 2031 | 16.7M | let mut memento = bit_reader::BrotliBitReaderState::default(); | 2032 | 16.7M | if (!safe) { | 2033 | 13.1M | cmd_code = ReadSymbol(fast!((insert_copy_hgroup)[s.htree_command_index as usize]), | 2034 | 13.1M | &mut s.br, | 2035 | 13.1M | input); | 2036 | 13.1M | } else { | 2037 | 3.63M | memento = bit_reader::BrotliBitReaderSaveState(&s.br); | 2038 | 3.63M | if (!SafeReadSymbol(fast!((insert_copy_hgroup)[s.htree_command_index as usize]), | 2039 | 3.63M | &mut s.br, | 2040 | 3.63M | &mut cmd_code, | 2041 | 3.63M | input)) { | 2042 | 4.03k | return false; | 2043 | 3.62M | } | 2044 | | } | 2045 | 16.7M | v = fast!((prefix::kCmdLut)[cmd_code as usize]); | 2046 | 16.7M | s.distance_code = v.distance_code as i32; | 2047 | 16.7M | s.distance_context = v.context as i32; | 2048 | 16.7M | s.dist_htree_index = fast_slice!((s.dist_context_map)[s.dist_context_map_slice_index | 2049 | 16.7M | + s.distance_context as usize]); | 2050 | 16.7M | *insert_length = v.insert_len_offset as i32; | 2051 | 16.7M | if (!safe) { | 2052 | 13.1M | if v.insert_len_extra_bits != 0 { | 2053 | 559k | mark_unlikely(); | 2054 | 559k | insert_len_extra = | 2055 | 559k | bit_reader::BrotliReadBits(&mut s.br, v.insert_len_extra_bits as u32, input); | 2056 | 12.5M | } | 2057 | 13.1M | copy_length = bit_reader::BrotliReadBits(&mut s.br, v.copy_len_extra_bits as u32, input); | 2058 | 3.62M | } else if (!SafeReadBits(&mut s.br, | 2059 | 3.62M | v.insert_len_extra_bits as u32, | 2060 | 3.62M | &mut insert_len_extra, | 2061 | 3.62M | input)) || | 2062 | 3.62M | (!SafeReadBits(&mut s.br, | 2063 | 3.62M | v.copy_len_extra_bits as u32, | 2064 | 3.62M | &mut copy_length, | 2065 | 3.62M | input)) { | 2066 | 8.94k | bit_reader::BrotliBitReaderRestoreState(&mut s.br, &memento); | 2067 | 8.94k | return false; | 2068 | 3.61M | } | 2069 | 16.7M | s.copy_length = copy_length as i32 + v.copy_len_offset as i32; | 2070 | 16.7M | fast_mut!((s.block_type_length_state.block_length)[1]) -= 1; | 2071 | 16.7M | *insert_length += insert_len_extra as i32; | 2072 | 16.7M | true | 2073 | 16.7M | } |
brotli_decompressor::decode::ReadCommandInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2018 | 67.2M | pub fn ReadCommandInternal<AllocU8: alloc::Allocator<u8>, | 2019 | 67.2M | AllocU32: alloc::Allocator<u32>, | 2020 | 67.2M | AllocHC: alloc::Allocator<HuffmanCode>> | 2021 | 67.2M | (safe: bool, | 2022 | 67.2M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2023 | 67.2M | insert_length: &mut i32, | 2024 | 67.2M | input: &[u8], | 2025 | 67.2M | insert_copy_hgroup: &[&[HuffmanCode]; 256]) | 2026 | 67.2M | -> bool { | 2027 | 67.2M | let mut cmd_code: u32 = 0; | 2028 | 67.2M | let mut insert_len_extra: u32 = 0; | 2029 | 67.2M | let mut copy_length: u32 = 0; | 2030 | | let v: prefix::CmdLutElement; | 2031 | 67.2M | let mut memento = bit_reader::BrotliBitReaderState::default(); | 2032 | 67.2M | if (!safe) { | 2033 | 26.9M | cmd_code = ReadSymbol(fast!((insert_copy_hgroup)[s.htree_command_index as usize]), | 2034 | 26.9M | &mut s.br, | 2035 | 26.9M | input); | 2036 | 26.9M | } else { | 2037 | 40.3M | memento = bit_reader::BrotliBitReaderSaveState(&s.br); | 2038 | 40.3M | if (!SafeReadSymbol(fast!((insert_copy_hgroup)[s.htree_command_index as usize]), | 2039 | 40.3M | &mut s.br, | 2040 | 40.3M | &mut cmd_code, | 2041 | 40.3M | input)) { | 2042 | 8.12k | return false; | 2043 | 40.3M | } | 2044 | | } | 2045 | 67.2M | v = fast!((prefix::kCmdLut)[cmd_code as usize]); | 2046 | 67.2M | s.distance_code = v.distance_code as i32; | 2047 | 67.2M | s.distance_context = v.context as i32; | 2048 | 67.2M | s.dist_htree_index = fast_slice!((s.dist_context_map)[s.dist_context_map_slice_index | 2049 | 67.2M | + s.distance_context as usize]); | 2050 | 67.2M | *insert_length = v.insert_len_offset as i32; | 2051 | 67.2M | if (!safe) { | 2052 | 26.9M | if v.insert_len_extra_bits != 0 { | 2053 | 347k | mark_unlikely(); | 2054 | 347k | insert_len_extra = | 2055 | 347k | bit_reader::BrotliReadBits(&mut s.br, v.insert_len_extra_bits as u32, input); | 2056 | 26.5M | } | 2057 | 26.9M | copy_length = bit_reader::BrotliReadBits(&mut s.br, v.copy_len_extra_bits as u32, input); | 2058 | 40.3M | } else if (!SafeReadBits(&mut s.br, | 2059 | 40.3M | v.insert_len_extra_bits as u32, | 2060 | 40.3M | &mut insert_len_extra, | 2061 | 40.3M | input)) || | 2062 | 40.2M | (!SafeReadBits(&mut s.br, | 2063 | 40.2M | v.copy_len_extra_bits as u32, | 2064 | 40.2M | &mut copy_length, | 2065 | 40.2M | input)) { | 2066 | 41.0k | bit_reader::BrotliBitReaderRestoreState(&mut s.br, &memento); | 2067 | 41.0k | return false; | 2068 | 40.2M | } | 2069 | 67.1M | s.copy_length = copy_length as i32 + v.copy_len_offset as i32; | 2070 | 67.1M | fast_mut!((s.block_type_length_state.block_length)[1]) -= 1; | 2071 | 67.1M | *insert_length += insert_len_extra as i32; | 2072 | 67.1M | true | 2073 | 67.2M | } |
|
2074 | | |
2075 | | |
2076 | 839k | fn WarmupBitReader(safe: bool, br: &mut bit_reader::BrotliBitReader, input: &[u8]) -> bool { |
2077 | 839k | safe || bit_reader::BrotliWarmupBitReader(br, input) |
2078 | 839k | } |
2079 | | |
2080 | 2.80G | fn CheckInputAmount(safe: bool, br: &bit_reader::BrotliBitReader, num: u32) -> bool { |
2081 | 2.80G | safe || bit_reader::BrotliCheckInputAmount(br, num) |
2082 | 2.80G | } |
2083 | | |
2084 | | #[inline(always)] |
2085 | 195M | fn memmove16(data: &mut [u8], u32off_dst: u32, u32off_src: u32) { |
2086 | 195M | let off_dst = u32off_dst as usize; |
2087 | 195M | let off_src = u32off_src as usize; |
2088 | | // data[off_dst + 15] = data[off_src + 15]; |
2089 | | // data[off_dst + 14] = data[off_src + 14]; |
2090 | | // data[off_dst + 13] = data[off_src + 13]; |
2091 | | // data[off_dst + 12] = data[off_src + 12]; |
2092 | | // |
2093 | | // data[off_dst + 11] = data[off_src + 11]; |
2094 | | // data[off_dst + 10] = data[off_src + 10]; |
2095 | | // data[off_dst + 9] = data[off_src + 9]; |
2096 | | // data[off_dst + 8] = data[off_src + 8]; |
2097 | | // |
2098 | | // data[off_dst + 7] = data[off_src + 7]; |
2099 | | // data[off_dst + 6] = data[off_src + 6]; |
2100 | | // data[off_dst + 5] = data[off_src + 5]; |
2101 | | // data[off_dst + 4] = data[off_src + 4]; |
2102 | | // |
2103 | | // data[off_dst + 3] = data[off_src + 3]; |
2104 | | // data[off_dst + 2] = data[off_src + 2]; |
2105 | | // data[off_dst + 1] = data[off_src + 1]; |
2106 | | // |
2107 | 195M | let mut local_array: [u8; 16] = fast_uninitialized!(16); |
2108 | 195M | local_array.clone_from_slice(fast!((data)[off_src as usize ; off_src as usize + 16])); |
2109 | 195M | fast_mut!((data)[off_dst as usize ; off_dst as usize + 16]).clone_from_slice(&local_array); |
2110 | | |
2111 | | |
2112 | 195M | } |
2113 | | |
2114 | | |
2115 | | #[cfg(not(feature="unsafe"))] |
2116 | 1.48M | fn memcpy_within_slice(data: &mut [u8], off_dst: usize, off_src: usize, size: usize) { |
2117 | 1.48M | if off_dst > off_src { |
2118 | 1.19M | let (src, dst) = data.split_at_mut(off_dst); |
2119 | 1.19M | let src_slice = fast!((src)[off_src ; off_src + size]); |
2120 | 1.19M | fast_mut!((dst)[0;size]).clone_from_slice(src_slice); |
2121 | 1.19M | } else { |
2122 | 290k | let (dst, src) = data.split_at_mut(off_src); |
2123 | 290k | let src_slice = fast!((src)[0;size]); |
2124 | 290k | fast_mut!((dst)[off_dst;off_dst + size]).clone_from_slice(src_slice); |
2125 | 290k | } |
2126 | 1.48M | } |
2127 | | |
2128 | | #[cfg(feature="unsafe")] |
2129 | | fn memcpy_within_slice(data: &mut [u8], off_dst: usize, off_src: usize, size: usize) { |
2130 | | let ptr = data.as_mut_ptr(); |
2131 | | unsafe { |
2132 | | let dst = ptr.offset(off_dst as isize); |
2133 | | let src = ptr.offset(off_src as isize); |
2134 | | core::ptr::copy_nonoverlapping(src, dst, size); |
2135 | | } |
2136 | | } |
2137 | | |
2138 | 0 | pub fn BrotliDecoderHasMoreOutput<AllocU8: alloc::Allocator<u8>, |
2139 | 0 | AllocU32: alloc::Allocator<u32>, |
2140 | 0 | AllocHC: alloc::Allocator<HuffmanCode>> |
2141 | 0 | (s: &BrotliState<AllocU8, AllocU32, AllocHC>) -> bool { |
2142 | | /* After unrecoverable error remaining output is considered nonsensical. */ |
2143 | 0 | if is_fatal(s.error_code) { |
2144 | 0 | return false; |
2145 | 0 | } |
2146 | 0 | s.ringbuffer.len() != 0 && UnwrittenBytes(s, false) != 0 |
2147 | 0 | } |
2148 | 0 | pub fn BrotliDecoderTakeOutput<'a, |
2149 | 0 | AllocU8: alloc::Allocator<u8>, |
2150 | 0 | AllocU32: alloc::Allocator<u32>, |
2151 | 0 | AllocHC: alloc::Allocator<HuffmanCode>>( |
2152 | 0 | s: &'a mut BrotliState<AllocU8, AllocU32, AllocHC>, |
2153 | 0 | size: &mut usize, |
2154 | 0 | ) -> &'a [u8] { |
2155 | 0 | let one:usize = 1; |
2156 | 0 | let mut available_out = if *size != 0 { *size } else { one << 24 }; |
2157 | 0 | let requested_out = available_out; |
2158 | 0 | if (s.ringbuffer.len() == 0) || is_fatal(s.error_code) { |
2159 | 0 | *size = 0; |
2160 | 0 | return &[]; |
2161 | 0 | } |
2162 | 0 | WrapRingBuffer(s); |
2163 | 0 | let mut ign = 0usize; |
2164 | 0 | let mut ign2 = 0usize; |
2165 | 0 | let (status, result) = WriteRingBuffer(&mut available_out, None, &mut ign,&mut ign2, true, s); |
2166 | | // Either WriteRingBuffer returns those "success" codes... |
2167 | 0 | match status { |
2168 | 0 | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS | BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_OUTPUT => { |
2169 | 0 | *size = requested_out - available_out; |
2170 | 0 | }, |
2171 | | _ => { |
2172 | | // ... or stream is broken. Normally this should be caught by |
2173 | | // BrotliDecoderDecompressStream, this is just a safeguard. |
2174 | 0 | if is_fatal(status) { |
2175 | 0 | // SaveErrorCode!(s, status); //borrow checker doesn't like this |
2176 | 0 | // but since it's a safeguard--ignore |
2177 | 0 | } |
2178 | 0 | *size = 0; |
2179 | 0 | return &[]; |
2180 | | } |
2181 | | } |
2182 | 0 | return result; |
2183 | 0 | } |
2184 | | |
2185 | | #[cfg(feature="ffi-api")] |
2186 | | pub fn BrotliDecoderIsUsed<AllocU8: alloc::Allocator<u8>, |
2187 | | AllocU32: alloc::Allocator<u32>, |
2188 | | AllocHC: alloc::Allocator<HuffmanCode>>( |
2189 | | s: &BrotliState<AllocU8, AllocU32, AllocHC>) -> bool { |
2190 | | if let BrotliRunningState::BROTLI_STATE_UNINITED = s.state { |
2191 | | false |
2192 | | } else { |
2193 | | bit_reader::BrotliGetAvailableBits(&s.br) != 0 |
2194 | | } |
2195 | | } |
2196 | | |
2197 | 0 | pub fn BrotliDecoderIsFinished<AllocU8: alloc::Allocator<u8>, |
2198 | 0 | AllocU32: alloc::Allocator<u32>, |
2199 | 0 | AllocHC: alloc::Allocator<HuffmanCode>>( |
2200 | 0 | s: &BrotliState<AllocU8, AllocU32, AllocHC>) -> bool { |
2201 | 0 | if let BrotliRunningState::BROTLI_STATE_DONE = s.state { |
2202 | 0 | !BrotliDecoderHasMoreOutput(s) |
2203 | | } else { |
2204 | 0 | false |
2205 | | } |
2206 | 0 | } |
2207 | | |
2208 | | pub fn BrotliDecoderGetErrorCode<AllocU8: alloc::Allocator<u8>, |
2209 | | AllocU32: alloc::Allocator<u32>, |
2210 | | AllocHC: alloc::Allocator<HuffmanCode>>( |
2211 | | s: &BrotliState<AllocU8, AllocU32, AllocHC>) -> BrotliDecoderErrorCode { |
2212 | | s.error_code |
2213 | | } |
2214 | | |
2215 | 1.44M | fn ProcessCommandsInternal<AllocU8: alloc::Allocator<u8>, |
2216 | 1.44M | AllocU32: alloc::Allocator<u32>, |
2217 | 1.44M | AllocHC: alloc::Allocator<HuffmanCode>> |
2218 | 1.44M | (safe: bool, |
2219 | 1.44M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
2220 | 1.44M | input: &[u8]) |
2221 | 1.44M | -> BrotliDecoderErrorCode { |
2222 | 1.44M | if (!CheckInputAmount(safe, &s.br, 28)) || (!WarmupBitReader(safe, &mut s.br, input)) { |
2223 | 605k | mark_unlikely(); |
2224 | 605k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2225 | 839k | } |
2226 | 839k | let mut pos = s.pos; |
2227 | 839k | let mut i: i32 = s.loop_counter; // important that this is signed |
2228 | 839k | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
2229 | 839k | let mut saved_literal_hgroup = |
2230 | 839k | core::mem::replace(&mut s.literal_hgroup, |
2231 | 839k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); |
2232 | 839k | let mut saved_distance_hgroup = |
2233 | 839k | core::mem::replace(&mut s.distance_hgroup, |
2234 | 839k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); |
2235 | 839k | let mut saved_insert_copy_hgroup = |
2236 | 839k | core::mem::replace(&mut s.insert_copy_hgroup, |
2237 | 839k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); |
2238 | | { |
2239 | | |
2240 | 839k | let literal_hgroup = saved_literal_hgroup.build_hgroup_cache(); |
2241 | 839k | let distance_hgroup = saved_distance_hgroup.build_hgroup_cache(); |
2242 | 839k | let insert_copy_hgroup = saved_insert_copy_hgroup.build_hgroup_cache(); |
2243 | | |
2244 | | loop { |
2245 | 564M | match s.state { |
2246 | | BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN => { |
2247 | 223M | if (!CheckInputAmount(safe, &s.br, 28)) { |
2248 | | // 156 bits + 7 bytes |
2249 | 27.6k | mark_unlikely(); |
2250 | 27.6k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2251 | 27.6k | break; // return |
2252 | 223M | } |
2253 | 223M | if (fast_mut!((s.block_type_length_state.block_length)[1]) == 0) { |
2254 | 751k | mark_unlikely(); |
2255 | 751k | if !DecodeCommandBlockSwitchInternal(safe, s, input) { |
2256 | 664 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2257 | 664 | break; // return |
2258 | 751k | } |
2259 | 751k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; |
2260 | 751k | continue; // goto CommandBegin; |
2261 | 222M | } |
2262 | | // Read the insert/copy length in the command |
2263 | 222M | if (!ReadCommandInternal(safe, s, &mut i, input, &insert_copy_hgroup)) && safe { |
2264 | 152k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2265 | 152k | break; // return |
2266 | 222M | } |
2267 | | BROTLI_LOG!("[ProcessCommandsInternal] pos = %d insert = %d copy = %d distance = %d\n", |
2268 | | pos, i, s.copy_length, s.distance_code); |
2269 | 222M | if (i == 0) { |
2270 | 187M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; |
2271 | 187M | continue; // goto CommandPostDecodeLiterals; |
2272 | 35.5M | } |
2273 | 35.5M | s.meta_block_remaining_len -= i; |
2274 | 35.5M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; |
2275 | | } |
2276 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER => { |
2277 | | // Read the literals in the command |
2278 | 35.7M | if (s.trivial_literal_context != 0) { |
2279 | 30.5M | let mut bits: u32 = 0; |
2280 | 30.5M | let mut value: u32 = 0; |
2281 | 30.5M | let mut literal_htree = &fast!((literal_hgroup)[s.literal_htree_index as usize]); |
2282 | 30.5M | PreloadSymbol(safe, literal_htree, &mut s.br, &mut bits, &mut value, input); |
2283 | 30.5M | let mut inner_return: bool = false; |
2284 | 30.5M | let mut inner_continue: bool = false; |
2285 | | loop { |
2286 | 2.38G | if (!CheckInputAmount(safe, &s.br, 28)) { |
2287 | | // 162 bits + 7 bytes |
2288 | 19.1k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2289 | 19.1k | inner_return = true; |
2290 | 19.1k | break; |
2291 | 2.38G | } |
2292 | 2.38G | if (fast!((s.block_type_length_state.block_length)[0]) == 0) { |
2293 | 8.54M | mark_unlikely(); |
2294 | 8.54M | if (!DecodeLiteralBlockSwitchInternal(safe, s, input)) && safe { |
2295 | 16.6k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2296 | 16.6k | inner_return = true; |
2297 | 16.6k | break; |
2298 | 8.53M | } |
2299 | 8.53M | literal_htree = fast_ref!((literal_hgroup)[s.literal_htree_index as usize]); |
2300 | 8.53M | PreloadSymbol(safe, literal_htree, &mut s.br, &mut bits, &mut value, input); |
2301 | 8.53M | if (s.trivial_literal_context == 0) { |
2302 | 6.31k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; |
2303 | 6.31k | inner_continue = true; |
2304 | 6.31k | break; // goto StateCommandInner |
2305 | 8.52M | } |
2306 | 2.37G | } |
2307 | 2.38G | if (!safe) { |
2308 | 384M | fast_mut!((s.ringbuffer.slice_mut())[pos as usize]) = |
2309 | 384M | ReadPreloadedSymbol(literal_htree, &mut s.br, &mut bits, &mut value, input) as u8; |
2310 | 384M | } else { |
2311 | 1.99G | let mut literal: u32 = 0; |
2312 | 1.99G | if (!SafeReadSymbol(literal_htree, &mut s.br, &mut literal, input)) { |
2313 | 45.4k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2314 | 45.4k | inner_return = true; |
2315 | 45.4k | break; |
2316 | 1.99G | } |
2317 | 1.99G | fast_mut!((s.ringbuffer.slice_mut())[pos as usize]) = literal as u8; |
2318 | | } |
2319 | 2.38G | if (s.block_type_length_state.block_length)[0] == 0 { |
2320 | 2 | mark_unlikely(); |
2321 | 2 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; |
2322 | 2 | inner_return = true; |
2323 | 2 | break; |
2324 | 2.38G | } |
2325 | 2.38G | fast_mut!((s.block_type_length_state.block_length)[0]) -= 1; |
2326 | | BROTLI_LOG_UINT!(s.literal_htree_index); |
2327 | | BROTLI_LOG_ARRAY_INDEX!(s.ringbuffer.slice(), pos); |
2328 | 2.38G | pos += 1; |
2329 | 2.38G | if (pos == s.ringbuffer_size) { |
2330 | 68.7k | mark_unlikely(); |
2331 | 68.7k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE; |
2332 | 68.7k | i -= 1; |
2333 | 68.7k | inner_return = true; |
2334 | 68.7k | break; |
2335 | 2.38G | } |
2336 | 2.38G | i -= 1; |
2337 | 2.38G | if i == 0 { |
2338 | 30.3M | break; |
2339 | 2.34G | } |
2340 | | } |
2341 | 30.5M | if inner_return { |
2342 | 150k | break; // return |
2343 | 30.3M | } |
2344 | 30.3M | if inner_continue { |
2345 | 6.31k | mark_unlikely(); |
2346 | 6.31k | continue; |
2347 | 30.3M | } |
2348 | | } else { |
2349 | 5.23M | let mut p1 = fast_slice!((s.ringbuffer)[((pos - 1) & s.ringbuffer_mask) as usize]); |
2350 | 5.23M | let mut p2 = fast_slice!((s.ringbuffer)[((pos - 2) & s.ringbuffer_mask) as usize]); |
2351 | 5.23M | if s.custom_dict_avoid_context_seed && pos < 2 { |
2352 | 0 | mark_unlikely(); |
2353 | 0 | p2 = 0; |
2354 | 0 | p1 = 0; |
2355 | 5.23M | } |
2356 | 5.23M | if pos > 1 |
2357 | 5.21M | { |
2358 | 5.21M | // have already set both seed bytes and can now move on to using |
2359 | 5.21M | // the ringbuffer. |
2360 | 5.21M | s.custom_dict_avoid_context_seed = false; |
2361 | 5.21M | } |
2362 | 5.23M | let mut inner_return: bool = false; |
2363 | 5.23M | let mut inner_continue: bool = false; |
2364 | | loop { |
2365 | 199M | if (!CheckInputAmount(safe, &s.br, 28)) { |
2366 | | // 162 bits + 7 bytes |
2367 | 4.02k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; |
2368 | 4.02k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2369 | 4.02k | inner_return = true; |
2370 | 4.02k | break; |
2371 | 199M | } |
2372 | 199M | if (fast!((s.block_type_length_state.block_length)[0]) == 0) { |
2373 | 1.13M | mark_unlikely(); |
2374 | 1.13M | if (!DecodeLiteralBlockSwitchInternal(safe, s, input)) && safe { |
2375 | 12.9k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2376 | 12.9k | inner_return = true; |
2377 | 12.9k | break; |
2378 | 1.12M | } |
2379 | 1.12M | if s.trivial_literal_context != 0 { |
2380 | 6.28k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; |
2381 | 6.28k | inner_continue = true; |
2382 | 6.28k | break; |
2383 | 1.11M | } |
2384 | 198M | } |
2385 | 199M | let context = s.context_lookup[p1 as usize] | s.context_lookup[p2 as usize |256]; |
2386 | | BROTLI_LOG_UINT!(p1); |
2387 | | BROTLI_LOG_UINT!(p2); |
2388 | | BROTLI_LOG_UINT!(context); |
2389 | | let hc: &[HuffmanCode]; |
2390 | 199M | { |
2391 | 199M | let i = fast_slice!((s.context_map)[s.context_map_slice_index + context as usize]); |
2392 | 199M | hc = fast!((literal_hgroup)[i as usize]); |
2393 | 199M | } |
2394 | 199M | p2 = p1; |
2395 | 199M | if (!safe) { |
2396 | 153M | p1 = ReadSymbol(hc, &mut s.br, input) as u8; |
2397 | 153M | } else { |
2398 | 45.6M | let mut literal: u32 = 0; |
2399 | 45.6M | if (!SafeReadSymbol(hc, &mut s.br, &mut literal, input)) { |
2400 | 72.1k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2401 | 72.1k | inner_return = true; |
2402 | 72.1k | break; |
2403 | 45.5M | } |
2404 | 45.5M | p1 = literal as u8; |
2405 | | } |
2406 | 199M | fast_slice_mut!((s.ringbuffer)[pos as usize]) = p1; |
2407 | 199M | if (s.block_type_length_state.block_length)[0] == 0 { |
2408 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; |
2409 | 0 | inner_return = true; |
2410 | 0 | break; |
2411 | 199M | } |
2412 | 199M | fast_mut!((s.block_type_length_state.block_length)[0]) -= 1; |
2413 | | BROTLI_LOG_UINT!(s.context_map.slice()[s.context_map_slice_index as usize + |
2414 | | context as usize]); |
2415 | | BROTLI_LOG_ARRAY_INDEX!(s.ringbuffer.slice(), pos & s.ringbuffer_mask); |
2416 | 199M | pos += 1; |
2417 | 199M | if (pos == s.ringbuffer_size) { |
2418 | 9.09k | mark_unlikely(); |
2419 | 9.09k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE; |
2420 | 9.09k | i -= 1; |
2421 | 9.09k | inner_return = true; |
2422 | 9.09k | break; |
2423 | 199M | } |
2424 | 199M | i -= 1; |
2425 | 199M | if i == 0 { |
2426 | 5.12M | break; |
2427 | 194M | } |
2428 | | } |
2429 | 5.23M | if inner_return { |
2430 | 98.2k | break; // return |
2431 | 5.13M | } |
2432 | 5.13M | if inner_continue { |
2433 | 6.28k | mark_unlikely(); |
2434 | 6.28k | continue; |
2435 | 5.12M | } |
2436 | | } |
2437 | 35.4M | if (s.meta_block_remaining_len <= 0) { |
2438 | 14.1k | mark_unlikely(); |
2439 | 14.1k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; |
2440 | 14.1k | break; // return |
2441 | 35.4M | } |
2442 | 35.4M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; |
2443 | | } |
2444 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS => { |
2445 | 222M | if s.distance_code >= 0 { |
2446 | 64.3M | let not_distance_code = if s.distance_code != 0 { 0 } else { 1 }; |
2447 | 64.3M | s.distance_context = not_distance_code; |
2448 | 64.3M | s.dist_rb_idx -= 1; |
2449 | 64.3M | s.distance_code = fast!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]); |
2450 | | // goto postReadDistance |
2451 | | } else { |
2452 | 158M | if fast!((s.block_type_length_state.block_length)[2]) == 0 { |
2453 | 457k | mark_unlikely(); |
2454 | 457k | if (!DecodeDistanceBlockSwitchInternal(safe, s, input)) && safe { |
2455 | 42.2k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2456 | 42.2k | break; // return |
2457 | 415k | } |
2458 | 157M | } |
2459 | 158M | if (!ReadDistanceInternal(safe, s, input, &distance_hgroup)) && safe { |
2460 | 81.3k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2461 | 81.3k | break; // return |
2462 | 158M | } |
2463 | | } |
2464 | | // postReadDistance: |
2465 | | BROTLI_LOG!("[ProcessCommandsInternal] pos = %d distance = %d\n", |
2466 | | pos, s.distance_code); |
2467 | | |
2468 | 222M | if (s.max_distance != s.max_backward_distance) { |
2469 | 47.5M | if (pos < s.max_backward_distance_minus_custom_dict_size) { |
2470 | 47.5M | s.max_distance = pos + s.custom_dict_size as i32; |
2471 | 47.5M | } else { |
2472 | 1.96k | s.max_distance = s.max_backward_distance; |
2473 | 1.96k | } |
2474 | 175M | } |
2475 | 222M | i = s.copy_length; |
2476 | | // Apply copy of LZ77 back-reference, or static dictionary reference if |
2477 | | // the distance is larger than the max LZ77 distance |
2478 | 222M | if (s.distance_code > s.max_distance) { |
2479 | 27.6M | if s.distance_code > kBrotliMaxAllowedDistance as i32 { |
2480 | 4.89k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_DISTANCE; |
2481 | 27.6M | } |
2482 | 27.6M | if (i >= kBrotliMinDictionaryWordLength as i32 && |
2483 | 27.6M | i <= kBrotliMaxDictionaryWordLength as i32) { |
2484 | 27.6M | let mut offset = fast!((kBrotliDictionaryOffsetsByLength)[i as usize]) as i32; |
2485 | 27.6M | let word_id = s.distance_code - s.max_distance - 1; |
2486 | 27.6M | let shift = fast!((kBrotliDictionarySizeBitsByLength)[i as usize]); |
2487 | 27.6M | let mask = bit_reader::BitMask(shift as u32) as i32; |
2488 | 27.6M | let word_idx = word_id & mask; |
2489 | 27.6M | let transform_idx = word_id >> shift; |
2490 | 27.6M | s.dist_rb_idx += s.distance_context; |
2491 | 27.6M | offset += word_idx * i; |
2492 | 27.6M | if (transform_idx < kNumTransforms) { |
2493 | 27.6M | let mut len = i; |
2494 | 27.6M | let word = fast!((kBrotliDictionary)[offset as usize ; (offset + len) as usize]); |
2495 | 27.6M | if (transform_idx == 0) { |
2496 | 27.2M | fast_slice_mut!((s.ringbuffer)[pos as usize ; ((pos + len) as usize)]) |
2497 | 27.2M | .clone_from_slice(word); |
2498 | 27.2M | } else { |
2499 | 406k | len = TransformDictionaryWord(fast_slice_mut!((s.ringbuffer)[pos as usize;]), |
2500 | 406k | word, |
2501 | 406k | len, |
2502 | 406k | transform_idx); |
2503 | 406k | } |
2504 | 27.6M | pos += len; |
2505 | 27.6M | s.meta_block_remaining_len -= len; |
2506 | 27.6M | if (pos >= s.ringbuffer_size) { |
2507 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; |
2508 | 140k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1; |
2509 | 140k | break; // return return |
2510 | 27.5M | } |
2511 | | } else { |
2512 | | BROTLI_LOG!( |
2513 | | "Invalid backward reference. pos: %d distance: %d len: %d bytes left: %d\n", |
2514 | | pos, s.distance_code, i, |
2515 | | s.meta_block_remaining_len); |
2516 | 1.39k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_TRANSFORM; |
2517 | 1.39k | break; // return |
2518 | | } |
2519 | | } else { |
2520 | | BROTLI_LOG!( |
2521 | | "Invalid backward reference. pos:%d distance:%d len:%d bytes left:%d\n", |
2522 | | pos, s.distance_code, i, s.meta_block_remaining_len); |
2523 | 3.65k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_DICTIONARY; |
2524 | 3.65k | break; // return |
2525 | | } |
2526 | | } else { |
2527 | | // update the recent distances cache |
2528 | 194M | fast_mut!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]) = s.distance_code; |
2529 | 194M | s.dist_rb_idx += 1; |
2530 | 194M | s.meta_block_remaining_len -= i; |
2531 | | // There is 128+ bytes of slack in the ringbuffer allocation. |
2532 | | // Also, we have 16 short codes, that make these 16 bytes irrelevant |
2533 | | // in the ringbuffer. Let's copy over them as a first guess. |
2534 | | // |
2535 | 194M | let src_start = ((pos - s.distance_code) & s.ringbuffer_mask) as u32; |
2536 | 194M | let dst_start = pos as u32; |
2537 | 194M | let dst_end = pos as u32 + i as u32; |
2538 | 194M | let src_end = src_start + i as u32; |
2539 | 194M | memmove16(&mut s.ringbuffer.slice_mut(), dst_start, src_start); |
2540 | | // Now check if the copy extends over the ringbuffer end, |
2541 | | // or if the copy overlaps with itself, if yes, do wrap-copy. |
2542 | 194M | if (src_end > pos as u32 && dst_end > src_start) { |
2543 | 81.8M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; |
2544 | 81.8M | continue; //goto CommandPostWrapCopy; |
2545 | 113M | } |
2546 | 113M | if (dst_end >= s.ringbuffer_size as u32 || src_end >= s.ringbuffer_size as u32) { |
2547 | 121k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; |
2548 | 121k | continue; //goto CommandPostWrapCopy; |
2549 | 112M | } |
2550 | 112M | pos += i; |
2551 | 112M | if (i > 16) { |
2552 | 1.78M | if (i > 32) { |
2553 | 1.48M | memcpy_within_slice(s.ringbuffer.slice_mut(), |
2554 | 1.48M | dst_start as usize + 16, |
2555 | 1.48M | src_start as usize + 16, |
2556 | 1.48M | (i - 16) as usize); |
2557 | 1.48M | } else { |
2558 | 304k | // This branch covers about 45% cases. |
2559 | 304k | // Fixed size short copy allows more compiler optimizations. |
2560 | 304k | memmove16(&mut s.ringbuffer.slice_mut(), |
2561 | 304k | dst_start + 16, |
2562 | 304k | src_start + 16); |
2563 | 304k | } |
2564 | 111M | } |
2565 | | } |
2566 | 140M | if (s.meta_block_remaining_len <= 0) { |
2567 | | // Next metablock, if any |
2568 | 1.40k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; |
2569 | 1.40k | break; // return |
2570 | | } else { |
2571 | 140M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; |
2572 | 140M | continue; // goto CommandBegin |
2573 | | } |
2574 | | } |
2575 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY => { |
2576 | 82.1M | let mut wrap_guard = s.ringbuffer_size - pos; |
2577 | 82.1M | let mut inner_return: bool = false; |
2578 | 6.27G | while i > 0 { |
2579 | 6.18G | i -= 1; |
2580 | 6.18G | fast_slice_mut!((s.ringbuffer)[pos as usize]) = |
2581 | 6.18G | fast_slice!((s.ringbuffer)[((pos - s.distance_code) & s.ringbuffer_mask) as usize]); |
2582 | 6.18G | pos += 1; |
2583 | 6.18G | wrap_guard -= 1; |
2584 | 6.18G | if (wrap_guard == 0) { |
2585 | 115k | mark_unlikely(); |
2586 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; |
2587 | 115k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2; |
2588 | 115k | inner_return = true; |
2589 | 115k | break; //return |
2590 | 6.18G | } |
2591 | | } |
2592 | 82.1M | if inner_return { |
2593 | 115k | mark_unlikely(); |
2594 | 115k | break; |
2595 | 81.9M | } |
2596 | 81.9M | i -= 1; |
2597 | 81.9M | if (s.meta_block_remaining_len <= 0) { |
2598 | | // Next metablock, if any |
2599 | 4.77k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; |
2600 | 4.77k | break; // return |
2601 | | } else { |
2602 | 81.9M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; |
2603 | 81.9M | continue; |
2604 | | } |
2605 | | } |
2606 | | _ => { |
2607 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; |
2608 | 0 | break; // return |
2609 | | } |
2610 | | } |
2611 | | } |
2612 | | } |
2613 | 834k | s.pos = pos; |
2614 | 834k | s.loop_counter = i; |
2615 | | |
2616 | 834k | let _ = core::mem::replace(&mut s.literal_hgroup, |
2617 | 834k | core::mem::replace(&mut saved_literal_hgroup, |
2618 | 834k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); |
2619 | | |
2620 | 834k | let _ = core::mem::replace(&mut s.distance_hgroup, |
2621 | 834k | core::mem::replace(&mut saved_distance_hgroup, |
2622 | 834k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); |
2623 | | |
2624 | 834k | let _ = core::mem::replace(&mut s.insert_copy_hgroup, |
2625 | 834k | core::mem::replace(&mut saved_insert_copy_hgroup, |
2626 | 834k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); |
2627 | | |
2628 | 834k | result |
2629 | 1.44M | } brotli_decompressor::decode::ProcessCommandsInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2215 | 1.12M | fn ProcessCommandsInternal<AllocU8: alloc::Allocator<u8>, | 2216 | 1.12M | AllocU32: alloc::Allocator<u32>, | 2217 | 1.12M | AllocHC: alloc::Allocator<HuffmanCode>> | 2218 | 1.12M | (safe: bool, | 2219 | 1.12M | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2220 | 1.12M | input: &[u8]) | 2221 | 1.12M | -> BrotliDecoderErrorCode { | 2222 | 1.12M | if (!CheckInputAmount(safe, &s.br, 28)) || (!WarmupBitReader(safe, &mut s.br, input)) { | 2223 | 472k | mark_unlikely(); | 2224 | 472k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2225 | 654k | } | 2226 | 654k | let mut pos = s.pos; | 2227 | 654k | let mut i: i32 = s.loop_counter; // important that this is signed | 2228 | 654k | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2229 | 654k | let mut saved_literal_hgroup = | 2230 | 654k | core::mem::replace(&mut s.literal_hgroup, | 2231 | 654k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); | 2232 | 654k | let mut saved_distance_hgroup = | 2233 | 654k | core::mem::replace(&mut s.distance_hgroup, | 2234 | 654k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); | 2235 | 654k | let mut saved_insert_copy_hgroup = | 2236 | 654k | core::mem::replace(&mut s.insert_copy_hgroup, | 2237 | 654k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); | 2238 | | { | 2239 | | | 2240 | 654k | let literal_hgroup = saved_literal_hgroup.build_hgroup_cache(); | 2241 | 654k | let distance_hgroup = saved_distance_hgroup.build_hgroup_cache(); | 2242 | 654k | let insert_copy_hgroup = saved_insert_copy_hgroup.build_hgroup_cache(); | 2243 | | | 2244 | | loop { | 2245 | 334M | match s.state { | 2246 | | BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN => { | 2247 | 138M | if (!CheckInputAmount(safe, &s.br, 28)) { | 2248 | | // 156 bits + 7 bytes | 2249 | 24.2k | mark_unlikely(); | 2250 | 24.2k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2251 | 24.2k | break; // return | 2252 | 138M | } | 2253 | 138M | if (fast_mut!((s.block_type_length_state.block_length)[1]) == 0) { | 2254 | 27.7k | mark_unlikely(); | 2255 | 27.7k | if !DecodeCommandBlockSwitchInternal(safe, s, input) { | 2256 | 342 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2257 | 342 | break; // return | 2258 | 27.3k | } | 2259 | 27.3k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 2260 | 27.3k | continue; // goto CommandBegin; | 2261 | 138M | } | 2262 | | // Read the insert/copy length in the command | 2263 | 138M | if (!ReadCommandInternal(safe, s, &mut i, input, &insert_copy_hgroup)) && safe { | 2264 | 90.4k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2265 | 90.4k | break; // return | 2266 | 138M | } | 2267 | | BROTLI_LOG!("[ProcessCommandsInternal] pos = %d insert = %d copy = %d distance = %d\n", | 2268 | | pos, i, s.copy_length, s.distance_code); | 2269 | 138M | if (i == 0) { | 2270 | 123M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; | 2271 | 123M | continue; // goto CommandPostDecodeLiterals; | 2272 | 15.1M | } | 2273 | 15.1M | s.meta_block_remaining_len -= i; | 2274 | 15.1M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2275 | | } | 2276 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER => { | 2277 | | // Read the literals in the command | 2278 | 15.3M | if (s.trivial_literal_context != 0) { | 2279 | 13.8M | let mut bits: u32 = 0; | 2280 | 13.8M | let mut value: u32 = 0; | 2281 | 13.8M | let mut literal_htree = &fast!((literal_hgroup)[s.literal_htree_index as usize]); | 2282 | 13.8M | PreloadSymbol(safe, literal_htree, &mut s.br, &mut bits, &mut value, input); | 2283 | 13.8M | let mut inner_return: bool = false; | 2284 | 13.8M | let mut inner_continue: bool = false; | 2285 | | loop { | 2286 | 1.36G | if (!CheckInputAmount(safe, &s.br, 28)) { | 2287 | | // 162 bits + 7 bytes | 2288 | 9.55k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2289 | 9.55k | inner_return = true; | 2290 | 9.55k | break; | 2291 | 1.36G | } | 2292 | 1.36G | if (fast!((s.block_type_length_state.block_length)[0]) == 0) { | 2293 | 392k | mark_unlikely(); | 2294 | 392k | if (!DecodeLiteralBlockSwitchInternal(safe, s, input)) && safe { | 2295 | 9.84k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2296 | 9.84k | inner_return = true; | 2297 | 9.84k | break; | 2298 | 382k | } | 2299 | 382k | literal_htree = fast_ref!((literal_hgroup)[s.literal_htree_index as usize]); | 2300 | 382k | PreloadSymbol(safe, literal_htree, &mut s.br, &mut bits, &mut value, input); | 2301 | 382k | if (s.trivial_literal_context == 0) { | 2302 | 3.87k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2303 | 3.87k | inner_continue = true; | 2304 | 3.87k | break; // goto StateCommandInner | 2305 | 378k | } | 2306 | 1.36G | } | 2307 | 1.36G | if (!safe) { | 2308 | 216M | fast_mut!((s.ringbuffer.slice_mut())[pos as usize]) = | 2309 | 216M | ReadPreloadedSymbol(literal_htree, &mut s.br, &mut bits, &mut value, input) as u8; | 2310 | 216M | } else { | 2311 | 1.14G | let mut literal: u32 = 0; | 2312 | 1.14G | if (!SafeReadSymbol(literal_htree, &mut s.br, &mut literal, input)) { | 2313 | 23.9k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2314 | 23.9k | inner_return = true; | 2315 | 23.9k | break; | 2316 | 1.14G | } | 2317 | 1.14G | fast_mut!((s.ringbuffer.slice_mut())[pos as usize]) = literal as u8; | 2318 | | } | 2319 | 1.36G | if (s.block_type_length_state.block_length)[0] == 0 { | 2320 | 2 | mark_unlikely(); | 2321 | 2 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; | 2322 | 2 | inner_return = true; | 2323 | 2 | break; | 2324 | 1.36G | } | 2325 | 1.36G | fast_mut!((s.block_type_length_state.block_length)[0]) -= 1; | 2326 | | BROTLI_LOG_UINT!(s.literal_htree_index); | 2327 | | BROTLI_LOG_ARRAY_INDEX!(s.ringbuffer.slice(), pos); | 2328 | 1.36G | pos += 1; | 2329 | 1.36G | if (pos == s.ringbuffer_size) { | 2330 | 63.0k | mark_unlikely(); | 2331 | 63.0k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE; | 2332 | 63.0k | i -= 1; | 2333 | 63.0k | inner_return = true; | 2334 | 63.0k | break; | 2335 | 1.36G | } | 2336 | 1.36G | i -= 1; | 2337 | 1.36G | if i == 0 { | 2338 | 13.7M | break; | 2339 | 1.34G | } | 2340 | | } | 2341 | 13.8M | if inner_return { | 2342 | 106k | break; // return | 2343 | 13.7M | } | 2344 | 13.7M | if inner_continue { | 2345 | 3.87k | mark_unlikely(); | 2346 | 3.87k | continue; | 2347 | 13.7M | } | 2348 | | } else { | 2349 | 1.57M | let mut p1 = fast_slice!((s.ringbuffer)[((pos - 1) & s.ringbuffer_mask) as usize]); | 2350 | 1.57M | let mut p2 = fast_slice!((s.ringbuffer)[((pos - 2) & s.ringbuffer_mask) as usize]); | 2351 | 1.57M | if s.custom_dict_avoid_context_seed && pos < 2 { | 2352 | 0 | mark_unlikely(); | 2353 | 0 | p2 = 0; | 2354 | 0 | p1 = 0; | 2355 | 1.57M | } | 2356 | 1.57M | if pos > 1 | 2357 | 1.57M | { | 2358 | 1.57M | // have already set both seed bytes and can now move on to using | 2359 | 1.57M | // the ringbuffer. | 2360 | 1.57M | s.custom_dict_avoid_context_seed = false; | 2361 | 1.57M | } | 2362 | 1.57M | let mut inner_return: bool = false; | 2363 | 1.57M | let mut inner_continue: bool = false; | 2364 | | loop { | 2365 | 33.7M | if (!CheckInputAmount(safe, &s.br, 28)) { | 2366 | | // 162 bits + 7 bytes | 2367 | 1.05k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2368 | 1.05k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2369 | 1.05k | inner_return = true; | 2370 | 1.05k | break; | 2371 | 33.7M | } | 2372 | 33.7M | if (fast!((s.block_type_length_state.block_length)[0]) == 0) { | 2373 | 940k | mark_unlikely(); | 2374 | 940k | if (!DecodeLiteralBlockSwitchInternal(safe, s, input)) && safe { | 2375 | 11.3k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2376 | 11.3k | inner_return = true; | 2377 | 11.3k | break; | 2378 | 929k | } | 2379 | 929k | if s.trivial_literal_context != 0 { | 2380 | 3.84k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2381 | 3.84k | inner_continue = true; | 2382 | 3.84k | break; | 2383 | 925k | } | 2384 | 32.7M | } | 2385 | 33.7M | let context = s.context_lookup[p1 as usize] | s.context_lookup[p2 as usize |256]; | 2386 | | BROTLI_LOG_UINT!(p1); | 2387 | | BROTLI_LOG_UINT!(p2); | 2388 | | BROTLI_LOG_UINT!(context); | 2389 | | let hc: &[HuffmanCode]; | 2390 | 33.7M | { | 2391 | 33.7M | let i = fast_slice!((s.context_map)[s.context_map_slice_index + context as usize]); | 2392 | 33.7M | hc = fast!((literal_hgroup)[i as usize]); | 2393 | 33.7M | } | 2394 | 33.7M | p2 = p1; | 2395 | 33.7M | if (!safe) { | 2396 | 30.0M | p1 = ReadSymbol(hc, &mut s.br, input) as u8; | 2397 | 30.0M | } else { | 2398 | 3.66M | let mut literal: u32 = 0; | 2399 | 3.66M | if (!SafeReadSymbol(hc, &mut s.br, &mut literal, input)) { | 2400 | 68.6k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2401 | 68.6k | inner_return = true; | 2402 | 68.6k | break; | 2403 | 3.59M | } | 2404 | 3.59M | p1 = literal as u8; | 2405 | | } | 2406 | 33.6M | fast_slice_mut!((s.ringbuffer)[pos as usize]) = p1; | 2407 | 33.6M | if (s.block_type_length_state.block_length)[0] == 0 { | 2408 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; | 2409 | 0 | inner_return = true; | 2410 | 0 | break; | 2411 | 33.6M | } | 2412 | 33.6M | fast_mut!((s.block_type_length_state.block_length)[0]) -= 1; | 2413 | | BROTLI_LOG_UINT!(s.context_map.slice()[s.context_map_slice_index as usize + | 2414 | | context as usize]); | 2415 | | BROTLI_LOG_ARRAY_INDEX!(s.ringbuffer.slice(), pos & s.ringbuffer_mask); | 2416 | 33.6M | pos += 1; | 2417 | 33.6M | if (pos == s.ringbuffer_size) { | 2418 | 6.60k | mark_unlikely(); | 2419 | 6.60k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE; | 2420 | 6.60k | i -= 1; | 2421 | 6.60k | inner_return = true; | 2422 | 6.60k | break; | 2423 | 33.6M | } | 2424 | 33.6M | i -= 1; | 2425 | 33.6M | if i == 0 { | 2426 | 1.48M | break; | 2427 | 32.1M | } | 2428 | | } | 2429 | 1.57M | if inner_return { | 2430 | 87.6k | break; // return | 2431 | 1.49M | } | 2432 | 1.49M | if inner_continue { | 2433 | 3.84k | mark_unlikely(); | 2434 | 3.84k | continue; | 2435 | 1.48M | } | 2436 | | } | 2437 | 15.1M | if (s.meta_block_remaining_len <= 0) { | 2438 | 10.1k | mark_unlikely(); | 2439 | 10.1k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2440 | 10.1k | break; // return | 2441 | 15.1M | } | 2442 | 15.1M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; | 2443 | | } | 2444 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS => { | 2445 | 138M | if s.distance_code >= 0 { | 2446 | 27.3M | let not_distance_code = if s.distance_code != 0 { 0 } else { 1 }; | 2447 | 27.3M | s.distance_context = not_distance_code; | 2448 | 27.3M | s.dist_rb_idx -= 1; | 2449 | 27.3M | s.distance_code = fast!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]); | 2450 | | // goto postReadDistance | 2451 | | } else { | 2452 | 111M | if fast!((s.block_type_length_state.block_length)[2]) == 0 { | 2453 | 143k | mark_unlikely(); | 2454 | 143k | if (!DecodeDistanceBlockSwitchInternal(safe, s, input)) && safe { | 2455 | 25.7k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2456 | 25.7k | break; // return | 2457 | 117k | } | 2458 | 111M | } | 2459 | 111M | if (!ReadDistanceInternal(safe, s, input, &distance_hgroup)) && safe { | 2460 | 59.5k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2461 | 59.5k | break; // return | 2462 | 111M | } | 2463 | | } | 2464 | | // postReadDistance: | 2465 | | BROTLI_LOG!("[ProcessCommandsInternal] pos = %d distance = %d\n", | 2466 | | pos, s.distance_code); | 2467 | | | 2468 | 138M | if (s.max_distance != s.max_backward_distance) { | 2469 | 38.6M | if (pos < s.max_backward_distance_minus_custom_dict_size) { | 2470 | 38.6M | s.max_distance = pos + s.custom_dict_size as i32; | 2471 | 38.6M | } else { | 2472 | 1.16k | s.max_distance = s.max_backward_distance; | 2473 | 1.16k | } | 2474 | 100M | } | 2475 | 138M | i = s.copy_length; | 2476 | | // Apply copy of LZ77 back-reference, or static dictionary reference if | 2477 | | // the distance is larger than the max LZ77 distance | 2478 | 138M | if (s.distance_code > s.max_distance) { | 2479 | 25.6M | if s.distance_code > kBrotliMaxAllowedDistance as i32 { | 2480 | 4.09k | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_DISTANCE; | 2481 | 25.5M | } | 2482 | 25.5M | if (i >= kBrotliMinDictionaryWordLength as i32 && | 2483 | 25.5M | i <= kBrotliMaxDictionaryWordLength as i32) { | 2484 | 25.5M | let mut offset = fast!((kBrotliDictionaryOffsetsByLength)[i as usize]) as i32; | 2485 | 25.5M | let word_id = s.distance_code - s.max_distance - 1; | 2486 | 25.5M | let shift = fast!((kBrotliDictionarySizeBitsByLength)[i as usize]); | 2487 | 25.5M | let mask = bit_reader::BitMask(shift as u32) as i32; | 2488 | 25.5M | let word_idx = word_id & mask; | 2489 | 25.5M | let transform_idx = word_id >> shift; | 2490 | 25.5M | s.dist_rb_idx += s.distance_context; | 2491 | 25.5M | offset += word_idx * i; | 2492 | 25.5M | if (transform_idx < kNumTransforms) { | 2493 | 25.5M | let mut len = i; | 2494 | 25.5M | let word = fast!((kBrotliDictionary)[offset as usize ; (offset + len) as usize]); | 2495 | 25.5M | if (transform_idx == 0) { | 2496 | 25.3M | fast_slice_mut!((s.ringbuffer)[pos as usize ; ((pos + len) as usize)]) | 2497 | 25.3M | .clone_from_slice(word); | 2498 | 25.3M | } else { | 2499 | 292k | len = TransformDictionaryWord(fast_slice_mut!((s.ringbuffer)[pos as usize;]), | 2500 | 292k | word, | 2501 | 292k | len, | 2502 | 292k | transform_idx); | 2503 | 292k | } | 2504 | 25.5M | pos += len; | 2505 | 25.5M | s.meta_block_remaining_len -= len; | 2506 | 25.5M | if (pos >= s.ringbuffer_size) { | 2507 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; | 2508 | 139k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1; | 2509 | 139k | break; // return return | 2510 | 25.4M | } | 2511 | | } else { | 2512 | | BROTLI_LOG!( | 2513 | | "Invalid backward reference. pos: %d distance: %d len: %d bytes left: %d\n", | 2514 | | pos, s.distance_code, i, | 2515 | | s.meta_block_remaining_len); | 2516 | 705 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_TRANSFORM; | 2517 | 705 | break; // return | 2518 | | } | 2519 | | } else { | 2520 | | BROTLI_LOG!( | 2521 | | "Invalid backward reference. pos:%d distance:%d len:%d bytes left:%d\n", | 2522 | | pos, s.distance_code, i, s.meta_block_remaining_len); | 2523 | 1.47k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_DICTIONARY; | 2524 | 1.47k | break; // return | 2525 | | } | 2526 | | } else { | 2527 | | // update the recent distances cache | 2528 | 113M | fast_mut!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]) = s.distance_code; | 2529 | 113M | s.dist_rb_idx += 1; | 2530 | 113M | s.meta_block_remaining_len -= i; | 2531 | | // There is 128+ bytes of slack in the ringbuffer allocation. | 2532 | | // Also, we have 16 short codes, that make these 16 bytes irrelevant | 2533 | | // in the ringbuffer. Let's copy over them as a first guess. | 2534 | | // | 2535 | 113M | let src_start = ((pos - s.distance_code) & s.ringbuffer_mask) as u32; | 2536 | 113M | let dst_start = pos as u32; | 2537 | 113M | let dst_end = pos as u32 + i as u32; | 2538 | 113M | let src_end = src_start + i as u32; | 2539 | 113M | memmove16(&mut s.ringbuffer.slice_mut(), dst_start, src_start); | 2540 | | // Now check if the copy extends over the ringbuffer end, | 2541 | | // or if the copy overlaps with itself, if yes, do wrap-copy. | 2542 | 113M | if (src_end > pos as u32 && dst_end > src_start) { | 2543 | 41.7M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; | 2544 | 41.7M | continue; //goto CommandPostWrapCopy; | 2545 | 71.2M | } | 2546 | 71.2M | if (dst_end >= s.ringbuffer_size as u32 || src_end >= s.ringbuffer_size as u32) { | 2547 | 100k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; | 2548 | 100k | continue; //goto CommandPostWrapCopy; | 2549 | 71.1M | } | 2550 | 71.1M | pos += i; | 2551 | 71.1M | if (i > 16) { | 2552 | 242k | if (i > 32) { | 2553 | 199k | memcpy_within_slice(s.ringbuffer.slice_mut(), | 2554 | 199k | dst_start as usize + 16, | 2555 | 199k | src_start as usize + 16, | 2556 | 199k | (i - 16) as usize); | 2557 | 199k | } else { | 2558 | 42.7k | // This branch covers about 45% cases. | 2559 | 42.7k | // Fixed size short copy allows more compiler optimizations. | 2560 | 42.7k | memmove16(&mut s.ringbuffer.slice_mut(), | 2561 | 42.7k | dst_start + 16, | 2562 | 42.7k | src_start + 16); | 2563 | 42.7k | } | 2564 | 70.9M | } | 2565 | | } | 2566 | 96.6M | if (s.meta_block_remaining_len <= 0) { | 2567 | | // Next metablock, if any | 2568 | 639 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2569 | 639 | break; // return | 2570 | | } else { | 2571 | 96.6M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 2572 | 96.6M | continue; // goto CommandBegin | 2573 | | } | 2574 | | } | 2575 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY => { | 2576 | 41.9M | let mut wrap_guard = s.ringbuffer_size - pos; | 2577 | 41.9M | let mut inner_return: bool = false; | 2578 | 5.16G | while i > 0 { | 2579 | 5.11G | i -= 1; | 2580 | 5.11G | fast_slice_mut!((s.ringbuffer)[pos as usize]) = | 2581 | 5.11G | fast_slice!((s.ringbuffer)[((pos - s.distance_code) & s.ringbuffer_mask) as usize]); | 2582 | 5.11G | pos += 1; | 2583 | 5.11G | wrap_guard -= 1; | 2584 | 5.11G | if (wrap_guard == 0) { | 2585 | 100k | mark_unlikely(); | 2586 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; | 2587 | 100k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2; | 2588 | 100k | inner_return = true; | 2589 | 100k | break; //return | 2590 | 5.11G | } | 2591 | | } | 2592 | 41.9M | if inner_return { | 2593 | 100k | mark_unlikely(); | 2594 | 100k | break; | 2595 | 41.8M | } | 2596 | 41.8M | i -= 1; | 2597 | 41.8M | if (s.meta_block_remaining_len <= 0) { | 2598 | | // Next metablock, if any | 2599 | 3.73k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2600 | 3.73k | break; // return | 2601 | | } else { | 2602 | 41.8M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 2603 | 41.8M | continue; | 2604 | | } | 2605 | | } | 2606 | | _ => { | 2607 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; | 2608 | 0 | break; // return | 2609 | | } | 2610 | | } | 2611 | | } | 2612 | | } | 2613 | 650k | s.pos = pos; | 2614 | 650k | s.loop_counter = i; | 2615 | | | 2616 | 650k | let _ = core::mem::replace(&mut s.literal_hgroup, | 2617 | 650k | core::mem::replace(&mut saved_literal_hgroup, | 2618 | 650k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); | 2619 | | | 2620 | 650k | let _ = core::mem::replace(&mut s.distance_hgroup, | 2621 | 650k | core::mem::replace(&mut saved_distance_hgroup, | 2622 | 650k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); | 2623 | | | 2624 | 650k | let _ = core::mem::replace(&mut s.insert_copy_hgroup, | 2625 | 650k | core::mem::replace(&mut saved_insert_copy_hgroup, | 2626 | 650k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); | 2627 | | | 2628 | 650k | result | 2629 | 1.12M | } |
Unexecuted instantiation: brotli_decompressor::decode::ProcessCommandsInternal::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::ProcessCommandsInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::ProcessCommandsInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2215 | 91.6k | fn ProcessCommandsInternal<AllocU8: alloc::Allocator<u8>, | 2216 | 91.6k | AllocU32: alloc::Allocator<u32>, | 2217 | 91.6k | AllocHC: alloc::Allocator<HuffmanCode>> | 2218 | 91.6k | (safe: bool, | 2219 | 91.6k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2220 | 91.6k | input: &[u8]) | 2221 | 91.6k | -> BrotliDecoderErrorCode { | 2222 | 91.6k | if (!CheckInputAmount(safe, &s.br, 28)) || (!WarmupBitReader(safe, &mut s.br, input)) { | 2223 | 33.2k | mark_unlikely(); | 2224 | 33.2k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2225 | 58.3k | } | 2226 | 58.3k | let mut pos = s.pos; | 2227 | 58.3k | let mut i: i32 = s.loop_counter; // important that this is signed | 2228 | 58.3k | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2229 | 58.3k | let mut saved_literal_hgroup = | 2230 | 58.3k | core::mem::replace(&mut s.literal_hgroup, | 2231 | 58.3k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); | 2232 | 58.3k | let mut saved_distance_hgroup = | 2233 | 58.3k | core::mem::replace(&mut s.distance_hgroup, | 2234 | 58.3k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); | 2235 | 58.3k | let mut saved_insert_copy_hgroup = | 2236 | 58.3k | core::mem::replace(&mut s.insert_copy_hgroup, | 2237 | 58.3k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); | 2238 | | { | 2239 | | | 2240 | 58.3k | let literal_hgroup = saved_literal_hgroup.build_hgroup_cache(); | 2241 | 58.3k | let distance_hgroup = saved_distance_hgroup.build_hgroup_cache(); | 2242 | 58.3k | let insert_copy_hgroup = saved_insert_copy_hgroup.build_hgroup_cache(); | 2243 | | | 2244 | | loop { | 2245 | 50.8M | match s.state { | 2246 | | BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN => { | 2247 | 17.4M | if (!CheckInputAmount(safe, &s.br, 28)) { | 2248 | | // 156 bits + 7 bytes | 2249 | 1.44k | mark_unlikely(); | 2250 | 1.44k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2251 | 1.44k | break; // return | 2252 | 17.4M | } | 2253 | 17.4M | if (fast_mut!((s.block_type_length_state.block_length)[1]) == 0) { | 2254 | 723k | mark_unlikely(); | 2255 | 723k | if !DecodeCommandBlockSwitchInternal(safe, s, input) { | 2256 | 235 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2257 | 235 | break; // return | 2258 | 723k | } | 2259 | 723k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 2260 | 723k | continue; // goto CommandBegin; | 2261 | 16.7M | } | 2262 | | // Read the insert/copy length in the command | 2263 | 16.7M | if (!ReadCommandInternal(safe, s, &mut i, input, &insert_copy_hgroup)) && safe { | 2264 | 12.9k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2265 | 12.9k | break; // return | 2266 | 16.7M | } | 2267 | | BROTLI_LOG!("[ProcessCommandsInternal] pos = %d insert = %d copy = %d distance = %d\n", | 2268 | | pos, i, s.copy_length, s.distance_code); | 2269 | 16.7M | if (i == 0) { | 2270 | 12.3M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; | 2271 | 12.3M | continue; // goto CommandPostDecodeLiterals; | 2272 | 4.42M | } | 2273 | 4.42M | s.meta_block_remaining_len -= i; | 2274 | 4.42M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2275 | | } | 2276 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER => { | 2277 | | // Read the literals in the command | 2278 | 4.45M | if (s.trivial_literal_context != 0) { | 2279 | 2.84M | let mut bits: u32 = 0; | 2280 | 2.84M | let mut value: u32 = 0; | 2281 | 2.84M | let mut literal_htree = &fast!((literal_hgroup)[s.literal_htree_index as usize]); | 2282 | 2.84M | PreloadSymbol(safe, literal_htree, &mut s.br, &mut bits, &mut value, input); | 2283 | 2.84M | let mut inner_return: bool = false; | 2284 | 2.84M | let mut inner_continue: bool = false; | 2285 | | loop { | 2286 | 278M | if (!CheckInputAmount(safe, &s.br, 28)) { | 2287 | | // 162 bits + 7 bytes | 2288 | 4.97k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2289 | 4.97k | inner_return = true; | 2290 | 4.97k | break; | 2291 | 278M | } | 2292 | 278M | if (fast!((s.block_type_length_state.block_length)[0]) == 0) { | 2293 | 8.14M | mark_unlikely(); | 2294 | 8.14M | if (!DecodeLiteralBlockSwitchInternal(safe, s, input)) && safe { | 2295 | 4.51k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2296 | 4.51k | inner_return = true; | 2297 | 4.51k | break; | 2298 | 8.13M | } | 2299 | 8.13M | literal_htree = fast_ref!((literal_hgroup)[s.literal_htree_index as usize]); | 2300 | 8.13M | PreloadSymbol(safe, literal_htree, &mut s.br, &mut bits, &mut value, input); | 2301 | 8.13M | if (s.trivial_literal_context == 0) { | 2302 | 400 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2303 | 400 | inner_continue = true; | 2304 | 400 | break; // goto StateCommandInner | 2305 | 8.13M | } | 2306 | 270M | } | 2307 | 278M | if (!safe) { | 2308 | 78.5M | fast_mut!((s.ringbuffer.slice_mut())[pos as usize]) = | 2309 | 78.5M | ReadPreloadedSymbol(literal_htree, &mut s.br, &mut bits, &mut value, input) as u8; | 2310 | 78.5M | } else { | 2311 | 200M | let mut literal: u32 = 0; | 2312 | 200M | if (!SafeReadSymbol(literal_htree, &mut s.br, &mut literal, input)) { | 2313 | 11.5k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2314 | 11.5k | inner_return = true; | 2315 | 11.5k | break; | 2316 | 200M | } | 2317 | 200M | fast_mut!((s.ringbuffer.slice_mut())[pos as usize]) = literal as u8; | 2318 | | } | 2319 | 278M | if (s.block_type_length_state.block_length)[0] == 0 { | 2320 | 0 | mark_unlikely(); | 2321 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; | 2322 | 0 | inner_return = true; | 2323 | 0 | break; | 2324 | 278M | } | 2325 | 278M | fast_mut!((s.block_type_length_state.block_length)[0]) -= 1; | 2326 | | BROTLI_LOG_UINT!(s.literal_htree_index); | 2327 | | BROTLI_LOG_ARRAY_INDEX!(s.ringbuffer.slice(), pos); | 2328 | 278M | pos += 1; | 2329 | 278M | if (pos == s.ringbuffer_size) { | 2330 | 340 | mark_unlikely(); | 2331 | 340 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE; | 2332 | 340 | i -= 1; | 2333 | 340 | inner_return = true; | 2334 | 340 | break; | 2335 | 278M | } | 2336 | 278M | i -= 1; | 2337 | 278M | if i == 0 { | 2338 | 2.82M | break; | 2339 | 276M | } | 2340 | | } | 2341 | 2.84M | if inner_return { | 2342 | 21.4k | break; // return | 2343 | 2.82M | } | 2344 | 2.82M | if inner_continue { | 2345 | 400 | mark_unlikely(); | 2346 | 400 | continue; | 2347 | 2.82M | } | 2348 | | } else { | 2349 | 1.60M | let mut p1 = fast_slice!((s.ringbuffer)[((pos - 1) & s.ringbuffer_mask) as usize]); | 2350 | 1.60M | let mut p2 = fast_slice!((s.ringbuffer)[((pos - 2) & s.ringbuffer_mask) as usize]); | 2351 | 1.60M | if s.custom_dict_avoid_context_seed && pos < 2 { | 2352 | 0 | mark_unlikely(); | 2353 | 0 | p2 = 0; | 2354 | 0 | p1 = 0; | 2355 | 1.60M | } | 2356 | 1.60M | if pos > 1 | 2357 | 1.60M | { | 2358 | 1.60M | // have already set both seed bytes and can now move on to using | 2359 | 1.60M | // the ringbuffer. | 2360 | 1.60M | s.custom_dict_avoid_context_seed = false; | 2361 | 1.60M | } | 2362 | 1.60M | let mut inner_return: bool = false; | 2363 | 1.60M | let mut inner_continue: bool = false; | 2364 | | loop { | 2365 | 156M | if (!CheckInputAmount(safe, &s.br, 28)) { | 2366 | | // 162 bits + 7 bytes | 2367 | 2.22k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2368 | 2.22k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2369 | 2.22k | inner_return = true; | 2370 | 2.22k | break; | 2371 | 156M | } | 2372 | 156M | if (fast!((s.block_type_length_state.block_length)[0]) == 0) { | 2373 | 59.3k | mark_unlikely(); | 2374 | 59.3k | if (!DecodeLiteralBlockSwitchInternal(safe, s, input)) && safe { | 2375 | 263 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2376 | 263 | inner_return = true; | 2377 | 263 | break; | 2378 | 59.1k | } | 2379 | 59.1k | if s.trivial_literal_context != 0 { | 2380 | 405 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2381 | 405 | inner_continue = true; | 2382 | 405 | break; | 2383 | 58.7k | } | 2384 | 156M | } | 2385 | 156M | let context = s.context_lookup[p1 as usize] | s.context_lookup[p2 as usize |256]; | 2386 | | BROTLI_LOG_UINT!(p1); | 2387 | | BROTLI_LOG_UINT!(p2); | 2388 | | BROTLI_LOG_UINT!(context); | 2389 | | let hc: &[HuffmanCode]; | 2390 | 156M | { | 2391 | 156M | let i = fast_slice!((s.context_map)[s.context_map_slice_index + context as usize]); | 2392 | 156M | hc = fast!((literal_hgroup)[i as usize]); | 2393 | 156M | } | 2394 | 156M | p2 = p1; | 2395 | 156M | if (!safe) { | 2396 | 114M | p1 = ReadSymbol(hc, &mut s.br, input) as u8; | 2397 | 114M | } else { | 2398 | 41.3M | let mut literal: u32 = 0; | 2399 | 41.3M | if (!SafeReadSymbol(hc, &mut s.br, &mut literal, input)) { | 2400 | 1.22k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2401 | 1.22k | inner_return = true; | 2402 | 1.22k | break; | 2403 | 41.3M | } | 2404 | 41.3M | p1 = literal as u8; | 2405 | | } | 2406 | 156M | fast_slice_mut!((s.ringbuffer)[pos as usize]) = p1; | 2407 | 156M | if (s.block_type_length_state.block_length)[0] == 0 { | 2408 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; | 2409 | 0 | inner_return = true; | 2410 | 0 | break; | 2411 | 156M | } | 2412 | 156M | fast_mut!((s.block_type_length_state.block_length)[0]) -= 1; | 2413 | | BROTLI_LOG_UINT!(s.context_map.slice()[s.context_map_slice_index as usize + | 2414 | | context as usize]); | 2415 | | BROTLI_LOG_ARRAY_INDEX!(s.ringbuffer.slice(), pos & s.ringbuffer_mask); | 2416 | 156M | pos += 1; | 2417 | 156M | if (pos == s.ringbuffer_size) { | 2418 | 2.34k | mark_unlikely(); | 2419 | 2.34k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE; | 2420 | 2.34k | i -= 1; | 2421 | 2.34k | inner_return = true; | 2422 | 2.34k | break; | 2423 | 156M | } | 2424 | 156M | i -= 1; | 2425 | 156M | if i == 0 { | 2426 | 1.59M | break; | 2427 | 154M | } | 2428 | | } | 2429 | 1.60M | if inner_return { | 2430 | 6.05k | break; // return | 2431 | 1.60M | } | 2432 | 1.60M | if inner_continue { | 2433 | 405 | mark_unlikely(); | 2434 | 405 | continue; | 2435 | 1.59M | } | 2436 | | } | 2437 | 4.42M | if (s.meta_block_remaining_len <= 0) { | 2438 | 784 | mark_unlikely(); | 2439 | 784 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2440 | 784 | break; // return | 2441 | 4.42M | } | 2442 | 4.42M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; | 2443 | | } | 2444 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS => { | 2445 | 16.7M | if s.distance_code >= 0 { | 2446 | 11.7M | let not_distance_code = if s.distance_code != 0 { 0 } else { 1 }; | 2447 | 11.7M | s.distance_context = not_distance_code; | 2448 | 11.7M | s.dist_rb_idx -= 1; | 2449 | 11.7M | s.distance_code = fast!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]); | 2450 | | // goto postReadDistance | 2451 | | } else { | 2452 | 5.00M | if fast!((s.block_type_length_state.block_length)[2]) == 0 { | 2453 | 229k | mark_unlikely(); | 2454 | 229k | if (!DecodeDistanceBlockSwitchInternal(safe, s, input)) && safe { | 2455 | 226 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2456 | 226 | break; // return | 2457 | 229k | } | 2458 | 4.77M | } | 2459 | 5.00M | if (!ReadDistanceInternal(safe, s, input, &distance_hgroup)) && safe { | 2460 | 7.38k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2461 | 7.38k | break; // return | 2462 | 4.99M | } | 2463 | | } | 2464 | | // postReadDistance: | 2465 | | BROTLI_LOG!("[ProcessCommandsInternal] pos = %d distance = %d\n", | 2466 | | pos, s.distance_code); | 2467 | | | 2468 | 16.7M | if (s.max_distance != s.max_backward_distance) { | 2469 | 1.93M | if (pos < s.max_backward_distance_minus_custom_dict_size) { | 2470 | 1.93M | s.max_distance = pos + s.custom_dict_size as i32; | 2471 | 1.93M | } else { | 2472 | 41 | s.max_distance = s.max_backward_distance; | 2473 | 41 | } | 2474 | 14.7M | } | 2475 | 16.7M | i = s.copy_length; | 2476 | | // Apply copy of LZ77 back-reference, or static dictionary reference if | 2477 | | // the distance is larger than the max LZ77 distance | 2478 | 16.7M | if (s.distance_code > s.max_distance) { | 2479 | 78.4k | if s.distance_code > kBrotliMaxAllowedDistance as i32 { | 2480 | 233 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_DISTANCE; | 2481 | 78.2k | } | 2482 | 78.2k | if (i >= kBrotliMinDictionaryWordLength as i32 && | 2483 | 78.1k | i <= kBrotliMaxDictionaryWordLength as i32) { | 2484 | 76.5k | let mut offset = fast!((kBrotliDictionaryOffsetsByLength)[i as usize]) as i32; | 2485 | 76.5k | let word_id = s.distance_code - s.max_distance - 1; | 2486 | 76.5k | let shift = fast!((kBrotliDictionarySizeBitsByLength)[i as usize]); | 2487 | 76.5k | let mask = bit_reader::BitMask(shift as u32) as i32; | 2488 | 76.5k | let word_idx = word_id & mask; | 2489 | 76.5k | let transform_idx = word_id >> shift; | 2490 | 76.5k | s.dist_rb_idx += s.distance_context; | 2491 | 76.5k | offset += word_idx * i; | 2492 | 76.5k | if (transform_idx < kNumTransforms) { | 2493 | 76.1k | let mut len = i; | 2494 | 76.1k | let word = fast!((kBrotliDictionary)[offset as usize ; (offset + len) as usize]); | 2495 | 76.1k | if (transform_idx == 0) { | 2496 | 7.20k | fast_slice_mut!((s.ringbuffer)[pos as usize ; ((pos + len) as usize)]) | 2497 | 7.20k | .clone_from_slice(word); | 2498 | 68.9k | } else { | 2499 | 68.9k | len = TransformDictionaryWord(fast_slice_mut!((s.ringbuffer)[pos as usize;]), | 2500 | 68.9k | word, | 2501 | 68.9k | len, | 2502 | 68.9k | transform_idx); | 2503 | 68.9k | } | 2504 | 76.1k | pos += len; | 2505 | 76.1k | s.meta_block_remaining_len -= len; | 2506 | 76.1k | if (pos >= s.ringbuffer_size) { | 2507 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; | 2508 | 0 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1; | 2509 | 0 | break; // return return | 2510 | 76.1k | } | 2511 | | } else { | 2512 | | BROTLI_LOG!( | 2513 | | "Invalid backward reference. pos: %d distance: %d len: %d bytes left: %d\n", | 2514 | | pos, s.distance_code, i, | 2515 | | s.meta_block_remaining_len); | 2516 | 397 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_TRANSFORM; | 2517 | 397 | break; // return | 2518 | | } | 2519 | | } else { | 2520 | | BROTLI_LOG!( | 2521 | | "Invalid backward reference. pos:%d distance:%d len:%d bytes left:%d\n", | 2522 | | pos, s.distance_code, i, s.meta_block_remaining_len); | 2523 | 1.65k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_DICTIONARY; | 2524 | 1.65k | break; // return | 2525 | | } | 2526 | | } else { | 2527 | | // update the recent distances cache | 2528 | 16.6M | fast_mut!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]) = s.distance_code; | 2529 | 16.6M | s.dist_rb_idx += 1; | 2530 | 16.6M | s.meta_block_remaining_len -= i; | 2531 | | // There is 128+ bytes of slack in the ringbuffer allocation. | 2532 | | // Also, we have 16 short codes, that make these 16 bytes irrelevant | 2533 | | // in the ringbuffer. Let's copy over them as a first guess. | 2534 | | // | 2535 | 16.6M | let src_start = ((pos - s.distance_code) & s.ringbuffer_mask) as u32; | 2536 | 16.6M | let dst_start = pos as u32; | 2537 | 16.6M | let dst_end = pos as u32 + i as u32; | 2538 | 16.6M | let src_end = src_start + i as u32; | 2539 | 16.6M | memmove16(&mut s.ringbuffer.slice_mut(), dst_start, src_start); | 2540 | | // Now check if the copy extends over the ringbuffer end, | 2541 | | // or if the copy overlaps with itself, if yes, do wrap-copy. | 2542 | 16.6M | if (src_end > pos as u32 && dst_end > src_start) { | 2543 | 12.1M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; | 2544 | 12.1M | continue; //goto CommandPostWrapCopy; | 2545 | 4.50M | } | 2546 | 4.50M | if (dst_end >= s.ringbuffer_size as u32 || src_end >= s.ringbuffer_size as u32) { | 2547 | 7.42k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; | 2548 | 7.42k | continue; //goto CommandPostWrapCopy; | 2549 | 4.50M | } | 2550 | 4.50M | pos += i; | 2551 | 4.50M | if (i > 16) { | 2552 | 1.47M | if (i > 32) { | 2553 | 1.27M | memcpy_within_slice(s.ringbuffer.slice_mut(), | 2554 | 1.27M | dst_start as usize + 16, | 2555 | 1.27M | src_start as usize + 16, | 2556 | 1.27M | (i - 16) as usize); | 2557 | 1.27M | } else { | 2558 | 205k | // This branch covers about 45% cases. | 2559 | 205k | // Fixed size short copy allows more compiler optimizations. | 2560 | 205k | memmove16(&mut s.ringbuffer.slice_mut(), | 2561 | 205k | dst_start + 16, | 2562 | 205k | src_start + 16); | 2563 | 205k | } | 2564 | 3.02M | } | 2565 | | } | 2566 | 4.57M | if (s.meta_block_remaining_len <= 0) { | 2567 | | // Next metablock, if any | 2568 | 151 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2569 | 151 | break; // return | 2570 | | } else { | 2571 | 4.57M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 2572 | 4.57M | continue; // goto CommandBegin | 2573 | | } | 2574 | | } | 2575 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY => { | 2576 | 12.1M | let mut wrap_guard = s.ringbuffer_size - pos; | 2577 | 12.1M | let mut inner_return: bool = false; | 2578 | 299M | while i > 0 { | 2579 | 287M | i -= 1; | 2580 | 287M | fast_slice_mut!((s.ringbuffer)[pos as usize]) = | 2581 | 287M | fast_slice!((s.ringbuffer)[((pos - s.distance_code) & s.ringbuffer_mask) as usize]); | 2582 | 287M | pos += 1; | 2583 | 287M | wrap_guard -= 1; | 2584 | 287M | if (wrap_guard == 0) { | 2585 | 5.18k | mark_unlikely(); | 2586 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; | 2587 | 5.18k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2; | 2588 | 5.18k | inner_return = true; | 2589 | 5.18k | break; //return | 2590 | 287M | } | 2591 | | } | 2592 | 12.1M | if inner_return { | 2593 | 5.18k | mark_unlikely(); | 2594 | 5.18k | break; | 2595 | 12.1M | } | 2596 | 12.1M | i -= 1; | 2597 | 12.1M | if (s.meta_block_remaining_len <= 0) { | 2598 | | // Next metablock, if any | 2599 | 194 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2600 | 194 | break; // return | 2601 | | } else { | 2602 | 12.1M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 2603 | 12.1M | continue; | 2604 | | } | 2605 | | } | 2606 | | _ => { | 2607 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; | 2608 | 0 | break; // return | 2609 | | } | 2610 | | } | 2611 | | } | 2612 | | } | 2613 | 58.1k | s.pos = pos; | 2614 | 58.1k | s.loop_counter = i; | 2615 | | | 2616 | 58.1k | let _ = core::mem::replace(&mut s.literal_hgroup, | 2617 | 58.1k | core::mem::replace(&mut saved_literal_hgroup, | 2618 | 58.1k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); | 2619 | | | 2620 | 58.1k | let _ = core::mem::replace(&mut s.distance_hgroup, | 2621 | 58.1k | core::mem::replace(&mut saved_distance_hgroup, | 2622 | 58.1k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); | 2623 | | | 2624 | 58.1k | let _ = core::mem::replace(&mut s.insert_copy_hgroup, | 2625 | 58.1k | core::mem::replace(&mut saved_insert_copy_hgroup, | 2626 | 58.1k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); | 2627 | | | 2628 | 58.1k | result | 2629 | 91.6k | } |
brotli_decompressor::decode::ProcessCommandsInternal::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2215 | 226k | fn ProcessCommandsInternal<AllocU8: alloc::Allocator<u8>, | 2216 | 226k | AllocU32: alloc::Allocator<u32>, | 2217 | 226k | AllocHC: alloc::Allocator<HuffmanCode>> | 2218 | 226k | (safe: bool, | 2219 | 226k | s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2220 | 226k | input: &[u8]) | 2221 | 226k | -> BrotliDecoderErrorCode { | 2222 | 226k | if (!CheckInputAmount(safe, &s.br, 28)) || (!WarmupBitReader(safe, &mut s.br, input)) { | 2223 | 100k | mark_unlikely(); | 2224 | 100k | return BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2225 | 125k | } | 2226 | 125k | let mut pos = s.pos; | 2227 | 125k | let mut i: i32 = s.loop_counter; // important that this is signed | 2228 | 125k | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2229 | 125k | let mut saved_literal_hgroup = | 2230 | 125k | core::mem::replace(&mut s.literal_hgroup, | 2231 | 125k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); | 2232 | 125k | let mut saved_distance_hgroup = | 2233 | 125k | core::mem::replace(&mut s.distance_hgroup, | 2234 | 125k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); | 2235 | 125k | let mut saved_insert_copy_hgroup = | 2236 | 125k | core::mem::replace(&mut s.insert_copy_hgroup, | 2237 | 125k | HuffmanTreeGroup::<AllocU32, AllocHC>::default()); | 2238 | | { | 2239 | | | 2240 | 125k | let literal_hgroup = saved_literal_hgroup.build_hgroup_cache(); | 2241 | 125k | let distance_hgroup = saved_distance_hgroup.build_hgroup_cache(); | 2242 | 125k | let insert_copy_hgroup = saved_insert_copy_hgroup.build_hgroup_cache(); | 2243 | | | 2244 | | loop { | 2245 | 178M | match s.state { | 2246 | | BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN => { | 2247 | 67.2M | if (!CheckInputAmount(safe, &s.br, 28)) { | 2248 | | // 156 bits + 7 bytes | 2249 | 1.95k | mark_unlikely(); | 2250 | 1.95k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2251 | 1.95k | break; // return | 2252 | 67.2M | } | 2253 | 67.2M | if (fast_mut!((s.block_type_length_state.block_length)[1]) == 0) { | 2254 | 833 | mark_unlikely(); | 2255 | 833 | if !DecodeCommandBlockSwitchInternal(safe, s, input) { | 2256 | 87 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2257 | 87 | break; // return | 2258 | 746 | } | 2259 | 746 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 2260 | 746 | continue; // goto CommandBegin; | 2261 | 67.2M | } | 2262 | | // Read the insert/copy length in the command | 2263 | 67.2M | if (!ReadCommandInternal(safe, s, &mut i, input, &insert_copy_hgroup)) && safe { | 2264 | 49.2k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2265 | 49.2k | break; // return | 2266 | 67.1M | } | 2267 | | BROTLI_LOG!("[ProcessCommandsInternal] pos = %d insert = %d copy = %d distance = %d\n", | 2268 | | pos, i, s.copy_length, s.distance_code); | 2269 | 67.1M | if (i == 0) { | 2270 | 51.3M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; | 2271 | 51.3M | continue; // goto CommandPostDecodeLiterals; | 2272 | 15.8M | } | 2273 | 15.8M | s.meta_block_remaining_len -= i; | 2274 | 15.8M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2275 | | } | 2276 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER => { | 2277 | | // Read the literals in the command | 2278 | 15.9M | if (s.trivial_literal_context != 0) { | 2279 | 13.8M | let mut bits: u32 = 0; | 2280 | 13.8M | let mut value: u32 = 0; | 2281 | 13.8M | let mut literal_htree = &fast!((literal_hgroup)[s.literal_htree_index as usize]); | 2282 | 13.8M | PreloadSymbol(safe, literal_htree, &mut s.br, &mut bits, &mut value, input); | 2283 | 13.8M | let mut inner_return: bool = false; | 2284 | 13.8M | let mut inner_continue: bool = false; | 2285 | | loop { | 2286 | 740M | if (!CheckInputAmount(safe, &s.br, 28)) { | 2287 | | // 162 bits + 7 bytes | 2288 | 4.66k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2289 | 4.66k | inner_return = true; | 2290 | 4.66k | break; | 2291 | 740M | } | 2292 | 740M | if (fast!((s.block_type_length_state.block_length)[0]) == 0) { | 2293 | 15.3k | mark_unlikely(); | 2294 | 15.3k | if (!DecodeLiteralBlockSwitchInternal(safe, s, input)) && safe { | 2295 | 2.32k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2296 | 2.32k | inner_return = true; | 2297 | 2.32k | break; | 2298 | 13.0k | } | 2299 | 13.0k | literal_htree = fast_ref!((literal_hgroup)[s.literal_htree_index as usize]); | 2300 | 13.0k | PreloadSymbol(safe, literal_htree, &mut s.br, &mut bits, &mut value, input); | 2301 | 13.0k | if (s.trivial_literal_context == 0) { | 2302 | 2.04k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2303 | 2.04k | inner_continue = true; | 2304 | 2.04k | break; // goto StateCommandInner | 2305 | 10.9k | } | 2306 | 740M | } | 2307 | 740M | if (!safe) { | 2308 | 89.5M | fast_mut!((s.ringbuffer.slice_mut())[pos as usize]) = | 2309 | 89.5M | ReadPreloadedSymbol(literal_htree, &mut s.br, &mut bits, &mut value, input) as u8; | 2310 | 89.5M | } else { | 2311 | 650M | let mut literal: u32 = 0; | 2312 | 650M | if (!SafeReadSymbol(literal_htree, &mut s.br, &mut literal, input)) { | 2313 | 9.90k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2314 | 9.90k | inner_return = true; | 2315 | 9.90k | break; | 2316 | 650M | } | 2317 | 650M | fast_mut!((s.ringbuffer.slice_mut())[pos as usize]) = literal as u8; | 2318 | | } | 2319 | 740M | if (s.block_type_length_state.block_length)[0] == 0 { | 2320 | 0 | mark_unlikely(); | 2321 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; | 2322 | 0 | inner_return = true; | 2323 | 0 | break; | 2324 | 740M | } | 2325 | 740M | fast_mut!((s.block_type_length_state.block_length)[0]) -= 1; | 2326 | | BROTLI_LOG_UINT!(s.literal_htree_index); | 2327 | | BROTLI_LOG_ARRAY_INDEX!(s.ringbuffer.slice(), pos); | 2328 | 740M | pos += 1; | 2329 | 740M | if (pos == s.ringbuffer_size) { | 2330 | 5.32k | mark_unlikely(); | 2331 | 5.32k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE; | 2332 | 5.32k | i -= 1; | 2333 | 5.32k | inner_return = true; | 2334 | 5.32k | break; | 2335 | 740M | } | 2336 | 740M | i -= 1; | 2337 | 740M | if i == 0 { | 2338 | 13.8M | break; | 2339 | 726M | } | 2340 | | } | 2341 | 13.8M | if inner_return { | 2342 | 22.2k | break; // return | 2343 | 13.8M | } | 2344 | 13.8M | if inner_continue { | 2345 | 2.04k | mark_unlikely(); | 2346 | 2.04k | continue; | 2347 | 13.8M | } | 2348 | | } else { | 2349 | 2.04M | let mut p1 = fast_slice!((s.ringbuffer)[((pos - 1) & s.ringbuffer_mask) as usize]); | 2350 | 2.04M | let mut p2 = fast_slice!((s.ringbuffer)[((pos - 2) & s.ringbuffer_mask) as usize]); | 2351 | 2.04M | if s.custom_dict_avoid_context_seed && pos < 2 { | 2352 | 0 | mark_unlikely(); | 2353 | 0 | p2 = 0; | 2354 | 0 | p1 = 0; | 2355 | 2.04M | } | 2356 | 2.04M | if pos > 1 | 2357 | 2.04M | { | 2358 | 2.04M | // have already set both seed bytes and can now move on to using | 2359 | 2.04M | // the ringbuffer. | 2360 | 2.04M | s.custom_dict_avoid_context_seed = false; | 2361 | 2.04M | } | 2362 | 2.04M | let mut inner_return: bool = false; | 2363 | 2.04M | let mut inner_continue: bool = false; | 2364 | | loop { | 2365 | 9.68M | if (!CheckInputAmount(safe, &s.br, 28)) { | 2366 | | // 162 bits + 7 bytes | 2367 | 754 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2368 | 754 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2369 | 754 | inner_return = true; | 2370 | 754 | break; | 2371 | 9.68M | } | 2372 | 9.68M | if (fast!((s.block_type_length_state.block_length)[0]) == 0) { | 2373 | 133k | mark_unlikely(); | 2374 | 133k | if (!DecodeLiteralBlockSwitchInternal(safe, s, input)) && safe { | 2375 | 1.31k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2376 | 1.31k | inner_return = true; | 2377 | 1.31k | break; | 2378 | 132k | } | 2379 | 132k | if s.trivial_literal_context != 0 { | 2380 | 2.03k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 2381 | 2.03k | inner_continue = true; | 2382 | 2.03k | break; | 2383 | 130k | } | 2384 | 9.55M | } | 2385 | 9.68M | let context = s.context_lookup[p1 as usize] | s.context_lookup[p2 as usize |256]; | 2386 | | BROTLI_LOG_UINT!(p1); | 2387 | | BROTLI_LOG_UINT!(p2); | 2388 | | BROTLI_LOG_UINT!(context); | 2389 | | let hc: &[HuffmanCode]; | 2390 | 9.68M | { | 2391 | 9.68M | let i = fast_slice!((s.context_map)[s.context_map_slice_index + context as usize]); | 2392 | 9.68M | hc = fast!((literal_hgroup)[i as usize]); | 2393 | 9.68M | } | 2394 | 9.68M | p2 = p1; | 2395 | 9.68M | if (!safe) { | 2396 | 9.03M | p1 = ReadSymbol(hc, &mut s.br, input) as u8; | 2397 | 9.03M | } else { | 2398 | 642k | let mut literal: u32 = 0; | 2399 | 642k | if (!SafeReadSymbol(hc, &mut s.br, &mut literal, input)) { | 2400 | 2.34k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2401 | 2.34k | inner_return = true; | 2402 | 2.34k | break; | 2403 | 640k | } | 2404 | 640k | p1 = literal as u8; | 2405 | | } | 2406 | 9.67M | fast_slice_mut!((s.ringbuffer)[pos as usize]) = p1; | 2407 | 9.67M | if (s.block_type_length_state.block_length)[0] == 0 { | 2408 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; | 2409 | 0 | inner_return = true; | 2410 | 0 | break; | 2411 | 9.67M | } | 2412 | 9.67M | fast_mut!((s.block_type_length_state.block_length)[0]) -= 1; | 2413 | | BROTLI_LOG_UINT!(s.context_map.slice()[s.context_map_slice_index as usize + | 2414 | | context as usize]); | 2415 | | BROTLI_LOG_ARRAY_INDEX!(s.ringbuffer.slice(), pos & s.ringbuffer_mask); | 2416 | 9.67M | pos += 1; | 2417 | 9.67M | if (pos == s.ringbuffer_size) { | 2418 | 147 | mark_unlikely(); | 2419 | 147 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE; | 2420 | 147 | i -= 1; | 2421 | 147 | inner_return = true; | 2422 | 147 | break; | 2423 | 9.67M | } | 2424 | 9.67M | i -= 1; | 2425 | 9.67M | if i == 0 { | 2426 | 2.03M | break; | 2427 | 7.64M | } | 2428 | | } | 2429 | 2.04M | if inner_return { | 2430 | 4.56k | break; // return | 2431 | 2.04M | } | 2432 | 2.04M | if inner_continue { | 2433 | 2.03k | mark_unlikely(); | 2434 | 2.03k | continue; | 2435 | 2.03M | } | 2436 | | } | 2437 | 15.8M | if (s.meta_block_remaining_len <= 0) { | 2438 | 3.20k | mark_unlikely(); | 2439 | 3.20k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2440 | 3.20k | break; // return | 2441 | 15.8M | } | 2442 | 15.8M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; | 2443 | | } | 2444 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS => { | 2445 | 67.2M | if s.distance_code >= 0 { | 2446 | 25.2M | let not_distance_code = if s.distance_code != 0 { 0 } else { 1 }; | 2447 | 25.2M | s.distance_context = not_distance_code; | 2448 | 25.2M | s.dist_rb_idx -= 1; | 2449 | 25.2M | s.distance_code = fast!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]); | 2450 | | // goto postReadDistance | 2451 | | } else { | 2452 | 41.9M | if fast!((s.block_type_length_state.block_length)[2]) == 0 { | 2453 | 85.2k | mark_unlikely(); | 2454 | 85.2k | if (!DecodeDistanceBlockSwitchInternal(safe, s, input)) && safe { | 2455 | 16.1k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2456 | 16.1k | break; // return | 2457 | 69.0k | } | 2458 | 41.8M | } | 2459 | 41.9M | if (!ReadDistanceInternal(safe, s, input, &distance_hgroup)) && safe { | 2460 | 14.3k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2461 | 14.3k | break; // return | 2462 | 41.9M | } | 2463 | | } | 2464 | | // postReadDistance: | 2465 | | BROTLI_LOG!("[ProcessCommandsInternal] pos = %d distance = %d\n", | 2466 | | pos, s.distance_code); | 2467 | | | 2468 | 67.1M | if (s.max_distance != s.max_backward_distance) { | 2469 | 6.97M | if (pos < s.max_backward_distance_minus_custom_dict_size) { | 2470 | 6.97M | s.max_distance = pos + s.custom_dict_size as i32; | 2471 | 6.97M | } else { | 2472 | 761 | s.max_distance = s.max_backward_distance; | 2473 | 761 | } | 2474 | 60.2M | } | 2475 | 67.1M | i = s.copy_length; | 2476 | | // Apply copy of LZ77 back-reference, or static dictionary reference if | 2477 | | // the distance is larger than the max LZ77 distance | 2478 | 67.1M | if (s.distance_code > s.max_distance) { | 2479 | 1.97M | if s.distance_code > kBrotliMaxAllowedDistance as i32 { | 2480 | 572 | return BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_DISTANCE; | 2481 | 1.97M | } | 2482 | 1.97M | if (i >= kBrotliMinDictionaryWordLength as i32 && | 2483 | 1.97M | i <= kBrotliMaxDictionaryWordLength as i32) { | 2484 | 1.97M | let mut offset = fast!((kBrotliDictionaryOffsetsByLength)[i as usize]) as i32; | 2485 | 1.97M | let word_id = s.distance_code - s.max_distance - 1; | 2486 | 1.97M | let shift = fast!((kBrotliDictionarySizeBitsByLength)[i as usize]); | 2487 | 1.97M | let mask = bit_reader::BitMask(shift as u32) as i32; | 2488 | 1.97M | let word_idx = word_id & mask; | 2489 | 1.97M | let transform_idx = word_id >> shift; | 2490 | 1.97M | s.dist_rb_idx += s.distance_context; | 2491 | 1.97M | offset += word_idx * i; | 2492 | 1.97M | if (transform_idx < kNumTransforms) { | 2493 | 1.97M | let mut len = i; | 2494 | 1.97M | let word = fast!((kBrotliDictionary)[offset as usize ; (offset + len) as usize]); | 2495 | 1.97M | if (transform_idx == 0) { | 2496 | 1.93M | fast_slice_mut!((s.ringbuffer)[pos as usize ; ((pos + len) as usize)]) | 2497 | 1.93M | .clone_from_slice(word); | 2498 | 1.93M | } else { | 2499 | 44.6k | len = TransformDictionaryWord(fast_slice_mut!((s.ringbuffer)[pos as usize;]), | 2500 | 44.6k | word, | 2501 | 44.6k | len, | 2502 | 44.6k | transform_idx); | 2503 | 44.6k | } | 2504 | 1.97M | pos += len; | 2505 | 1.97M | s.meta_block_remaining_len -= len; | 2506 | 1.97M | if (pos >= s.ringbuffer_size) { | 2507 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; | 2508 | 690 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1; | 2509 | 690 | break; // return return | 2510 | 1.97M | } | 2511 | | } else { | 2512 | | BROTLI_LOG!( | 2513 | | "Invalid backward reference. pos: %d distance: %d len: %d bytes left: %d\n", | 2514 | | pos, s.distance_code, i, | 2515 | | s.meta_block_remaining_len); | 2516 | 294 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_TRANSFORM; | 2517 | 294 | break; // return | 2518 | | } | 2519 | | } else { | 2520 | | BROTLI_LOG!( | 2521 | | "Invalid backward reference. pos:%d distance:%d len:%d bytes left:%d\n", | 2522 | | pos, s.distance_code, i, s.meta_block_remaining_len); | 2523 | 527 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_DICTIONARY; | 2524 | 527 | break; // return | 2525 | | } | 2526 | | } else { | 2527 | | // update the recent distances cache | 2528 | 65.2M | fast_mut!((s.dist_rb)[(s.dist_rb_idx & 3) as usize]) = s.distance_code; | 2529 | 65.2M | s.dist_rb_idx += 1; | 2530 | 65.2M | s.meta_block_remaining_len -= i; | 2531 | | // There is 128+ bytes of slack in the ringbuffer allocation. | 2532 | | // Also, we have 16 short codes, that make these 16 bytes irrelevant | 2533 | | // in the ringbuffer. Let's copy over them as a first guess. | 2534 | | // | 2535 | 65.2M | let src_start = ((pos - s.distance_code) & s.ringbuffer_mask) as u32; | 2536 | 65.2M | let dst_start = pos as u32; | 2537 | 65.2M | let dst_end = pos as u32 + i as u32; | 2538 | 65.2M | let src_end = src_start + i as u32; | 2539 | 65.2M | memmove16(&mut s.ringbuffer.slice_mut(), dst_start, src_start); | 2540 | | // Now check if the copy extends over the ringbuffer end, | 2541 | | // or if the copy overlaps with itself, if yes, do wrap-copy. | 2542 | 65.2M | if (src_end > pos as u32 && dst_end > src_start) { | 2543 | 27.9M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; | 2544 | 27.9M | continue; //goto CommandPostWrapCopy; | 2545 | 37.2M | } | 2546 | 37.2M | if (dst_end >= s.ringbuffer_size as u32 || src_end >= s.ringbuffer_size as u32) { | 2547 | 13.1k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; | 2548 | 13.1k | continue; //goto CommandPostWrapCopy; | 2549 | 37.2M | } | 2550 | 37.2M | pos += i; | 2551 | 37.2M | if (i > 16) { | 2552 | 66.0k | if (i > 32) { | 2553 | 10.3k | memcpy_within_slice(s.ringbuffer.slice_mut(), | 2554 | 10.3k | dst_start as usize + 16, | 2555 | 10.3k | src_start as usize + 16, | 2556 | 10.3k | (i - 16) as usize); | 2557 | 55.7k | } else { | 2558 | 55.7k | // This branch covers about 45% cases. | 2559 | 55.7k | // Fixed size short copy allows more compiler optimizations. | 2560 | 55.7k | memmove16(&mut s.ringbuffer.slice_mut(), | 2561 | 55.7k | dst_start + 16, | 2562 | 55.7k | src_start + 16); | 2563 | 55.7k | } | 2564 | 37.1M | } | 2565 | | } | 2566 | 39.2M | if (s.meta_block_remaining_len <= 0) { | 2567 | | // Next metablock, if any | 2568 | 615 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2569 | 615 | break; // return | 2570 | | } else { | 2571 | 39.2M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 2572 | 39.2M | continue; // goto CommandBegin | 2573 | | } | 2574 | | } | 2575 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY => { | 2576 | 27.9M | let mut wrap_guard = s.ringbuffer_size - pos; | 2577 | 27.9M | let mut inner_return: bool = false; | 2578 | 810M | while i > 0 { | 2579 | 782M | i -= 1; | 2580 | 782M | fast_slice_mut!((s.ringbuffer)[pos as usize]) = | 2581 | 782M | fast_slice!((s.ringbuffer)[((pos - s.distance_code) & s.ringbuffer_mask) as usize]); | 2582 | 782M | pos += 1; | 2583 | 782M | wrap_guard -= 1; | 2584 | 782M | if (wrap_guard == 0) { | 2585 | 10.5k | mark_unlikely(); | 2586 | | // s.partial_pos_rb += (size_t)s.ringbuffer_size; | 2587 | 10.5k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2; | 2588 | 10.5k | inner_return = true; | 2589 | 10.5k | break; //return | 2590 | 782M | } | 2591 | | } | 2592 | 27.9M | if inner_return { | 2593 | 10.5k | mark_unlikely(); | 2594 | 10.5k | break; | 2595 | 27.9M | } | 2596 | 27.9M | i -= 1; | 2597 | 27.9M | if (s.meta_block_remaining_len <= 0) { | 2598 | | // Next metablock, if any | 2599 | 841 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2600 | 841 | break; // return | 2601 | | } else { | 2602 | 27.9M | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 2603 | 27.9M | continue; | 2604 | | } | 2605 | | } | 2606 | | _ => { | 2607 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE; | 2608 | 0 | break; // return | 2609 | | } | 2610 | | } | 2611 | | } | 2612 | | } | 2613 | 125k | s.pos = pos; | 2614 | 125k | s.loop_counter = i; | 2615 | | | 2616 | 125k | let _ = core::mem::replace(&mut s.literal_hgroup, | 2617 | 125k | core::mem::replace(&mut saved_literal_hgroup, | 2618 | 125k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); | 2619 | | | 2620 | 125k | let _ = core::mem::replace(&mut s.distance_hgroup, | 2621 | 125k | core::mem::replace(&mut saved_distance_hgroup, | 2622 | 125k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); | 2623 | | | 2624 | 125k | let _ = core::mem::replace(&mut s.insert_copy_hgroup, | 2625 | 125k | core::mem::replace(&mut saved_insert_copy_hgroup, | 2626 | 125k | HuffmanTreeGroup::<AllocU32, AllocHC>::default())); | 2627 | | | 2628 | 125k | result | 2629 | 226k | } |
|
2630 | | |
2631 | 788k | fn ProcessCommands<AllocU8: alloc::Allocator<u8>, |
2632 | 788k | AllocU32: alloc::Allocator<u32>, |
2633 | 788k | AllocHC: alloc::Allocator<HuffmanCode>> |
2634 | 788k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
2635 | 788k | input: &[u8]) |
2636 | 788k | -> BrotliDecoderErrorCode { |
2637 | 788k | ProcessCommandsInternal(false, s, input) |
2638 | 788k | } brotli_decompressor::decode::ProcessCommands::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2631 | 620k | fn ProcessCommands<AllocU8: alloc::Allocator<u8>, | 2632 | 620k | AllocU32: alloc::Allocator<u32>, | 2633 | 620k | AllocHC: alloc::Allocator<HuffmanCode>> | 2634 | 620k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2635 | 620k | input: &[u8]) | 2636 | 620k | -> BrotliDecoderErrorCode { | 2637 | 620k | ProcessCommandsInternal(false, s, input) | 2638 | 620k | } |
Unexecuted instantiation: brotli_decompressor::decode::ProcessCommands::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::ProcessCommands::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::ProcessCommands::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2631 | 49.7k | fn ProcessCommands<AllocU8: alloc::Allocator<u8>, | 2632 | 49.7k | AllocU32: alloc::Allocator<u32>, | 2633 | 49.7k | AllocHC: alloc::Allocator<HuffmanCode>> | 2634 | 49.7k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2635 | 49.7k | input: &[u8]) | 2636 | 49.7k | -> BrotliDecoderErrorCode { | 2637 | 49.7k | ProcessCommandsInternal(false, s, input) | 2638 | 49.7k | } |
brotli_decompressor::decode::ProcessCommands::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2631 | 118k | fn ProcessCommands<AllocU8: alloc::Allocator<u8>, | 2632 | 118k | AllocU32: alloc::Allocator<u32>, | 2633 | 118k | AllocHC: alloc::Allocator<HuffmanCode>> | 2634 | 118k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2635 | 118k | input: &[u8]) | 2636 | 118k | -> BrotliDecoderErrorCode { | 2637 | 118k | ProcessCommandsInternal(false, s, input) | 2638 | 118k | } |
|
2639 | | |
2640 | 656k | fn SafeProcessCommands<AllocU8: alloc::Allocator<u8>, |
2641 | 656k | AllocU32: alloc::Allocator<u32>, |
2642 | 656k | AllocHC: alloc::Allocator<HuffmanCode>> |
2643 | 656k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, |
2644 | 656k | input: &[u8]) |
2645 | 656k | -> BrotliDecoderErrorCode { |
2646 | 656k | ProcessCommandsInternal(true, s, input) |
2647 | 656k | } brotli_decompressor::decode::SafeProcessCommands::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2640 | 506k | fn SafeProcessCommands<AllocU8: alloc::Allocator<u8>, | 2641 | 506k | AllocU32: alloc::Allocator<u32>, | 2642 | 506k | AllocHC: alloc::Allocator<HuffmanCode>> | 2643 | 506k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2644 | 506k | input: &[u8]) | 2645 | 506k | -> BrotliDecoderErrorCode { | 2646 | 506k | ProcessCommandsInternal(true, s, input) | 2647 | 506k | } |
Unexecuted instantiation: brotli_decompressor::decode::SafeProcessCommands::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::SafeProcessCommands::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::SafeProcessCommands::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2640 | 41.9k | fn SafeProcessCommands<AllocU8: alloc::Allocator<u8>, | 2641 | 41.9k | AllocU32: alloc::Allocator<u32>, | 2642 | 41.9k | AllocHC: alloc::Allocator<HuffmanCode>> | 2643 | 41.9k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2644 | 41.9k | input: &[u8]) | 2645 | 41.9k | -> BrotliDecoderErrorCode { | 2646 | 41.9k | ProcessCommandsInternal(true, s, input) | 2647 | 41.9k | } |
brotli_decompressor::decode::SafeProcessCommands::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2640 | 107k | fn SafeProcessCommands<AllocU8: alloc::Allocator<u8>, | 2641 | 107k | AllocU32: alloc::Allocator<u32>, | 2642 | 107k | AllocHC: alloc::Allocator<HuffmanCode>> | 2643 | 107k | (s: &mut BrotliState<AllocU8, AllocU32, AllocHC>, | 2644 | 107k | input: &[u8]) | 2645 | 107k | -> BrotliDecoderErrorCode { | 2646 | 107k | ProcessCommandsInternal(true, s, input) | 2647 | 107k | } |
|
2648 | | |
2649 | | /* Returns the maximum number of distance symbols which can only represent |
2650 | | distances not exceeding BROTLI_MAX_ALLOWED_DISTANCE. */ |
2651 | 28.2k | pub fn BrotliMaxDistanceSymbol(ndirect: u32, npostfix: u32) -> u32{ |
2652 | 28.2k | let bound:[u32;kBrotliMaxPostfix + 1] = [0, 4, 12, 28]; |
2653 | 28.2k | let diff:[u32;kBrotliMaxPostfix + 1] = [73, 126, 228, 424]; |
2654 | 28.2k | let postfix = 1 << npostfix; |
2655 | 28.2k | if (ndirect < bound[npostfix as usize ]) { |
2656 | 4.47k | return ndirect + diff[npostfix as usize] + postfix; |
2657 | 23.7k | } else if (ndirect > bound[npostfix as usize] + postfix) { |
2658 | 13.8k | return ndirect + diff[npostfix as usize]; |
2659 | | } else { |
2660 | 9.86k | return bound[npostfix as usize] + diff[npostfix as usize] + postfix; |
2661 | | } |
2662 | 28.2k | } |
2663 | | |
2664 | 2.55M | pub fn BrotliDecompressStream<AllocU8: alloc::Allocator<u8>, |
2665 | 2.55M | AllocU32: alloc::Allocator<u32>, |
2666 | 2.55M | AllocHC: alloc::Allocator<HuffmanCode>> |
2667 | 2.55M | (available_in: &mut usize, |
2668 | 2.55M | input_offset: &mut usize, |
2669 | 2.55M | xinput: &[u8], |
2670 | 2.55M | mut available_out: &mut usize, |
2671 | 2.55M | mut output_offset: &mut usize, |
2672 | 2.55M | mut output: &mut [u8], |
2673 | 2.55M | mut total_out: &mut usize, |
2674 | 2.55M | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) |
2675 | 2.55M | -> BrotliResult { |
2676 | | |
2677 | 2.55M | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
2678 | | |
2679 | 2.55M | let mut saved_buffer: [u8; 8] = s.buffer; |
2680 | | let mut local_input: &[u8]; |
2681 | 2.55M | if is_fatal(s.error_code) { |
2682 | 18.4k | return BrotliResult::ResultFailure; |
2683 | 2.53M | } |
2684 | 2.53M | if *available_in as u64 >= (1u64 << 32) { |
2685 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); |
2686 | 2.53M | } |
2687 | 2.53M | if *input_offset as u64 >= (1u64 << 32) { |
2688 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); |
2689 | 2.53M | } |
2690 | 2.53M | if *input_offset + *available_in > xinput.len() { |
2691 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); |
2692 | 2.53M | } |
2693 | 2.53M | if *output_offset + *available_out > output.len() { |
2694 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); |
2695 | 2.53M | } |
2696 | 2.53M | if s.buffer_length == 0 { |
2697 | 2.51M | local_input = xinput; |
2698 | 2.51M | s.br.avail_in = *available_in as u32; |
2699 | 2.51M | s.br.next_in = *input_offset as u32; |
2700 | 2.51M | } else { |
2701 | 19.9k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2702 | 19.9k | let copy_len = core::cmp::min(saved_buffer.len() - s.buffer_length as usize, *available_in); |
2703 | 19.9k | if copy_len > 0 { |
2704 | 5.06k | fast_mut!((saved_buffer)[s.buffer_length as usize ; (s.buffer_length as usize + copy_len)]) |
2705 | 5.06k | .clone_from_slice(fast!((xinput)[*input_offset ; copy_len + *input_offset])); |
2706 | 5.06k | fast_mut!((s.buffer)[s.buffer_length as usize ; (s.buffer_length as usize + copy_len)]) |
2707 | 5.06k | .clone_from_slice(fast!((xinput)[*input_offset ; copy_len + *input_offset])); |
2708 | 14.8k | } |
2709 | 19.9k | local_input = &saved_buffer[..]; |
2710 | 19.9k | s.br.next_in = 0; |
2711 | | } |
2712 | | loop { |
2713 | 6.35M | match result { |
2714 | 3.85M | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
2715 | | _ => { |
2716 | 2.49M | match result { |
2717 | | BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT => { |
2718 | 1.60M | if s.ringbuffer.slice().len() != 0 { |
2719 | 1.50M | let (intermediate_result, _) = WriteRingBuffer(available_out, |
2720 | 1.50M | Some(&mut output), |
2721 | 1.50M | &mut output_offset, |
2722 | 1.50M | &mut total_out, |
2723 | 1.50M | true, |
2724 | 1.50M | &mut s); |
2725 | 1.50M | if is_fatal(intermediate_result) { |
2726 | 1.74k | result = intermediate_result; |
2727 | 1.74k | break; |
2728 | 1.50M | } |
2729 | 103k | } |
2730 | 1.60M | if s.buffer_length != 0 { |
2731 | | // Used with internal buffer. |
2732 | 22.9k | if s.br.avail_in == 0 { |
2733 | | // Successfully finished read transaction. |
2734 | | // Accamulator contains less than 8 bits, because internal buffer |
2735 | | // is expanded byte-by-byte until it is enough to complete read. |
2736 | 2.74k | s.buffer_length = 0; |
2737 | | // Switch to input stream and restart. |
2738 | 2.74k | result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
2739 | 2.74k | local_input = xinput; |
2740 | 2.74k | s.br.avail_in = *available_in as u32; |
2741 | 2.74k | s.br.next_in = *input_offset as u32; |
2742 | 2.74k | continue; |
2743 | 20.2k | } else if *available_in != 0 { |
2744 | | // Not enough data in buffer, but can take one more byte from |
2745 | | // input stream. |
2746 | 5.30k | result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; |
2747 | 5.30k | let new_byte = fast!((xinput)[*input_offset]); |
2748 | 5.30k | fast_mut!((s.buffer)[s.buffer_length as usize]) = new_byte; |
2749 | | // we did the following copy upfront, so we wouldn't have to do it here |
2750 | | // since saved_buffer[s.buffer_length as usize] = new_byte violates borrow rules |
2751 | 5.30k | assert_eq!(fast!((saved_buffer)[s.buffer_length as usize]), new_byte); |
2752 | 5.30k | s.buffer_length += 1; |
2753 | 5.30k | s.br.avail_in = s.buffer_length; |
2754 | 5.30k | (*input_offset) += 1; |
2755 | 5.30k | (*available_in) -= 1; |
2756 | | // Retry with more data in buffer. |
2757 | | // we can't re-borrow the saved buffer...so we have to do this recursively |
2758 | 5.30k | continue; |
2759 | 14.9k | } |
2760 | | // Can't finish reading and no more input. |
2761 | | |
2762 | | // FIXME :: NOT SURE WHAT THIS MEANT |
2763 | | // saved_buffer = core::mem::replace( |
2764 | | // &mut s.br.input_, |
2765 | | // &mut[]); // clear input |
2766 | 14.9k | break; |
2767 | | } else { |
2768 | | // Input stream doesn't contain enough input. |
2769 | | // Copy tail to internal buffer and return. |
2770 | 1.58M | *input_offset = s.br.next_in as usize; |
2771 | 1.58M | *available_in = s.br.avail_in as usize; |
2772 | 1.58M | while *available_in != 0 { |
2773 | 6.83k | fast_mut!((s.buffer)[s.buffer_length as usize]) = fast!((xinput)[*input_offset]); |
2774 | 6.83k | s.buffer_length += 1; |
2775 | 6.83k | (*input_offset) += 1; |
2776 | 6.83k | (*available_in) -= 1; |
2777 | 6.83k | } |
2778 | 1.58M | break; |
2779 | | } |
2780 | | // unreachable!(); <- dead code |
2781 | | } |
2782 | | _ => { |
2783 | | // Fail or needs more output. |
2784 | 890k | if s.buffer_length != 0 { |
2785 | 1.70k | // Just consumed the buffered input and produced some output. Otherwise |
2786 | 1.70k | // it would result in "needs more input". Reset internal buffer. |
2787 | 1.70k | s.buffer_length = 0; |
2788 | 888k | } else { |
2789 | 888k | // Using input stream in last iteration. When decoder switches to input |
2790 | 888k | // stream it has less than 8 bits in accamulator, so it is safe to |
2791 | 888k | // return unused accamulator bits there. |
2792 | 888k | bit_reader::BrotliBitReaderUnload(&mut s.br); |
2793 | 888k | *available_in = s.br.avail_in as usize; |
2794 | 888k | *input_offset = s.br.next_in as usize; |
2795 | 888k | } |
2796 | | } |
2797 | | } |
2798 | 890k | break; |
2799 | | } |
2800 | | } |
2801 | | loop { |
2802 | | // this emulates fallthrough behavior |
2803 | 4.65M | match s.state { |
2804 | | BrotliRunningState::BROTLI_STATE_UNINITED => { |
2805 | | // Prepare to the first read. |
2806 | 201k | if (!bit_reader::BrotliWarmupBitReader(&mut s.br, local_input)) { |
2807 | 87.9k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2808 | 87.9k | break; |
2809 | 113k | } |
2810 | | // Decode window size. |
2811 | | /* Reads 1..8 bits. */ |
2812 | 113k | result = DecodeWindowBits(&mut s.large_window, &mut s.window_bits, &mut s.br); |
2813 | 113k | match result { |
2814 | 113k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
2815 | 604 | _ => break, |
2816 | | } |
2817 | 113k | if s.large_window { |
2818 | 4.79k | s.state = BrotliRunningState::BROTLI_STATE_LARGE_WINDOW_BITS; |
2819 | 108k | } else { |
2820 | 108k | s.state = BrotliRunningState::BROTLI_STATE_INITIALIZE; |
2821 | 108k | } |
2822 | | } |
2823 | | BrotliRunningState::BROTLI_STATE_LARGE_WINDOW_BITS => { |
2824 | 5.94k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 6, &mut s.window_bits, local_input)) { |
2825 | 1.23k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2826 | 1.23k | break; |
2827 | 4.70k | } |
2828 | 4.70k | if (s.window_bits < kBrotliLargeMinWbits || |
2829 | 3.57k | s.window_bits > kBrotliLargeMaxWbits) { |
2830 | 1.40k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; |
2831 | 1.40k | break; |
2832 | 3.29k | } |
2833 | 3.29k | s.state = BrotliRunningState::BROTLI_STATE_INITIALIZE; |
2834 | | } |
2835 | | BrotliRunningState::BROTLI_STATE_INITIALIZE => { |
2836 | 111k | s.max_backward_distance = (1 << s.window_bits) - kBrotliWindowGap as i32; |
2837 | 111k | s.max_backward_distance_minus_custom_dict_size = (s.max_backward_distance as isize - |
2838 | 111k | s.custom_dict_size) as i32; |
2839 | | |
2840 | | // (formerly) Allocate memory for both block_type_trees and block_len_trees. |
2841 | 111k | s.block_type_length_state.block_type_trees = s.alloc_hc |
2842 | 111k | .alloc_cell(3 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize); |
2843 | 111k | if (s.block_type_length_state.block_type_trees.slice().len() == 0) { |
2844 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES; |
2845 | 0 | break; |
2846 | 111k | } |
2847 | 111k | s.block_type_length_state.block_len_trees = s.alloc_hc |
2848 | 111k | .alloc_cell(3 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize); |
2849 | | |
2850 | 111k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN; |
2851 | | // No break, continue to next state |
2852 | | } |
2853 | 133k | BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN => { |
2854 | 133k | s.BrotliStateMetablockBegin(); |
2855 | 133k | BROTLI_LOG_UINT!(s.pos); |
2856 | 133k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER; |
2857 | 133k | // No break, continue to next state |
2858 | 133k | } |
2859 | | BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER => { |
2860 | 433k | result = DecodeMetaBlockLength(&mut s, local_input); // Reads 2 - 31 bits. |
2861 | 433k | match result { |
2862 | 125k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
2863 | 308k | _ => break, |
2864 | | } |
2865 | | BROTLI_LOG_UINT!(s.is_last_metablock); |
2866 | | BROTLI_LOG_UINT!(s.meta_block_remaining_len); |
2867 | | BROTLI_LOG_UINT!(s.is_metadata); |
2868 | | BROTLI_LOG_UINT!(s.is_uncompressed); |
2869 | 125k | if (s.is_metadata != 0 || s.is_uncompressed != 0) && |
2870 | 24.1k | !bit_reader::BrotliJumpToByteBoundary(&mut s.br) { |
2871 | 3.39k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_PADDING_2; |
2872 | 3.39k | break; |
2873 | 122k | } |
2874 | 122k | if s.is_metadata != 0 { |
2875 | 12.3k | s.state = BrotliRunningState::BROTLI_STATE_METADATA; |
2876 | 12.3k | break; |
2877 | 109k | } |
2878 | 109k | if s.meta_block_remaining_len == 0 { |
2879 | 4.03k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; |
2880 | 4.03k | break; |
2881 | 105k | } |
2882 | 105k | if s.ringbuffer.slice().len() == 0 && !BrotliAllocateRingBuffer(&mut s, local_input) { |
2883 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2; |
2884 | 0 | break; |
2885 | 105k | } |
2886 | 105k | if s.is_uncompressed != 0 { |
2887 | 8.39k | s.state = BrotliRunningState::BROTLI_STATE_UNCOMPRESSED; |
2888 | 8.39k | break; |
2889 | 97.4k | } |
2890 | 97.4k | s.loop_counter = 0; |
2891 | 97.4k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0; |
2892 | 97.4k | break; |
2893 | | } |
2894 | | BrotliRunningState::BROTLI_STATE_UNCOMPRESSED => { |
2895 | 139k | let mut _bytes_copied = s.meta_block_remaining_len; |
2896 | 139k | result = CopyUncompressedBlockToOutput(&mut available_out, |
2897 | 139k | &mut output, |
2898 | 139k | &mut output_offset, |
2899 | 139k | &mut total_out, |
2900 | 139k | &mut s, |
2901 | 139k | local_input); |
2902 | 139k | _bytes_copied -= s.meta_block_remaining_len; |
2903 | 139k | match result { |
2904 | 3.29k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
2905 | 136k | _ => break, |
2906 | | } |
2907 | 3.29k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; |
2908 | 3.29k | break; |
2909 | | } |
2910 | | BrotliRunningState::BROTLI_STATE_METADATA => { |
2911 | 688k | while s.meta_block_remaining_len > 0 { |
2912 | 677k | let mut bits = 0u32; |
2913 | | // Read one byte and ignore it. |
2914 | 677k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 8, &mut bits, local_input) { |
2915 | 25.3k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
2916 | 25.3k | break; |
2917 | 652k | } |
2918 | 652k | s.meta_block_remaining_len -= 1; |
2919 | | } |
2920 | 36.0k | if let BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS = result { |
2921 | 10.7k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE |
2922 | 25.3k | } |
2923 | 36.0k | break; |
2924 | | } |
2925 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0 => { |
2926 | 411k | if s.loop_counter >= 3 { |
2927 | 85.6k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER_2; |
2928 | 85.6k | break; |
2929 | 325k | } |
2930 | | // Reads 1..11 bits. |
2931 | 325k | { |
2932 | 325k | let index = s.loop_counter as usize; |
2933 | 325k | result = |
2934 | 325k | DecodeVarLenUint8(&mut s.substate_decode_uint8, |
2935 | 325k | &mut s.br, |
2936 | 325k | &mut fast_mut!((s.block_type_length_state.num_block_types)[index]), |
2937 | 325k | local_input); |
2938 | 325k | } |
2939 | 325k | match result { |
2940 | 276k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
2941 | 48.7k | _ => break, |
2942 | | } |
2943 | 276k | fast_mut!((s.block_type_length_state.num_block_types)[s.loop_counter as usize]) += 1; |
2944 | | BROTLI_LOG_UINT!(s.block_type_length_state.num_block_types[s.loop_counter as usize]); |
2945 | 276k | if fast!((s.block_type_length_state.num_block_types)[s.loop_counter as usize]) < 2 { |
2946 | 237k | s.loop_counter += 1; |
2947 | 237k | break; |
2948 | 39.6k | } |
2949 | 39.6k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_1; |
2950 | | // No break, continue to next state |
2951 | | } |
2952 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_1 => { |
2953 | 244k | let tree_offset = s.loop_counter as u32 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as u32; |
2954 | 244k | let mut new_huffman_table = mem::replace(&mut s.block_type_length_state.block_type_trees, |
2955 | 244k | AllocHC::AllocatedMemory::default()); |
2956 | 244k | let loop_counter = s.loop_counter as usize; |
2957 | 244k | let alphabet_size = fast!((s.block_type_length_state.num_block_types)[loop_counter]) + 2; |
2958 | 244k | result = |
2959 | 244k | ReadHuffmanCode(alphabet_size, alphabet_size, |
2960 | 244k | new_huffman_table.slice_mut(), |
2961 | 244k | tree_offset as usize, |
2962 | 244k | None, |
2963 | 244k | &mut s, |
2964 | 244k | local_input); |
2965 | 244k | let _ = mem::replace(&mut s.block_type_length_state.block_type_trees, |
2966 | 244k | new_huffman_table); |
2967 | 244k | match result { |
2968 | 33.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
2969 | 211k | _ => break, |
2970 | | } |
2971 | 33.3k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_2; |
2972 | | // No break, continue to next state |
2973 | | } |
2974 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_2 => { |
2975 | 76.2k | let tree_offset = s.loop_counter * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as i32; |
2976 | 76.2k | let mut new_huffman_table = mem::replace(&mut s.block_type_length_state.block_len_trees, |
2977 | 76.2k | AllocHC::AllocatedMemory::default()); |
2978 | 76.2k | result = ReadHuffmanCode(kNumBlockLengthCodes, kNumBlockLengthCodes, |
2979 | 76.2k | new_huffman_table.slice_mut(), |
2980 | 76.2k | tree_offset as usize, |
2981 | 76.2k | None, |
2982 | 76.2k | &mut s, |
2983 | 76.2k | local_input); |
2984 | 76.2k | let _ = mem::replace(&mut s.block_type_length_state.block_len_trees, |
2985 | 76.2k | new_huffman_table); |
2986 | 76.2k | match result { |
2987 | 29.5k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
2988 | 46.7k | _ => break, |
2989 | | } |
2990 | 29.5k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_3; |
2991 | | // No break, continue to next state |
2992 | | } |
2993 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_3 => { |
2994 | 48.8k | let tree_offset = s.loop_counter * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as i32; |
2995 | | |
2996 | 48.8k | let mut block_length_out: u32 = 0; |
2997 | | let ind_ret: (bool, u32); |
2998 | | |
2999 | 48.8k | ind_ret = SafeReadBlockLengthIndex(&s.block_type_length_state.substate_read_block_length, |
3000 | 48.8k | s.block_type_length_state.block_length_index, |
3001 | 48.8k | fast_slice!((s.block_type_length_state.block_len_trees) |
3002 | 48.8k | [tree_offset as usize;]), |
3003 | 48.8k | &mut s.br, local_input); |
3004 | | |
3005 | 48.8k | if !SafeReadBlockLengthFromIndex(&mut s.block_type_length_state, |
3006 | 48.8k | &mut s.br, |
3007 | 48.8k | &mut block_length_out, |
3008 | 48.8k | ind_ret, |
3009 | 48.8k | local_input) { |
3010 | 20.3k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
3011 | 20.3k | break; |
3012 | 28.5k | } |
3013 | 28.5k | fast_mut!((s.block_type_length_state.block_length)[s.loop_counter as usize]) = |
3014 | 28.5k | block_length_out; |
3015 | | BROTLI_LOG_UINT!(s.block_type_length_state.block_length[s.loop_counter as usize]); |
3016 | 28.5k | s.loop_counter += 1; |
3017 | 28.5k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0; |
3018 | 28.5k | break; |
3019 | | } |
3020 | | BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER_2 => { |
3021 | 110k | let mut bits: u32 = 0; |
3022 | 110k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 6, &mut bits, local_input)) { |
3023 | 24.9k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; |
3024 | 24.9k | break; |
3025 | 85.4k | } |
3026 | 85.4k | s.distance_postfix_bits = bits & bit_reader::BitMask(2); |
3027 | 85.4k | bits >>= 2; |
3028 | 85.4k | s.num_direct_distance_codes = NUM_DISTANCE_SHORT_CODES + |
3029 | 85.4k | (bits << s.distance_postfix_bits); |
3030 | | BROTLI_LOG_UINT!(s.num_direct_distance_codes); |
3031 | | BROTLI_LOG_UINT!(s.distance_postfix_bits); |
3032 | 85.4k | s.distance_postfix_mask = bit_reader::BitMask(s.distance_postfix_bits) as i32; |
3033 | 85.4k | s.context_modes = s.alloc_u8 |
3034 | 85.4k | .alloc_cell(fast!((s.block_type_length_state.num_block_types)[0]) as usize); |
3035 | 85.4k | if (s.context_modes.slice().len() == 0) { |
3036 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES; |
3037 | 0 | break; |
3038 | 85.4k | } |
3039 | 85.4k | s.loop_counter = 0; |
3040 | 85.4k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MODES; |
3041 | | // No break, continue to next state |
3042 | | } |
3043 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MODES => { |
3044 | 91.9k | result = ReadContextModes(&mut s, local_input); |
3045 | 91.9k | match result { |
3046 | 85.2k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
3047 | 6.72k | _ => break, |
3048 | | } |
3049 | 85.2k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1; |
3050 | | // No break, continue to next state |
3051 | | } |
3052 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1 => { |
3053 | 166k | result = |
3054 | 166k | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[0]) as usize) << |
3055 | 166k | kLiteralContextBits as usize, |
3056 | 166k | false, |
3057 | 166k | &mut s, |
3058 | 166k | local_input); |
3059 | 166k | match result { |
3060 | 78.5k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
3061 | 88.0k | _ => break, |
3062 | | } |
3063 | 78.5k | DetectTrivialLiteralBlockTypes(s); |
3064 | 78.5k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2; |
3065 | | // No break, continue to next state |
3066 | | } |
3067 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2 => { |
3068 | 150k | let num_direct_codes = |
3069 | 150k | s.num_direct_distance_codes - NUM_DISTANCE_SHORT_CODES; |
3070 | 150k | let num_distance_codes = BROTLI_DISTANCE_ALPHABET_SIZE( |
3071 | 150k | s.distance_postfix_bits, num_direct_codes, |
3072 | 150k | (if s.large_window { BROTLI_LARGE_MAX_DISTANCE_BITS } else { |
3073 | 122k | BROTLI_MAX_DISTANCE_BITS})); |
3074 | 150k | let max_distance_symbol = if s.large_window { |
3075 | 28.2k | BrotliMaxDistanceSymbol( |
3076 | 28.2k | num_direct_codes, s.distance_postfix_bits) |
3077 | | } else { |
3078 | 122k | num_distance_codes |
3079 | | }; |
3080 | 150k | result = |
3081 | 150k | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[2]) as usize) << |
3082 | 150k | kDistanceContextBits as usize, |
3083 | 150k | true, |
3084 | 150k | s, |
3085 | 150k | local_input); |
3086 | 150k | match result { |
3087 | 72.0k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
3088 | 78.9k | _ => break, |
3089 | | } |
3090 | 72.0k | s.literal_hgroup.init(&mut s.alloc_u32, |
3091 | 72.0k | &mut s.alloc_hc, |
3092 | | kNumLiteralCodes, |
3093 | | kNumLiteralCodes, |
3094 | 72.0k | s.num_literal_htrees as u16); |
3095 | 72.0k | s.insert_copy_hgroup.init(&mut s.alloc_u32, |
3096 | 72.0k | &mut s.alloc_hc, |
3097 | | kNumInsertAndCopyCodes, |
3098 | | kNumInsertAndCopyCodes, |
3099 | 72.0k | fast!((s.block_type_length_state.num_block_types)[1]) as u16); |
3100 | 72.0k | s.distance_hgroup.init(&mut s.alloc_u32, |
3101 | 72.0k | &mut s.alloc_hc, |
3102 | 72.0k | num_distance_codes as u16, |
3103 | 72.0k | max_distance_symbol as u16, |
3104 | 72.0k | s.num_dist_htrees as u16); |
3105 | 72.0k | if (s.literal_hgroup.codes.slice().len() == 0 || |
3106 | 72.0k | s.insert_copy_hgroup.codes.slice().len() == 0 || |
3107 | 72.0k | s.distance_hgroup.codes.slice().len() == 0) { |
3108 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE); |
3109 | 72.0k | } |
3110 | | |
3111 | | /*{ |
3112 | | let num_distance_codes: u32 = s.num_direct_distance_codes + |
3113 | | (48u32 << s.distance_postfix_bits); |
3114 | | result = |
3115 | | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[2]) as usize) << |
3116 | | kDistanceContextBits as usize, |
3117 | | true, |
3118 | | s, |
3119 | | local_input); |
3120 | | match result { |
3121 | | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
3122 | | _ => break, |
3123 | | } |
3124 | | s.literal_hgroup.init(&mut s.alloc_u32, |
3125 | | &mut s.alloc_hc, |
3126 | | kNumLiteralCodes, |
3127 | | s.num_literal_htrees as u16); |
3128 | | s.insert_copy_hgroup.init(&mut s.alloc_u32, |
3129 | | &mut s.alloc_hc, |
3130 | | kNumInsertAndCopyCodes, |
3131 | | fast!((s.block_type_length_state.num_block_types)[1]) as u16); |
3132 | | s.distance_hgroup.init(&mut s.alloc_u32, |
3133 | | &mut s.alloc_hc, |
3134 | | num_distance_codes as u16, |
3135 | | s.num_dist_htrees as u16); |
3136 | | if (s.literal_hgroup.codes.slice().len() == 0 || |
3137 | | s.insert_copy_hgroup.codes.slice().len() == 0 || |
3138 | | s.distance_hgroup.codes.slice().len() == 0) { |
3139 | | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS); |
3140 | | } |
3141 | | }*/ |
3142 | 72.0k | s.loop_counter = 0; |
3143 | 72.0k | s.state = BrotliRunningState::BROTLI_STATE_TREE_GROUP; |
3144 | | // No break, continue to next state |
3145 | | } |
3146 | | BrotliRunningState::BROTLI_STATE_TREE_GROUP => { |
3147 | 258k | result = HuffmanTreeGroupDecode(s.loop_counter, &mut s, local_input); |
3148 | 258k | match result { |
3149 | 134k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
3150 | 123k | _ => break, |
3151 | | } |
3152 | 134k | s.loop_counter += 1; |
3153 | 134k | if (s.loop_counter >= 3) { |
3154 | 40.6k | PrepareLiteralDecoding(s); |
3155 | 40.6k | s.dist_context_map_slice_index = 0; |
3156 | 40.6k | /* |
3157 | 40.6k | s.context_map_slice_index = 0; |
3158 | 40.6k | let context_mode_index = fast!((s.block_type_length_state.block_type_rb)[1]); |
3159 | 40.6k | let context_mode = fast_slice!((s.context_modes)[context_mode_index as usize]); |
3160 | 40.6k | s.context_lookup = &kContextLookup[context_mode as usize & 3]; |
3161 | 40.6k | */ |
3162 | 40.6k | s.htree_command_index = 0; |
3163 | 40.6k | // look it up each time s.literal_htree=s.literal_hgroup.htrees[s.literal_htree_index]; |
3164 | 40.6k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; |
3165 | 94.3k | } |
3166 | 134k | break; |
3167 | | } |
3168 | | BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN | |
3169 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER | |
3170 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS | |
3171 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY => { |
3172 | 788k | result = ProcessCommands(s, local_input); |
3173 | 788k | if let BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT = result { |
3174 | 656k | result = SafeProcessCommands(s, local_input) |
3175 | 131k | } |
3176 | 788k | break; |
3177 | | } |
3178 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE | |
3179 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1 | |
3180 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2 => { |
3181 | 916k | let (xresult, _) = WriteRingBuffer(&mut available_out, |
3182 | 916k | Some(&mut output), |
3183 | 916k | &mut output_offset, |
3184 | 916k | &mut total_out, |
3185 | 916k | false, |
3186 | 916k | &mut s); |
3187 | 916k | result = xresult; |
3188 | 916k | match result { |
3189 | 332k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
3190 | 583k | _ => break, |
3191 | | } |
3192 | 332k | WrapRingBuffer(s); |
3193 | 332k | if s.ringbuffer_size == 1 << s.window_bits { |
3194 | 332k | s.max_distance = s.max_backward_distance; |
3195 | 332k | } |
3196 | 332k | match s.state { |
3197 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1 => { |
3198 | 140k | if (s.meta_block_remaining_len <= 0) { |
3199 | 0 | // Next metablock, if any |
3200 | 0 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; |
3201 | 140k | } else { |
3202 | 140k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; |
3203 | 140k | } |
3204 | 140k | break; |
3205 | | } |
3206 | 115k | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2 => { |
3207 | 115k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; |
3208 | 115k | } |
3209 | | _ => { |
3210 | | // BROTLI_STATE_COMMAND_INNER_WRITE |
3211 | 77.4k | if (s.loop_counter == 0) { |
3212 | 3.43k | if (s.meta_block_remaining_len <= 0) { |
3213 | 0 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; |
3214 | 3.43k | } else { |
3215 | 3.43k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; |
3216 | 3.43k | } |
3217 | 3.43k | break; |
3218 | 74.0k | } |
3219 | 74.0k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; |
3220 | | } |
3221 | | } |
3222 | 189k | break; |
3223 | | } |
3224 | | BrotliRunningState::BROTLI_STATE_METABLOCK_DONE => { |
3225 | 38.3k | s.BrotliStateCleanupAfterMetablock(); |
3226 | 38.3k | if (s.is_last_metablock == 0) { |
3227 | 21.8k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN; |
3228 | 21.8k | break; |
3229 | 16.4k | } |
3230 | 16.4k | if (!bit_reader::BrotliJumpToByteBoundary(&mut s.br)) { |
3231 | 3.65k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_PADDING_2; |
3232 | 12.8k | } |
3233 | 16.4k | if (s.buffer_length == 0) { |
3234 | 15.9k | bit_reader::BrotliBitReaderUnload(&mut s.br); |
3235 | 15.9k | *available_in = s.br.avail_in as usize; |
3236 | 15.9k | *input_offset = s.br.next_in as usize; |
3237 | 15.9k | } |
3238 | 16.4k | s.state = BrotliRunningState::BROTLI_STATE_DONE; |
3239 | | // No break, continue to next state |
3240 | | } |
3241 | | BrotliRunningState::BROTLI_STATE_DONE => { |
3242 | 289k | if (s.ringbuffer.slice().len() != 0) { |
3243 | 279k | let (xresult, _) = WriteRingBuffer(&mut available_out, |
3244 | 279k | Some(&mut output), |
3245 | 279k | &mut output_offset, |
3246 | 279k | &mut total_out, |
3247 | 279k | true, |
3248 | 279k | &mut s); |
3249 | 279k | result = xresult; |
3250 | 279k | match result { |
3251 | 33.4k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} |
3252 | 246k | _ => break, |
3253 | | } |
3254 | 10.0k | } |
3255 | 43.5k | return SaveErrorCode!(s, result); |
3256 | | } |
3257 | | } |
3258 | | } |
3259 | | } |
3260 | | |
3261 | 2.48M | SaveErrorCode!(s, result) |
3262 | 2.55M | } brotli_decompressor::decode::BrotliDecompressStream::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2664 | 1.82M | pub fn BrotliDecompressStream<AllocU8: alloc::Allocator<u8>, | 2665 | 1.82M | AllocU32: alloc::Allocator<u32>, | 2666 | 1.82M | AllocHC: alloc::Allocator<HuffmanCode>> | 2667 | 1.82M | (available_in: &mut usize, | 2668 | 1.82M | input_offset: &mut usize, | 2669 | 1.82M | xinput: &[u8], | 2670 | 1.82M | mut available_out: &mut usize, | 2671 | 1.82M | mut output_offset: &mut usize, | 2672 | 1.82M | mut output: &mut [u8], | 2673 | 1.82M | mut total_out: &mut usize, | 2674 | 1.82M | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) | 2675 | 1.82M | -> BrotliResult { | 2676 | | | 2677 | 1.82M | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2678 | | | 2679 | 1.82M | let mut saved_buffer: [u8; 8] = s.buffer; | 2680 | | let mut local_input: &[u8]; | 2681 | 1.82M | if is_fatal(s.error_code) { | 2682 | 0 | return BrotliResult::ResultFailure; | 2683 | 1.82M | } | 2684 | 1.82M | if *available_in as u64 >= (1u64 << 32) { | 2685 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2686 | 1.82M | } | 2687 | 1.82M | if *input_offset as u64 >= (1u64 << 32) { | 2688 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2689 | 1.82M | } | 2690 | 1.82M | if *input_offset + *available_in > xinput.len() { | 2691 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2692 | 1.82M | } | 2693 | 1.82M | if *output_offset + *available_out > output.len() { | 2694 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2695 | 1.82M | } | 2696 | 1.82M | if s.buffer_length == 0 { | 2697 | 1.81M | local_input = xinput; | 2698 | 1.81M | s.br.avail_in = *available_in as u32; | 2699 | 1.81M | s.br.next_in = *input_offset as u32; | 2700 | 1.81M | } else { | 2701 | 10.3k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2702 | 10.3k | let copy_len = core::cmp::min(saved_buffer.len() - s.buffer_length as usize, *available_in); | 2703 | 10.3k | if copy_len > 0 { | 2704 | 2.31k | fast_mut!((saved_buffer)[s.buffer_length as usize ; (s.buffer_length as usize + copy_len)]) | 2705 | 2.31k | .clone_from_slice(fast!((xinput)[*input_offset ; copy_len + *input_offset])); | 2706 | 2.31k | fast_mut!((s.buffer)[s.buffer_length as usize ; (s.buffer_length as usize + copy_len)]) | 2707 | 2.31k | .clone_from_slice(fast!((xinput)[*input_offset ; copy_len + *input_offset])); | 2708 | 8.07k | } | 2709 | 10.3k | local_input = &saved_buffer[..]; | 2710 | 10.3k | s.br.next_in = 0; | 2711 | | } | 2712 | | loop { | 2713 | 4.61M | match result { | 2714 | 2.82M | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2715 | | _ => { | 2716 | 1.79M | match result { | 2717 | | BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT => { | 2718 | 1.19M | if s.ringbuffer.slice().len() != 0 { | 2719 | 1.13M | let (intermediate_result, _) = WriteRingBuffer(available_out, | 2720 | 1.13M | Some(&mut output), | 2721 | 1.13M | &mut output_offset, | 2722 | 1.13M | &mut total_out, | 2723 | 1.13M | true, | 2724 | 1.13M | &mut s); | 2725 | 1.13M | if is_fatal(intermediate_result) { | 2726 | 553 | result = intermediate_result; | 2727 | 553 | break; | 2728 | 1.13M | } | 2729 | 66.8k | } | 2730 | 1.19M | if s.buffer_length != 0 { | 2731 | | // Used with internal buffer. | 2732 | 11.3k | if s.br.avail_in == 0 { | 2733 | | // Successfully finished read transaction. | 2734 | | // Accamulator contains less than 8 bits, because internal buffer | 2735 | | // is expanded byte-by-byte until it is enough to complete read. | 2736 | 919 | s.buffer_length = 0; | 2737 | | // Switch to input stream and restart. | 2738 | 919 | result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2739 | 919 | local_input = xinput; | 2740 | 919 | s.br.avail_in = *available_in as u32; | 2741 | 919 | s.br.next_in = *input_offset as u32; | 2742 | 919 | continue; | 2743 | 10.4k | } else if *available_in != 0 { | 2744 | | // Not enough data in buffer, but can take one more byte from | 2745 | | // input stream. | 2746 | 2.33k | result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2747 | 2.33k | let new_byte = fast!((xinput)[*input_offset]); | 2748 | 2.33k | fast_mut!((s.buffer)[s.buffer_length as usize]) = new_byte; | 2749 | | // we did the following copy upfront, so we wouldn't have to do it here | 2750 | | // since saved_buffer[s.buffer_length as usize] = new_byte violates borrow rules | 2751 | 2.33k | assert_eq!(fast!((saved_buffer)[s.buffer_length as usize]), new_byte); | 2752 | 2.33k | s.buffer_length += 1; | 2753 | 2.33k | s.br.avail_in = s.buffer_length; | 2754 | 2.33k | (*input_offset) += 1; | 2755 | 2.33k | (*available_in) -= 1; | 2756 | | // Retry with more data in buffer. | 2757 | | // we can't re-borrow the saved buffer...so we have to do this recursively | 2758 | 2.33k | continue; | 2759 | 8.07k | } | 2760 | | // Can't finish reading and no more input. | 2761 | | | 2762 | | // FIXME :: NOT SURE WHAT THIS MEANT | 2763 | | // saved_buffer = core::mem::replace( | 2764 | | // &mut s.br.input_, | 2765 | | // &mut[]); // clear input | 2766 | 8.07k | break; | 2767 | | } else { | 2768 | | // Input stream doesn't contain enough input. | 2769 | | // Copy tail to internal buffer and return. | 2770 | 1.18M | *input_offset = s.br.next_in as usize; | 2771 | 1.18M | *available_in = s.br.avail_in as usize; | 2772 | 1.18M | while *available_in != 0 { | 2773 | 2.77k | fast_mut!((s.buffer)[s.buffer_length as usize]) = fast!((xinput)[*input_offset]); | 2774 | 2.77k | s.buffer_length += 1; | 2775 | 2.77k | (*input_offset) += 1; | 2776 | 2.77k | (*available_in) -= 1; | 2777 | 2.77k | } | 2778 | 1.18M | break; | 2779 | | } | 2780 | | // unreachable!(); <- dead code | 2781 | | } | 2782 | | _ => { | 2783 | | // Fail or needs more output. | 2784 | 600k | if s.buffer_length != 0 { | 2785 | 1.35k | // Just consumed the buffered input and produced some output. Otherwise | 2786 | 1.35k | // it would result in "needs more input". Reset internal buffer. | 2787 | 1.35k | s.buffer_length = 0; | 2788 | 599k | } else { | 2789 | 599k | // Using input stream in last iteration. When decoder switches to input | 2790 | 599k | // stream it has less than 8 bits in accamulator, so it is safe to | 2791 | 599k | // return unused accamulator bits there. | 2792 | 599k | bit_reader::BrotliBitReaderUnload(&mut s.br); | 2793 | 599k | *available_in = s.br.avail_in as usize; | 2794 | 599k | *input_offset = s.br.next_in as usize; | 2795 | 599k | } | 2796 | | } | 2797 | | } | 2798 | 600k | break; | 2799 | | } | 2800 | | } | 2801 | | loop { | 2802 | | // this emulates fallthrough behavior | 2803 | 3.25M | match s.state { | 2804 | | BrotliRunningState::BROTLI_STATE_UNINITED => { | 2805 | | // Prepare to the first read. | 2806 | 124k | if (!bit_reader::BrotliWarmupBitReader(&mut s.br, local_input)) { | 2807 | 63.1k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2808 | 63.1k | break; | 2809 | 61.5k | } | 2810 | | // Decode window size. | 2811 | | /* Reads 1..8 bits. */ | 2812 | 61.5k | result = DecodeWindowBits(&mut s.large_window, &mut s.window_bits, &mut s.br); | 2813 | 61.5k | match result { | 2814 | 61.1k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2815 | 471 | _ => break, | 2816 | | } | 2817 | 61.1k | if s.large_window { | 2818 | 3.65k | s.state = BrotliRunningState::BROTLI_STATE_LARGE_WINDOW_BITS; | 2819 | 57.4k | } else { | 2820 | 57.4k | s.state = BrotliRunningState::BROTLI_STATE_INITIALIZE; | 2821 | 57.4k | } | 2822 | | } | 2823 | | BrotliRunningState::BROTLI_STATE_LARGE_WINDOW_BITS => { | 2824 | 4.32k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 6, &mut s.window_bits, local_input)) { | 2825 | 746 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2826 | 746 | break; | 2827 | 3.58k | } | 2828 | 3.58k | if (s.window_bits < kBrotliLargeMinWbits || | 2829 | 2.64k | s.window_bits > kBrotliLargeMaxWbits) { | 2830 | 1.13k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; | 2831 | 1.13k | break; | 2832 | 2.44k | } | 2833 | 2.44k | s.state = BrotliRunningState::BROTLI_STATE_INITIALIZE; | 2834 | | } | 2835 | | BrotliRunningState::BROTLI_STATE_INITIALIZE => { | 2836 | 59.8k | s.max_backward_distance = (1 << s.window_bits) - kBrotliWindowGap as i32; | 2837 | 59.8k | s.max_backward_distance_minus_custom_dict_size = (s.max_backward_distance as isize - | 2838 | 59.8k | s.custom_dict_size) as i32; | 2839 | | | 2840 | | // (formerly) Allocate memory for both block_type_trees and block_len_trees. | 2841 | 59.8k | s.block_type_length_state.block_type_trees = s.alloc_hc | 2842 | 59.8k | .alloc_cell(3 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize); | 2843 | 59.8k | if (s.block_type_length_state.block_type_trees.slice().len() == 0) { | 2844 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES; | 2845 | 0 | break; | 2846 | 59.8k | } | 2847 | 59.8k | s.block_type_length_state.block_len_trees = s.alloc_hc | 2848 | 59.8k | .alloc_cell(3 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize); | 2849 | | | 2850 | 59.8k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN; | 2851 | | // No break, continue to next state | 2852 | | } | 2853 | 71.8k | BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN => { | 2854 | 71.8k | s.BrotliStateMetablockBegin(); | 2855 | 71.8k | BROTLI_LOG_UINT!(s.pos); | 2856 | 71.8k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER; | 2857 | 71.8k | // No break, continue to next state | 2858 | 71.8k | } | 2859 | | BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER => { | 2860 | 347k | result = DecodeMetaBlockLength(&mut s, local_input); // Reads 2 - 31 bits. | 2861 | 347k | match result { | 2862 | 67.8k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2863 | 279k | _ => break, | 2864 | | } | 2865 | | BROTLI_LOG_UINT!(s.is_last_metablock); | 2866 | | BROTLI_LOG_UINT!(s.meta_block_remaining_len); | 2867 | | BROTLI_LOG_UINT!(s.is_metadata); | 2868 | | BROTLI_LOG_UINT!(s.is_uncompressed); | 2869 | 67.8k | if (s.is_metadata != 0 || s.is_uncompressed != 0) && | 2870 | 13.2k | !bit_reader::BrotliJumpToByteBoundary(&mut s.br) { | 2871 | 1.81k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_PADDING_2; | 2872 | 1.81k | break; | 2873 | 66.0k | } | 2874 | 66.0k | if s.is_metadata != 0 { | 2875 | 6.18k | s.state = BrotliRunningState::BROTLI_STATE_METADATA; | 2876 | 6.18k | break; | 2877 | 59.8k | } | 2878 | 59.8k | if s.meta_block_remaining_len == 0 { | 2879 | 1.39k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2880 | 1.39k | break; | 2881 | 58.4k | } | 2882 | 58.4k | if s.ringbuffer.slice().len() == 0 && !BrotliAllocateRingBuffer(&mut s, local_input) { | 2883 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2; | 2884 | 0 | break; | 2885 | 58.4k | } | 2886 | 58.4k | if s.is_uncompressed != 0 { | 2887 | 5.22k | s.state = BrotliRunningState::BROTLI_STATE_UNCOMPRESSED; | 2888 | 5.22k | break; | 2889 | 53.2k | } | 2890 | 53.2k | s.loop_counter = 0; | 2891 | 53.2k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0; | 2892 | 53.2k | break; | 2893 | | } | 2894 | | BrotliRunningState::BROTLI_STATE_UNCOMPRESSED => { | 2895 | 100k | let mut _bytes_copied = s.meta_block_remaining_len; | 2896 | 100k | result = CopyUncompressedBlockToOutput(&mut available_out, | 2897 | 100k | &mut output, | 2898 | 100k | &mut output_offset, | 2899 | 100k | &mut total_out, | 2900 | 100k | &mut s, | 2901 | 100k | local_input); | 2902 | 100k | _bytes_copied -= s.meta_block_remaining_len; | 2903 | 100k | match result { | 2904 | 2.26k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2905 | 97.9k | _ => break, | 2906 | | } | 2907 | 2.26k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2908 | 2.26k | break; | 2909 | | } | 2910 | | BrotliRunningState::BROTLI_STATE_METADATA => { | 2911 | 601k | while s.meta_block_remaining_len > 0 { | 2912 | 595k | let mut bits = 0u32; | 2913 | | // Read one byte and ignore it. | 2914 | 595k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 8, &mut bits, local_input) { | 2915 | 19.0k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2916 | 19.0k | break; | 2917 | 576k | } | 2918 | 576k | s.meta_block_remaining_len -= 1; | 2919 | | } | 2920 | 24.9k | if let BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS = result { | 2921 | 5.93k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE | 2922 | 19.0k | } | 2923 | 24.9k | break; | 2924 | | } | 2925 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0 => { | 2926 | 242k | if s.loop_counter >= 3 { | 2927 | 49.3k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER_2; | 2928 | 49.3k | break; | 2929 | 192k | } | 2930 | | // Reads 1..11 bits. | 2931 | 192k | { | 2932 | 192k | let index = s.loop_counter as usize; | 2933 | 192k | result = | 2934 | 192k | DecodeVarLenUint8(&mut s.substate_decode_uint8, | 2935 | 192k | &mut s.br, | 2936 | 192k | &mut fast_mut!((s.block_type_length_state.num_block_types)[index]), | 2937 | 192k | local_input); | 2938 | 192k | } | 2939 | 192k | match result { | 2940 | 154k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2941 | 38.0k | _ => break, | 2942 | | } | 2943 | 154k | fast_mut!((s.block_type_length_state.num_block_types)[s.loop_counter as usize]) += 1; | 2944 | | BROTLI_LOG_UINT!(s.block_type_length_state.num_block_types[s.loop_counter as usize]); | 2945 | 154k | if fast!((s.block_type_length_state.num_block_types)[s.loop_counter as usize]) < 2 { | 2946 | 139k | s.loop_counter += 1; | 2947 | 139k | break; | 2948 | 15.3k | } | 2949 | 15.3k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_1; | 2950 | | // No break, continue to next state | 2951 | | } | 2952 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_1 => { | 2953 | 141k | let tree_offset = s.loop_counter as u32 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as u32; | 2954 | 141k | let mut new_huffman_table = mem::replace(&mut s.block_type_length_state.block_type_trees, | 2955 | 141k | AllocHC::AllocatedMemory::default()); | 2956 | 141k | let loop_counter = s.loop_counter as usize; | 2957 | 141k | let alphabet_size = fast!((s.block_type_length_state.num_block_types)[loop_counter]) + 2; | 2958 | 141k | result = | 2959 | 141k | ReadHuffmanCode(alphabet_size, alphabet_size, | 2960 | 141k | new_huffman_table.slice_mut(), | 2961 | 141k | tree_offset as usize, | 2962 | 141k | None, | 2963 | 141k | &mut s, | 2964 | 141k | local_input); | 2965 | 141k | let _ = mem::replace(&mut s.block_type_length_state.block_type_trees, | 2966 | 141k | new_huffman_table); | 2967 | 141k | match result { | 2968 | 13.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2969 | 128k | _ => break, | 2970 | | } | 2971 | 13.3k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_2; | 2972 | | // No break, continue to next state | 2973 | | } | 2974 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_2 => { | 2975 | 50.8k | let tree_offset = s.loop_counter * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as i32; | 2976 | 50.8k | let mut new_huffman_table = mem::replace(&mut s.block_type_length_state.block_len_trees, | 2977 | 50.8k | AllocHC::AllocatedMemory::default()); | 2978 | 50.8k | result = ReadHuffmanCode(kNumBlockLengthCodes, kNumBlockLengthCodes, | 2979 | 50.8k | new_huffman_table.slice_mut(), | 2980 | 50.8k | tree_offset as usize, | 2981 | 50.8k | None, | 2982 | 50.8k | &mut s, | 2983 | 50.8k | local_input); | 2984 | 50.8k | let _ = mem::replace(&mut s.block_type_length_state.block_len_trees, | 2985 | 50.8k | new_huffman_table); | 2986 | 50.8k | match result { | 2987 | 11.9k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2988 | 38.9k | _ => break, | 2989 | | } | 2990 | 11.9k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_3; | 2991 | | // No break, continue to next state | 2992 | | } | 2993 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_3 => { | 2994 | 29.0k | let tree_offset = s.loop_counter * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as i32; | 2995 | | | 2996 | 29.0k | let mut block_length_out: u32 = 0; | 2997 | | let ind_ret: (bool, u32); | 2998 | | | 2999 | 29.0k | ind_ret = SafeReadBlockLengthIndex(&s.block_type_length_state.substate_read_block_length, | 3000 | 29.0k | s.block_type_length_state.block_length_index, | 3001 | 29.0k | fast_slice!((s.block_type_length_state.block_len_trees) | 3002 | 29.0k | [tree_offset as usize;]), | 3003 | 29.0k | &mut s.br, local_input); | 3004 | | | 3005 | 29.0k | if !SafeReadBlockLengthFromIndex(&mut s.block_type_length_state, | 3006 | 29.0k | &mut s.br, | 3007 | 29.0k | &mut block_length_out, | 3008 | 29.0k | ind_ret, | 3009 | 29.0k | local_input) { | 3010 | 17.4k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 3011 | 17.4k | break; | 3012 | 11.5k | } | 3013 | 11.5k | fast_mut!((s.block_type_length_state.block_length)[s.loop_counter as usize]) = | 3014 | 11.5k | block_length_out; | 3015 | | BROTLI_LOG_UINT!(s.block_type_length_state.block_length[s.loop_counter as usize]); | 3016 | 11.5k | s.loop_counter += 1; | 3017 | 11.5k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0; | 3018 | 11.5k | break; | 3019 | | } | 3020 | | BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER_2 => { | 3021 | 71.8k | let mut bits: u32 = 0; | 3022 | 71.8k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 6, &mut bits, local_input)) { | 3023 | 22.5k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 3024 | 22.5k | break; | 3025 | 49.2k | } | 3026 | 49.2k | s.distance_postfix_bits = bits & bit_reader::BitMask(2); | 3027 | 49.2k | bits >>= 2; | 3028 | 49.2k | s.num_direct_distance_codes = NUM_DISTANCE_SHORT_CODES + | 3029 | 49.2k | (bits << s.distance_postfix_bits); | 3030 | | BROTLI_LOG_UINT!(s.num_direct_distance_codes); | 3031 | | BROTLI_LOG_UINT!(s.distance_postfix_bits); | 3032 | 49.2k | s.distance_postfix_mask = bit_reader::BitMask(s.distance_postfix_bits) as i32; | 3033 | 49.2k | s.context_modes = s.alloc_u8 | 3034 | 49.2k | .alloc_cell(fast!((s.block_type_length_state.num_block_types)[0]) as usize); | 3035 | 49.2k | if (s.context_modes.slice().len() == 0) { | 3036 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES; | 3037 | 0 | break; | 3038 | 49.2k | } | 3039 | 49.2k | s.loop_counter = 0; | 3040 | 49.2k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MODES; | 3041 | | // No break, continue to next state | 3042 | | } | 3043 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MODES => { | 3044 | 53.7k | result = ReadContextModes(&mut s, local_input); | 3045 | 53.7k | match result { | 3046 | 49.2k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3047 | 4.56k | _ => break, | 3048 | | } | 3049 | 49.2k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1; | 3050 | | // No break, continue to next state | 3051 | | } | 3052 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1 => { | 3053 | 112k | result = | 3054 | 112k | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[0]) as usize) << | 3055 | 112k | kLiteralContextBits as usize, | 3056 | 112k | false, | 3057 | 112k | &mut s, | 3058 | 112k | local_input); | 3059 | 112k | match result { | 3060 | 45.6k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3061 | 66.7k | _ => break, | 3062 | | } | 3063 | 45.6k | DetectTrivialLiteralBlockTypes(s); | 3064 | 45.6k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2; | 3065 | | // No break, continue to next state | 3066 | | } | 3067 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2 => { | 3068 | 104k | let num_direct_codes = | 3069 | 104k | s.num_direct_distance_codes - NUM_DISTANCE_SHORT_CODES; | 3070 | 104k | let num_distance_codes = BROTLI_DISTANCE_ALPHABET_SIZE( | 3071 | 104k | s.distance_postfix_bits, num_direct_codes, | 3072 | 104k | (if s.large_window { BROTLI_LARGE_MAX_DISTANCE_BITS } else { | 3073 | 77.9k | BROTLI_MAX_DISTANCE_BITS})); | 3074 | 104k | let max_distance_symbol = if s.large_window { | 3075 | 26.9k | BrotliMaxDistanceSymbol( | 3076 | 26.9k | num_direct_codes, s.distance_postfix_bits) | 3077 | | } else { | 3078 | 77.9k | num_distance_codes | 3079 | | }; | 3080 | 104k | result = | 3081 | 104k | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[2]) as usize) << | 3082 | 104k | kDistanceContextBits as usize, | 3083 | 104k | true, | 3084 | 104k | s, | 3085 | 104k | local_input); | 3086 | 104k | match result { | 3087 | 42.4k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3088 | 62.3k | _ => break, | 3089 | | } | 3090 | 42.4k | s.literal_hgroup.init(&mut s.alloc_u32, | 3091 | 42.4k | &mut s.alloc_hc, | 3092 | | kNumLiteralCodes, | 3093 | | kNumLiteralCodes, | 3094 | 42.4k | s.num_literal_htrees as u16); | 3095 | 42.4k | s.insert_copy_hgroup.init(&mut s.alloc_u32, | 3096 | 42.4k | &mut s.alloc_hc, | 3097 | | kNumInsertAndCopyCodes, | 3098 | | kNumInsertAndCopyCodes, | 3099 | 42.4k | fast!((s.block_type_length_state.num_block_types)[1]) as u16); | 3100 | 42.4k | s.distance_hgroup.init(&mut s.alloc_u32, | 3101 | 42.4k | &mut s.alloc_hc, | 3102 | 42.4k | num_distance_codes as u16, | 3103 | 42.4k | max_distance_symbol as u16, | 3104 | 42.4k | s.num_dist_htrees as u16); | 3105 | 42.4k | if (s.literal_hgroup.codes.slice().len() == 0 || | 3106 | 42.4k | s.insert_copy_hgroup.codes.slice().len() == 0 || | 3107 | 42.4k | s.distance_hgroup.codes.slice().len() == 0) { | 3108 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE); | 3109 | 42.4k | } | 3110 | | | 3111 | | /*{ | 3112 | | let num_distance_codes: u32 = s.num_direct_distance_codes + | 3113 | | (48u32 << s.distance_postfix_bits); | 3114 | | result = | 3115 | | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[2]) as usize) << | 3116 | | kDistanceContextBits as usize, | 3117 | | true, | 3118 | | s, | 3119 | | local_input); | 3120 | | match result { | 3121 | | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3122 | | _ => break, | 3123 | | } | 3124 | | s.literal_hgroup.init(&mut s.alloc_u32, | 3125 | | &mut s.alloc_hc, | 3126 | | kNumLiteralCodes, | 3127 | | s.num_literal_htrees as u16); | 3128 | | s.insert_copy_hgroup.init(&mut s.alloc_u32, | 3129 | | &mut s.alloc_hc, | 3130 | | kNumInsertAndCopyCodes, | 3131 | | fast!((s.block_type_length_state.num_block_types)[1]) as u16); | 3132 | | s.distance_hgroup.init(&mut s.alloc_u32, | 3133 | | &mut s.alloc_hc, | 3134 | | num_distance_codes as u16, | 3135 | | s.num_dist_htrees as u16); | 3136 | | if (s.literal_hgroup.codes.slice().len() == 0 || | 3137 | | s.insert_copy_hgroup.codes.slice().len() == 0 || | 3138 | | s.distance_hgroup.codes.slice().len() == 0) { | 3139 | | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS); | 3140 | | } | 3141 | | }*/ | 3142 | 42.4k | s.loop_counter = 0; | 3143 | 42.4k | s.state = BrotliRunningState::BROTLI_STATE_TREE_GROUP; | 3144 | | // No break, continue to next state | 3145 | | } | 3146 | | BrotliRunningState::BROTLI_STATE_TREE_GROUP => { | 3147 | 160k | result = HuffmanTreeGroupDecode(s.loop_counter, &mut s, local_input); | 3148 | 160k | match result { | 3149 | 85.6k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3150 | 75.2k | _ => break, | 3151 | | } | 3152 | 85.6k | s.loop_counter += 1; | 3153 | 85.6k | if (s.loop_counter >= 3) { | 3154 | 26.1k | PrepareLiteralDecoding(s); | 3155 | 26.1k | s.dist_context_map_slice_index = 0; | 3156 | 26.1k | /* | 3157 | 26.1k | s.context_map_slice_index = 0; | 3158 | 26.1k | let context_mode_index = fast!((s.block_type_length_state.block_type_rb)[1]); | 3159 | 26.1k | let context_mode = fast_slice!((s.context_modes)[context_mode_index as usize]); | 3160 | 26.1k | s.context_lookup = &kContextLookup[context_mode as usize & 3]; | 3161 | 26.1k | */ | 3162 | 26.1k | s.htree_command_index = 0; | 3163 | 26.1k | // look it up each time s.literal_htree=s.literal_hgroup.htrees[s.literal_htree_index]; | 3164 | 26.1k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 3165 | 59.4k | } | 3166 | 85.6k | break; | 3167 | | } | 3168 | | BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN | | 3169 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER | | 3170 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS | | 3171 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY => { | 3172 | 620k | result = ProcessCommands(s, local_input); | 3173 | 620k | if let BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT = result { | 3174 | 506k | result = SafeProcessCommands(s, local_input) | 3175 | 113k | } | 3176 | 620k | break; | 3177 | | } | 3178 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE | | 3179 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1 | | 3180 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2 => { | 3181 | 692k | let (xresult, _) = WriteRingBuffer(&mut available_out, | 3182 | 692k | Some(&mut output), | 3183 | 692k | &mut output_offset, | 3184 | 692k | &mut total_out, | 3185 | 692k | false, | 3186 | 692k | &mut s); | 3187 | 692k | result = xresult; | 3188 | 692k | match result { | 3189 | 308k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3190 | 383k | _ => break, | 3191 | | } | 3192 | 308k | WrapRingBuffer(s); | 3193 | 308k | if s.ringbuffer_size == 1 << s.window_bits { | 3194 | 308k | s.max_distance = s.max_backward_distance; | 3195 | 308k | } | 3196 | 308k | match s.state { | 3197 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1 => { | 3198 | 139k | if (s.meta_block_remaining_len <= 0) { | 3199 | 0 | // Next metablock, if any | 3200 | 0 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 3201 | 139k | } else { | 3202 | 139k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 3203 | 139k | } | 3204 | 139k | break; | 3205 | | } | 3206 | 99.6k | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2 => { | 3207 | 99.6k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; | 3208 | 99.6k | } | 3209 | | _ => { | 3210 | | // BROTLI_STATE_COMMAND_INNER_WRITE | 3211 | 69.5k | if (s.loop_counter == 0) { | 3212 | 2.77k | if (s.meta_block_remaining_len <= 0) { | 3213 | 0 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 3214 | 2.77k | } else { | 3215 | 2.77k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; | 3216 | 2.77k | } | 3217 | 2.77k | break; | 3218 | 66.7k | } | 3219 | 66.7k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 3220 | | } | 3221 | | } | 3222 | 166k | break; | 3223 | | } | 3224 | | BrotliRunningState::BROTLI_STATE_METABLOCK_DONE => { | 3225 | 24.1k | s.BrotliStateCleanupAfterMetablock(); | 3226 | 24.1k | if (s.is_last_metablock == 0) { | 3227 | 11.9k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN; | 3228 | 11.9k | break; | 3229 | 12.1k | } | 3230 | 12.1k | if (!bit_reader::BrotliJumpToByteBoundary(&mut s.br)) { | 3231 | 1.54k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_PADDING_2; | 3232 | 10.5k | } | 3233 | 12.1k | if (s.buffer_length == 0) { | 3234 | 11.6k | bit_reader::BrotliBitReaderUnload(&mut s.br); | 3235 | 11.6k | *available_in = s.br.avail_in as usize; | 3236 | 11.6k | *input_offset = s.br.next_in as usize; | 3237 | 11.6k | } | 3238 | 12.1k | s.state = BrotliRunningState::BROTLI_STATE_DONE; | 3239 | | // No break, continue to next state | 3240 | | } | 3241 | | BrotliRunningState::BROTLI_STATE_DONE => { | 3242 | 217k | if (s.ringbuffer.slice().len() != 0) { | 3243 | 214k | let (xresult, _) = WriteRingBuffer(&mut available_out, | 3244 | 214k | Some(&mut output), | 3245 | 214k | &mut output_offset, | 3246 | 214k | &mut total_out, | 3247 | 214k | true, | 3248 | 214k | &mut s); | 3249 | 214k | result = xresult; | 3250 | 214k | match result { | 3251 | 24.5k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3252 | 189k | _ => break, | 3253 | | } | 3254 | 2.89k | } | 3255 | 27.4k | return SaveErrorCode!(s, result); | 3256 | | } | 3257 | | } | 3258 | | } | 3259 | | } | 3260 | | | 3261 | 1.79M | SaveErrorCode!(s, result) | 3262 | 1.82M | } |
Unexecuted instantiation: brotli_decompressor::decode::BrotliDecompressStream::<alloc_no_stdlib::stack_allocator::StackAllocator<u8, brotli_decompressor::MemPool<u8>>, alloc_no_stdlib::stack_allocator::StackAllocator<u32, brotli_decompressor::MemPool<u32>>, alloc_no_stdlib::stack_allocator::StackAllocator<brotli_decompressor::huffman::HuffmanCode, brotli_decompressor::MemPool<brotli_decompressor::huffman::HuffmanCode>>> Unexecuted instantiation: brotli_decompressor::decode::BrotliDecompressStream::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> brotli_decompressor::decode::BrotliDecompressStream::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2664 | 223k | pub fn BrotliDecompressStream<AllocU8: alloc::Allocator<u8>, | 2665 | 223k | AllocU32: alloc::Allocator<u32>, | 2666 | 223k | AllocHC: alloc::Allocator<HuffmanCode>> | 2667 | 223k | (available_in: &mut usize, | 2668 | 223k | input_offset: &mut usize, | 2669 | 223k | xinput: &[u8], | 2670 | 223k | mut available_out: &mut usize, | 2671 | 223k | mut output_offset: &mut usize, | 2672 | 223k | mut output: &mut [u8], | 2673 | 223k | mut total_out: &mut usize, | 2674 | 223k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) | 2675 | 223k | -> BrotliResult { | 2676 | | | 2677 | 223k | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2678 | | | 2679 | 223k | let mut saved_buffer: [u8; 8] = s.buffer; | 2680 | | let mut local_input: &[u8]; | 2681 | 223k | if is_fatal(s.error_code) { | 2682 | 18.4k | return BrotliResult::ResultFailure; | 2683 | 205k | } | 2684 | 205k | if *available_in as u64 >= (1u64 << 32) { | 2685 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2686 | 205k | } | 2687 | 205k | if *input_offset as u64 >= (1u64 << 32) { | 2688 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2689 | 205k | } | 2690 | 205k | if *input_offset + *available_in > xinput.len() { | 2691 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2692 | 205k | } | 2693 | 205k | if *output_offset + *available_out > output.len() { | 2694 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2695 | 205k | } | 2696 | 205k | if s.buffer_length == 0 { | 2697 | 203k | local_input = xinput; | 2698 | 203k | s.br.avail_in = *available_in as u32; | 2699 | 203k | s.br.next_in = *input_offset as u32; | 2700 | 203k | } else { | 2701 | 1.77k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2702 | 1.77k | let copy_len = core::cmp::min(saved_buffer.len() - s.buffer_length as usize, *available_in); | 2703 | 1.77k | if copy_len > 0 { | 2704 | 1.68k | fast_mut!((saved_buffer)[s.buffer_length as usize ; (s.buffer_length as usize + copy_len)]) | 2705 | 1.68k | .clone_from_slice(fast!((xinput)[*input_offset ; copy_len + *input_offset])); | 2706 | 1.68k | fast_mut!((s.buffer)[s.buffer_length as usize ; (s.buffer_length as usize + copy_len)]) | 2707 | 1.68k | .clone_from_slice(fast!((xinput)[*input_offset ; copy_len + *input_offset])); | 2708 | 1.68k | } | 2709 | 1.77k | local_input = &saved_buffer[..]; | 2710 | 1.77k | s.br.next_in = 0; | 2711 | | } | 2712 | | loop { | 2713 | 550k | match result { | 2714 | 350k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2715 | | _ => { | 2716 | 199k | match result { | 2717 | | BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT => { | 2718 | 113k | if s.ringbuffer.slice().len() != 0 { | 2719 | 105k | let (intermediate_result, _) = WriteRingBuffer(available_out, | 2720 | 105k | Some(&mut output), | 2721 | 105k | &mut output_offset, | 2722 | 105k | &mut total_out, | 2723 | 105k | true, | 2724 | 105k | &mut s); | 2725 | 105k | if is_fatal(intermediate_result) { | 2726 | 844 | result = intermediate_result; | 2727 | 844 | break; | 2728 | 104k | } | 2729 | 7.74k | } | 2730 | 112k | if s.buffer_length != 0 { | 2731 | | // Used with internal buffer. | 2732 | 3.01k | if s.br.avail_in == 0 { | 2733 | | // Successfully finished read transaction. | 2734 | | // Accamulator contains less than 8 bits, because internal buffer | 2735 | | // is expanded byte-by-byte until it is enough to complete read. | 2736 | 1.03k | s.buffer_length = 0; | 2737 | | // Switch to input stream and restart. | 2738 | 1.03k | result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2739 | 1.03k | local_input = xinput; | 2740 | 1.03k | s.br.avail_in = *available_in as u32; | 2741 | 1.03k | s.br.next_in = *input_offset as u32; | 2742 | 1.03k | continue; | 2743 | 1.97k | } else if *available_in != 0 { | 2744 | | // Not enough data in buffer, but can take one more byte from | 2745 | | // input stream. | 2746 | 1.88k | result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2747 | 1.88k | let new_byte = fast!((xinput)[*input_offset]); | 2748 | 1.88k | fast_mut!((s.buffer)[s.buffer_length as usize]) = new_byte; | 2749 | | // we did the following copy upfront, so we wouldn't have to do it here | 2750 | | // since saved_buffer[s.buffer_length as usize] = new_byte violates borrow rules | 2751 | 1.88k | assert_eq!(fast!((saved_buffer)[s.buffer_length as usize]), new_byte); | 2752 | 1.88k | s.buffer_length += 1; | 2753 | 1.88k | s.br.avail_in = s.buffer_length; | 2754 | 1.88k | (*input_offset) += 1; | 2755 | 1.88k | (*available_in) -= 1; | 2756 | | // Retry with more data in buffer. | 2757 | | // we can't re-borrow the saved buffer...so we have to do this recursively | 2758 | 1.88k | continue; | 2759 | 87 | } | 2760 | | // Can't finish reading and no more input. | 2761 | | | 2762 | | // FIXME :: NOT SURE WHAT THIS MEANT | 2763 | | // saved_buffer = core::mem::replace( | 2764 | | // &mut s.br.input_, | 2765 | | // &mut[]); // clear input | 2766 | 87 | break; | 2767 | | } else { | 2768 | | // Input stream doesn't contain enough input. | 2769 | | // Copy tail to internal buffer and return. | 2770 | 109k | *input_offset = s.br.next_in as usize; | 2771 | 109k | *available_in = s.br.avail_in as usize; | 2772 | 112k | while *available_in != 0 { | 2773 | 2.75k | fast_mut!((s.buffer)[s.buffer_length as usize]) = fast!((xinput)[*input_offset]); | 2774 | 2.75k | s.buffer_length += 1; | 2775 | 2.75k | (*input_offset) += 1; | 2776 | 2.75k | (*available_in) -= 1; | 2777 | 2.75k | } | 2778 | 109k | break; | 2779 | | } | 2780 | | // unreachable!(); <- dead code | 2781 | | } | 2782 | | _ => { | 2783 | | // Fail or needs more output. | 2784 | 86.5k | if s.buffer_length != 0 { | 2785 | 96 | // Just consumed the buffered input and produced some output. Otherwise | 2786 | 96 | // it would result in "needs more input". Reset internal buffer. | 2787 | 96 | s.buffer_length = 0; | 2788 | 86.4k | } else { | 2789 | 86.4k | // Using input stream in last iteration. When decoder switches to input | 2790 | 86.4k | // stream it has less than 8 bits in accamulator, so it is safe to | 2791 | 86.4k | // return unused accamulator bits there. | 2792 | 86.4k | bit_reader::BrotliBitReaderUnload(&mut s.br); | 2793 | 86.4k | *available_in = s.br.avail_in as usize; | 2794 | 86.4k | *input_offset = s.br.next_in as usize; | 2795 | 86.4k | } | 2796 | | } | 2797 | | } | 2798 | 86.5k | break; | 2799 | | } | 2800 | | } | 2801 | | loop { | 2802 | | // this emulates fallthrough behavior | 2803 | 547k | match s.state { | 2804 | | BrotliRunningState::BROTLI_STATE_UNINITED => { | 2805 | | // Prepare to the first read. | 2806 | 29.0k | if (!bit_reader::BrotliWarmupBitReader(&mut s.br, local_input)) { | 2807 | 661 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2808 | 661 | break; | 2809 | 28.4k | } | 2810 | | // Decode window size. | 2811 | | /* Reads 1..8 bits. */ | 2812 | 28.4k | result = DecodeWindowBits(&mut s.large_window, &mut s.window_bits, &mut s.br); | 2813 | 28.4k | match result { | 2814 | 28.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2815 | 67 | _ => break, | 2816 | | } | 2817 | 28.3k | if s.large_window { | 2818 | 681 | s.state = BrotliRunningState::BROTLI_STATE_LARGE_WINDOW_BITS; | 2819 | 27.6k | } else { | 2820 | 27.6k | s.state = BrotliRunningState::BROTLI_STATE_INITIALIZE; | 2821 | 27.6k | } | 2822 | | } | 2823 | | BrotliRunningState::BROTLI_STATE_LARGE_WINDOW_BITS => { | 2824 | 683 | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 6, &mut s.window_bits, local_input)) { | 2825 | 3 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2826 | 3 | break; | 2827 | 680 | } | 2828 | 680 | if (s.window_bits < kBrotliLargeMinWbits || | 2829 | 679 | s.window_bits > kBrotliLargeMaxWbits) { | 2830 | 70 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; | 2831 | 70 | break; | 2832 | 610 | } | 2833 | 610 | s.state = BrotliRunningState::BROTLI_STATE_INITIALIZE; | 2834 | | } | 2835 | | BrotliRunningState::BROTLI_STATE_INITIALIZE => { | 2836 | 28.2k | s.max_backward_distance = (1 << s.window_bits) - kBrotliWindowGap as i32; | 2837 | 28.2k | s.max_backward_distance_minus_custom_dict_size = (s.max_backward_distance as isize - | 2838 | 28.2k | s.custom_dict_size) as i32; | 2839 | | | 2840 | | // (formerly) Allocate memory for both block_type_trees and block_len_trees. | 2841 | 28.2k | s.block_type_length_state.block_type_trees = s.alloc_hc | 2842 | 28.2k | .alloc_cell(3 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize); | 2843 | 28.2k | if (s.block_type_length_state.block_type_trees.slice().len() == 0) { | 2844 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES; | 2845 | 0 | break; | 2846 | 28.2k | } | 2847 | 28.2k | s.block_type_length_state.block_len_trees = s.alloc_hc | 2848 | 28.2k | .alloc_cell(3 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize); | 2849 | | | 2850 | 28.2k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN; | 2851 | | // No break, continue to next state | 2852 | | } | 2853 | 31.2k | BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN => { | 2854 | 31.2k | s.BrotliStateMetablockBegin(); | 2855 | 31.2k | BROTLI_LOG_UINT!(s.pos); | 2856 | 31.2k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER; | 2857 | 31.2k | // No break, continue to next state | 2858 | 31.2k | } | 2859 | | BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER => { | 2860 | 34.8k | result = DecodeMetaBlockLength(&mut s, local_input); // Reads 2 - 31 bits. | 2861 | 34.8k | match result { | 2862 | 28.9k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2863 | 5.91k | _ => break, | 2864 | | } | 2865 | | BROTLI_LOG_UINT!(s.is_last_metablock); | 2866 | | BROTLI_LOG_UINT!(s.meta_block_remaining_len); | 2867 | | BROTLI_LOG_UINT!(s.is_metadata); | 2868 | | BROTLI_LOG_UINT!(s.is_uncompressed); | 2869 | 28.9k | if (s.is_metadata != 0 || s.is_uncompressed != 0) && | 2870 | 4.22k | !bit_reader::BrotliJumpToByteBoundary(&mut s.br) { | 2871 | 866 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_PADDING_2; | 2872 | 866 | break; | 2873 | 28.0k | } | 2874 | 28.0k | if s.is_metadata != 0 { | 2875 | 1.82k | s.state = BrotliRunningState::BROTLI_STATE_METADATA; | 2876 | 1.82k | break; | 2877 | 26.2k | } | 2878 | 26.2k | if s.meta_block_remaining_len == 0 { | 2879 | 1.54k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2880 | 1.54k | break; | 2881 | 24.6k | } | 2882 | 24.6k | if s.ringbuffer.slice().len() == 0 && !BrotliAllocateRingBuffer(&mut s, local_input) { | 2883 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2; | 2884 | 0 | break; | 2885 | 24.6k | } | 2886 | 24.6k | if s.is_uncompressed != 0 { | 2887 | 1.53k | s.state = BrotliRunningState::BROTLI_STATE_UNCOMPRESSED; | 2888 | 1.53k | break; | 2889 | 23.1k | } | 2890 | 23.1k | s.loop_counter = 0; | 2891 | 23.1k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0; | 2892 | 23.1k | break; | 2893 | | } | 2894 | | BrotliRunningState::BROTLI_STATE_UNCOMPRESSED => { | 2895 | 12.2k | let mut _bytes_copied = s.meta_block_remaining_len; | 2896 | 12.2k | result = CopyUncompressedBlockToOutput(&mut available_out, | 2897 | 12.2k | &mut output, | 2898 | 12.2k | &mut output_offset, | 2899 | 12.2k | &mut total_out, | 2900 | 12.2k | &mut s, | 2901 | 12.2k | local_input); | 2902 | 12.2k | _bytes_copied -= s.meta_block_remaining_len; | 2903 | 12.2k | match result { | 2904 | 438 | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2905 | 11.8k | _ => break, | 2906 | | } | 2907 | 438 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2908 | 438 | break; | 2909 | | } | 2910 | | BrotliRunningState::BROTLI_STATE_METADATA => { | 2911 | 35.1k | while s.meta_block_remaining_len > 0 { | 2912 | 33.6k | let mut bits = 0u32; | 2913 | | // Read one byte and ignore it. | 2914 | 33.6k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 8, &mut bits, local_input) { | 2915 | 3.04k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2916 | 3.04k | break; | 2917 | 30.6k | } | 2918 | 30.6k | s.meta_block_remaining_len -= 1; | 2919 | | } | 2920 | 4.52k | if let BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS = result { | 2921 | 1.48k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE | 2922 | 3.04k | } | 2923 | 4.52k | break; | 2924 | | } | 2925 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0 => { | 2926 | 83.5k | if s.loop_counter >= 3 { | 2927 | 17.0k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER_2; | 2928 | 17.0k | break; | 2929 | 66.5k | } | 2930 | | // Reads 1..11 bits. | 2931 | 66.5k | { | 2932 | 66.5k | let index = s.loop_counter as usize; | 2933 | 66.5k | result = | 2934 | 66.5k | DecodeVarLenUint8(&mut s.substate_decode_uint8, | 2935 | 66.5k | &mut s.br, | 2936 | 66.5k | &mut fast_mut!((s.block_type_length_state.num_block_types)[index]), | 2937 | 66.5k | local_input); | 2938 | 66.5k | } | 2939 | 66.5k | match result { | 2940 | 62.0k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2941 | 4.45k | _ => break, | 2942 | | } | 2943 | 62.0k | fast_mut!((s.block_type_length_state.num_block_types)[s.loop_counter as usize]) += 1; | 2944 | | BROTLI_LOG_UINT!(s.block_type_length_state.num_block_types[s.loop_counter as usize]); | 2945 | 62.0k | if fast!((s.block_type_length_state.num_block_types)[s.loop_counter as usize]) < 2 { | 2946 | 43.8k | s.loop_counter += 1; | 2947 | 43.8k | break; | 2948 | 18.2k | } | 2949 | 18.2k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_1; | 2950 | | // No break, continue to next state | 2951 | | } | 2952 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_1 => { | 2953 | 24.3k | let tree_offset = s.loop_counter as u32 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as u32; | 2954 | 24.3k | let mut new_huffman_table = mem::replace(&mut s.block_type_length_state.block_type_trees, | 2955 | 24.3k | AllocHC::AllocatedMemory::default()); | 2956 | 24.3k | let loop_counter = s.loop_counter as usize; | 2957 | 24.3k | let alphabet_size = fast!((s.block_type_length_state.num_block_types)[loop_counter]) + 2; | 2958 | 24.3k | result = | 2959 | 24.3k | ReadHuffmanCode(alphabet_size, alphabet_size, | 2960 | 24.3k | new_huffman_table.slice_mut(), | 2961 | 24.3k | tree_offset as usize, | 2962 | 24.3k | None, | 2963 | 24.3k | &mut s, | 2964 | 24.3k | local_input); | 2965 | 24.3k | let _ = mem::replace(&mut s.block_type_length_state.block_type_trees, | 2966 | 24.3k | new_huffman_table); | 2967 | 24.3k | match result { | 2968 | 14.7k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2969 | 9.65k | _ => break, | 2970 | | } | 2971 | 14.7k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_2; | 2972 | | // No break, continue to next state | 2973 | | } | 2974 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_2 => { | 2975 | 17.7k | let tree_offset = s.loop_counter * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as i32; | 2976 | 17.7k | let mut new_huffman_table = mem::replace(&mut s.block_type_length_state.block_len_trees, | 2977 | 17.7k | AllocHC::AllocatedMemory::default()); | 2978 | 17.7k | result = ReadHuffmanCode(kNumBlockLengthCodes, kNumBlockLengthCodes, | 2979 | 17.7k | new_huffman_table.slice_mut(), | 2980 | 17.7k | tree_offset as usize, | 2981 | 17.7k | None, | 2982 | 17.7k | &mut s, | 2983 | 17.7k | local_input); | 2984 | 17.7k | let _ = mem::replace(&mut s.block_type_length_state.block_len_trees, | 2985 | 17.7k | new_huffman_table); | 2986 | 17.7k | match result { | 2987 | 12.6k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2988 | 5.10k | _ => break, | 2989 | | } | 2990 | 12.6k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_3; | 2991 | | // No break, continue to next state | 2992 | | } | 2993 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_3 => { | 2994 | 14.4k | let tree_offset = s.loop_counter * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as i32; | 2995 | | | 2996 | 14.4k | let mut block_length_out: u32 = 0; | 2997 | | let ind_ret: (bool, u32); | 2998 | | | 2999 | 14.4k | ind_ret = SafeReadBlockLengthIndex(&s.block_type_length_state.substate_read_block_length, | 3000 | 14.4k | s.block_type_length_state.block_length_index, | 3001 | 14.4k | fast_slice!((s.block_type_length_state.block_len_trees) | 3002 | 14.4k | [tree_offset as usize;]), | 3003 | 14.4k | &mut s.br, local_input); | 3004 | | | 3005 | 14.4k | if !SafeReadBlockLengthFromIndex(&mut s.block_type_length_state, | 3006 | 14.4k | &mut s.br, | 3007 | 14.4k | &mut block_length_out, | 3008 | 14.4k | ind_ret, | 3009 | 14.4k | local_input) { | 3010 | 2.25k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 3011 | 2.25k | break; | 3012 | 12.1k | } | 3013 | 12.1k | fast_mut!((s.block_type_length_state.block_length)[s.loop_counter as usize]) = | 3014 | 12.1k | block_length_out; | 3015 | | BROTLI_LOG_UINT!(s.block_type_length_state.block_length[s.loop_counter as usize]); | 3016 | 12.1k | s.loop_counter += 1; | 3017 | 12.1k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0; | 3018 | 12.1k | break; | 3019 | | } | 3020 | | BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER_2 => { | 3021 | 18.5k | let mut bits: u32 = 0; | 3022 | 18.5k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 6, &mut bits, local_input)) { | 3023 | 1.55k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 3024 | 1.55k | break; | 3025 | 16.9k | } | 3026 | 16.9k | s.distance_postfix_bits = bits & bit_reader::BitMask(2); | 3027 | 16.9k | bits >>= 2; | 3028 | 16.9k | s.num_direct_distance_codes = NUM_DISTANCE_SHORT_CODES + | 3029 | 16.9k | (bits << s.distance_postfix_bits); | 3030 | | BROTLI_LOG_UINT!(s.num_direct_distance_codes); | 3031 | | BROTLI_LOG_UINT!(s.distance_postfix_bits); | 3032 | 16.9k | s.distance_postfix_mask = bit_reader::BitMask(s.distance_postfix_bits) as i32; | 3033 | 16.9k | s.context_modes = s.alloc_u8 | 3034 | 16.9k | .alloc_cell(fast!((s.block_type_length_state.num_block_types)[0]) as usize); | 3035 | 16.9k | if (s.context_modes.slice().len() == 0) { | 3036 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES; | 3037 | 0 | break; | 3038 | 16.9k | } | 3039 | 16.9k | s.loop_counter = 0; | 3040 | 16.9k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MODES; | 3041 | | // No break, continue to next state | 3042 | | } | 3043 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MODES => { | 3044 | 18.6k | result = ReadContextModes(&mut s, local_input); | 3045 | 18.6k | match result { | 3046 | 16.8k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3047 | 1.81k | _ => break, | 3048 | | } | 3049 | 16.8k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1; | 3050 | | // No break, continue to next state | 3051 | | } | 3052 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1 => { | 3053 | 29.1k | result = | 3054 | 29.1k | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[0]) as usize) << | 3055 | 29.1k | kLiteralContextBits as usize, | 3056 | 29.1k | false, | 3057 | 29.1k | &mut s, | 3058 | 29.1k | local_input); | 3059 | 29.1k | match result { | 3060 | 14.3k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3061 | 14.8k | _ => break, | 3062 | | } | 3063 | 14.3k | DetectTrivialLiteralBlockTypes(s); | 3064 | 14.3k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2; | 3065 | | // No break, continue to next state | 3066 | | } | 3067 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2 => { | 3068 | 17.0k | let num_direct_codes = | 3069 | 17.0k | s.num_direct_distance_codes - NUM_DISTANCE_SHORT_CODES; | 3070 | 17.0k | let num_distance_codes = BROTLI_DISTANCE_ALPHABET_SIZE( | 3071 | 17.0k | s.distance_postfix_bits, num_direct_codes, | 3072 | 17.0k | (if s.large_window { BROTLI_LARGE_MAX_DISTANCE_BITS } else { | 3073 | 16.6k | BROTLI_MAX_DISTANCE_BITS})); | 3074 | 17.0k | let max_distance_symbol = if s.large_window { | 3075 | 438 | BrotliMaxDistanceSymbol( | 3076 | 438 | num_direct_codes, s.distance_postfix_bits) | 3077 | | } else { | 3078 | 16.6k | num_distance_codes | 3079 | | }; | 3080 | 17.0k | result = | 3081 | 17.0k | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[2]) as usize) << | 3082 | 17.0k | kDistanceContextBits as usize, | 3083 | 17.0k | true, | 3084 | 17.0k | s, | 3085 | 17.0k | local_input); | 3086 | 17.0k | match result { | 3087 | 12.7k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3088 | 4.30k | _ => break, | 3089 | | } | 3090 | 12.7k | s.literal_hgroup.init(&mut s.alloc_u32, | 3091 | 12.7k | &mut s.alloc_hc, | 3092 | | kNumLiteralCodes, | 3093 | | kNumLiteralCodes, | 3094 | 12.7k | s.num_literal_htrees as u16); | 3095 | 12.7k | s.insert_copy_hgroup.init(&mut s.alloc_u32, | 3096 | 12.7k | &mut s.alloc_hc, | 3097 | | kNumInsertAndCopyCodes, | 3098 | | kNumInsertAndCopyCodes, | 3099 | 12.7k | fast!((s.block_type_length_state.num_block_types)[1]) as u16); | 3100 | 12.7k | s.distance_hgroup.init(&mut s.alloc_u32, | 3101 | 12.7k | &mut s.alloc_hc, | 3102 | 12.7k | num_distance_codes as u16, | 3103 | 12.7k | max_distance_symbol as u16, | 3104 | 12.7k | s.num_dist_htrees as u16); | 3105 | 12.7k | if (s.literal_hgroup.codes.slice().len() == 0 || | 3106 | 12.7k | s.insert_copy_hgroup.codes.slice().len() == 0 || | 3107 | 12.7k | s.distance_hgroup.codes.slice().len() == 0) { | 3108 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE); | 3109 | 12.7k | } | 3110 | | | 3111 | | /*{ | 3112 | | let num_distance_codes: u32 = s.num_direct_distance_codes + | 3113 | | (48u32 << s.distance_postfix_bits); | 3114 | | result = | 3115 | | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[2]) as usize) << | 3116 | | kDistanceContextBits as usize, | 3117 | | true, | 3118 | | s, | 3119 | | local_input); | 3120 | | match result { | 3121 | | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3122 | | _ => break, | 3123 | | } | 3124 | | s.literal_hgroup.init(&mut s.alloc_u32, | 3125 | | &mut s.alloc_hc, | 3126 | | kNumLiteralCodes, | 3127 | | s.num_literal_htrees as u16); | 3128 | | s.insert_copy_hgroup.init(&mut s.alloc_u32, | 3129 | | &mut s.alloc_hc, | 3130 | | kNumInsertAndCopyCodes, | 3131 | | fast!((s.block_type_length_state.num_block_types)[1]) as u16); | 3132 | | s.distance_hgroup.init(&mut s.alloc_u32, | 3133 | | &mut s.alloc_hc, | 3134 | | num_distance_codes as u16, | 3135 | | s.num_dist_htrees as u16); | 3136 | | if (s.literal_hgroup.codes.slice().len() == 0 || | 3137 | | s.insert_copy_hgroup.codes.slice().len() == 0 || | 3138 | | s.distance_hgroup.codes.slice().len() == 0) { | 3139 | | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS); | 3140 | | } | 3141 | | }*/ | 3142 | 12.7k | s.loop_counter = 0; | 3143 | 12.7k | s.state = BrotliRunningState::BROTLI_STATE_TREE_GROUP; | 3144 | | // No break, continue to next state | 3145 | | } | 3146 | | BrotliRunningState::BROTLI_STATE_TREE_GROUP => { | 3147 | 46.3k | result = HuffmanTreeGroupDecode(s.loop_counter, &mut s, local_input); | 3148 | 46.3k | match result { | 3149 | 21.7k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3150 | 24.5k | _ => break, | 3151 | | } | 3152 | 21.7k | s.loop_counter += 1; | 3153 | 21.7k | if (s.loop_counter >= 3) { | 3154 | 6.32k | PrepareLiteralDecoding(s); | 3155 | 6.32k | s.dist_context_map_slice_index = 0; | 3156 | 6.32k | /* | 3157 | 6.32k | s.context_map_slice_index = 0; | 3158 | 6.32k | let context_mode_index = fast!((s.block_type_length_state.block_type_rb)[1]); | 3159 | 6.32k | let context_mode = fast_slice!((s.context_modes)[context_mode_index as usize]); | 3160 | 6.32k | s.context_lookup = &kContextLookup[context_mode as usize & 3]; | 3161 | 6.32k | */ | 3162 | 6.32k | s.htree_command_index = 0; | 3163 | 6.32k | // look it up each time s.literal_htree=s.literal_hgroup.htrees[s.literal_htree_index]; | 3164 | 6.32k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 3165 | 15.4k | } | 3166 | 21.7k | break; | 3167 | | } | 3168 | | BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN | | 3169 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER | | 3170 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS | | 3171 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY => { | 3172 | 49.7k | result = ProcessCommands(s, local_input); | 3173 | 49.7k | if let BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT = result { | 3174 | 41.9k | result = SafeProcessCommands(s, local_input) | 3175 | 7.79k | } | 3176 | 49.7k | break; | 3177 | | } | 3178 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE | | 3179 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1 | | 3180 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2 => { | 3181 | 67.3k | let (xresult, _) = WriteRingBuffer(&mut available_out, | 3182 | 67.3k | Some(&mut output), | 3183 | 67.3k | &mut output_offset, | 3184 | 67.3k | &mut total_out, | 3185 | 67.3k | false, | 3186 | 67.3k | &mut s); | 3187 | 67.3k | result = xresult; | 3188 | 67.3k | match result { | 3189 | 7.65k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3190 | 59.6k | _ => break, | 3191 | | } | 3192 | 7.65k | WrapRingBuffer(s); | 3193 | 7.65k | if s.ringbuffer_size == 1 << s.window_bits { | 3194 | 7.65k | s.max_distance = s.max_backward_distance; | 3195 | 7.65k | } | 3196 | 7.65k | match s.state { | 3197 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1 => { | 3198 | 0 | if (s.meta_block_remaining_len <= 0) { | 3199 | 0 | // Next metablock, if any | 3200 | 0 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 3201 | 0 | } else { | 3202 | 0 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 3203 | 0 | } | 3204 | 0 | break; | 3205 | | } | 3206 | 5.05k | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2 => { | 3207 | 5.05k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; | 3208 | 5.05k | } | 3209 | | _ => { | 3210 | | // BROTLI_STATE_COMMAND_INNER_WRITE | 3211 | 2.59k | if (s.loop_counter == 0) { | 3212 | 68 | if (s.meta_block_remaining_len <= 0) { | 3213 | 0 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 3214 | 68 | } else { | 3215 | 68 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; | 3216 | 68 | } | 3217 | 68 | break; | 3218 | 2.53k | } | 3219 | 2.53k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 3220 | | } | 3221 | | } | 3222 | 7.59k | break; | 3223 | | } | 3224 | | BrotliRunningState::BROTLI_STATE_METABLOCK_DONE => { | 3225 | 4.59k | s.BrotliStateCleanupAfterMetablock(); | 3226 | 4.59k | if (s.is_last_metablock == 0) { | 3227 | 2.93k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN; | 3228 | 2.93k | break; | 3229 | 1.66k | } | 3230 | 1.66k | if (!bit_reader::BrotliJumpToByteBoundary(&mut s.br)) { | 3231 | 1.18k | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_PADDING_2; | 3232 | 1.18k | } | 3233 | 1.66k | if (s.buffer_length == 0) { | 3234 | 1.64k | bit_reader::BrotliBitReaderUnload(&mut s.br); | 3235 | 1.64k | *available_in = s.br.avail_in as usize; | 3236 | 1.64k | *input_offset = s.br.next_in as usize; | 3237 | 1.64k | } | 3238 | 1.66k | s.state = BrotliRunningState::BROTLI_STATE_DONE; | 3239 | | // No break, continue to next state | 3240 | | } | 3241 | | BrotliRunningState::BROTLI_STATE_DONE => { | 3242 | 15.1k | if (s.ringbuffer.slice().len() != 0) { | 3243 | 9.19k | let (xresult, _) = WriteRingBuffer(&mut available_out, | 3244 | 9.19k | Some(&mut output), | 3245 | 9.19k | &mut output_offset, | 3246 | 9.19k | &mut total_out, | 3247 | 9.19k | true, | 3248 | 9.19k | &mut s); | 3249 | 9.19k | result = xresult; | 3250 | 9.19k | match result { | 3251 | 2.44k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3252 | 6.74k | _ => break, | 3253 | | } | 3254 | 5.96k | } | 3255 | 8.41k | return SaveErrorCode!(s, result); | 3256 | | } | 3257 | | } | 3258 | | } | 3259 | | } | 3260 | | | 3261 | 196k | SaveErrorCode!(s, result) | 3262 | 223k | } |
brotli_decompressor::decode::BrotliDecompressStream::<alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc, alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 2664 | 505k | pub fn BrotliDecompressStream<AllocU8: alloc::Allocator<u8>, | 2665 | 505k | AllocU32: alloc::Allocator<u32>, | 2666 | 505k | AllocHC: alloc::Allocator<HuffmanCode>> | 2667 | 505k | (available_in: &mut usize, | 2668 | 505k | input_offset: &mut usize, | 2669 | 505k | xinput: &[u8], | 2670 | 505k | mut available_out: &mut usize, | 2671 | 505k | mut output_offset: &mut usize, | 2672 | 505k | mut output: &mut [u8], | 2673 | 505k | mut total_out: &mut usize, | 2674 | 505k | mut s: &mut BrotliState<AllocU8, AllocU32, AllocHC>) | 2675 | 505k | -> BrotliResult { | 2676 | | | 2677 | 505k | let mut result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2678 | | | 2679 | 505k | let mut saved_buffer: [u8; 8] = s.buffer; | 2680 | | let mut local_input: &[u8]; | 2681 | 505k | if is_fatal(s.error_code) { | 2682 | 0 | return BrotliResult::ResultFailure; | 2683 | 505k | } | 2684 | 505k | if *available_in as u64 >= (1u64 << 32) { | 2685 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2686 | 505k | } | 2687 | 505k | if *input_offset as u64 >= (1u64 << 32) { | 2688 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2689 | 505k | } | 2690 | 505k | if *input_offset + *available_in > xinput.len() { | 2691 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2692 | 505k | } | 2693 | 505k | if *output_offset + *available_out > output.len() { | 2694 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); | 2695 | 505k | } | 2696 | 505k | if s.buffer_length == 0 { | 2697 | 497k | local_input = xinput; | 2698 | 497k | s.br.avail_in = *available_in as u32; | 2699 | 497k | s.br.next_in = *input_offset as u32; | 2700 | 497k | } else { | 2701 | 7.78k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2702 | 7.78k | let copy_len = core::cmp::min(saved_buffer.len() - s.buffer_length as usize, *available_in); | 2703 | 7.78k | if copy_len > 0 { | 2704 | 1.06k | fast_mut!((saved_buffer)[s.buffer_length as usize ; (s.buffer_length as usize + copy_len)]) | 2705 | 1.06k | .clone_from_slice(fast!((xinput)[*input_offset ; copy_len + *input_offset])); | 2706 | 1.06k | fast_mut!((s.buffer)[s.buffer_length as usize ; (s.buffer_length as usize + copy_len)]) | 2707 | 1.06k | .clone_from_slice(fast!((xinput)[*input_offset ; copy_len + *input_offset])); | 2708 | 6.72k | } | 2709 | 7.78k | local_input = &saved_buffer[..]; | 2710 | 7.78k | s.br.next_in = 0; | 2711 | | } | 2712 | | loop { | 2713 | 1.18M | match result { | 2714 | 681k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2715 | | _ => { | 2716 | 499k | match result { | 2717 | | BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT => { | 2718 | 296k | if s.ringbuffer.slice().len() != 0 { | 2719 | 267k | let (intermediate_result, _) = WriteRingBuffer(available_out, | 2720 | 267k | Some(&mut output), | 2721 | 267k | &mut output_offset, | 2722 | 267k | &mut total_out, | 2723 | 267k | true, | 2724 | 267k | &mut s); | 2725 | 267k | if is_fatal(intermediate_result) { | 2726 | 348 | result = intermediate_result; | 2727 | 348 | break; | 2728 | 266k | } | 2729 | 29.3k | } | 2730 | 295k | if s.buffer_length != 0 { | 2731 | | // Used with internal buffer. | 2732 | 8.61k | if s.br.avail_in == 0 { | 2733 | | // Successfully finished read transaction. | 2734 | | // Accamulator contains less than 8 bits, because internal buffer | 2735 | | // is expanded byte-by-byte until it is enough to complete read. | 2736 | 790 | s.buffer_length = 0; | 2737 | | // Switch to input stream and restart. | 2738 | 790 | result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2739 | 790 | local_input = xinput; | 2740 | 790 | s.br.avail_in = *available_in as u32; | 2741 | 790 | s.br.next_in = *input_offset as u32; | 2742 | 790 | continue; | 2743 | 7.82k | } else if *available_in != 0 { | 2744 | | // Not enough data in buffer, but can take one more byte from | 2745 | | // input stream. | 2746 | 1.07k | result = BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS; | 2747 | 1.07k | let new_byte = fast!((xinput)[*input_offset]); | 2748 | 1.07k | fast_mut!((s.buffer)[s.buffer_length as usize]) = new_byte; | 2749 | | // we did the following copy upfront, so we wouldn't have to do it here | 2750 | | // since saved_buffer[s.buffer_length as usize] = new_byte violates borrow rules | 2751 | 1.07k | assert_eq!(fast!((saved_buffer)[s.buffer_length as usize]), new_byte); | 2752 | 1.07k | s.buffer_length += 1; | 2753 | 1.07k | s.br.avail_in = s.buffer_length; | 2754 | 1.07k | (*input_offset) += 1; | 2755 | 1.07k | (*available_in) -= 1; | 2756 | | // Retry with more data in buffer. | 2757 | | // we can't re-borrow the saved buffer...so we have to do this recursively | 2758 | 1.07k | continue; | 2759 | 6.75k | } | 2760 | | // Can't finish reading and no more input. | 2761 | | | 2762 | | // FIXME :: NOT SURE WHAT THIS MEANT | 2763 | | // saved_buffer = core::mem::replace( | 2764 | | // &mut s.br.input_, | 2765 | | // &mut[]); // clear input | 2766 | 6.75k | break; | 2767 | | } else { | 2768 | | // Input stream doesn't contain enough input. | 2769 | | // Copy tail to internal buffer and return. | 2770 | 287k | *input_offset = s.br.next_in as usize; | 2771 | 287k | *available_in = s.br.avail_in as usize; | 2772 | 288k | while *available_in != 0 { | 2773 | 1.30k | fast_mut!((s.buffer)[s.buffer_length as usize]) = fast!((xinput)[*input_offset]); | 2774 | 1.30k | s.buffer_length += 1; | 2775 | 1.30k | (*input_offset) += 1; | 2776 | 1.30k | (*available_in) -= 1; | 2777 | 1.30k | } | 2778 | 287k | break; | 2779 | | } | 2780 | | // unreachable!(); <- dead code | 2781 | | } | 2782 | | _ => { | 2783 | | // Fail or needs more output. | 2784 | 203k | if s.buffer_length != 0 { | 2785 | 245 | // Just consumed the buffered input and produced some output. Otherwise | 2786 | 245 | // it would result in "needs more input". Reset internal buffer. | 2787 | 245 | s.buffer_length = 0; | 2788 | 202k | } else { | 2789 | 202k | // Using input stream in last iteration. When decoder switches to input | 2790 | 202k | // stream it has less than 8 bits in accamulator, so it is safe to | 2791 | 202k | // return unused accamulator bits there. | 2792 | 202k | bit_reader::BrotliBitReaderUnload(&mut s.br); | 2793 | 202k | *available_in = s.br.avail_in as usize; | 2794 | 202k | *input_offset = s.br.next_in as usize; | 2795 | 202k | } | 2796 | | } | 2797 | | } | 2798 | 203k | break; | 2799 | | } | 2800 | | } | 2801 | | loop { | 2802 | | // this emulates fallthrough behavior | 2803 | 852k | match s.state { | 2804 | | BrotliRunningState::BROTLI_STATE_UNINITED => { | 2805 | | // Prepare to the first read. | 2806 | 48.0k | if (!bit_reader::BrotliWarmupBitReader(&mut s.br, local_input)) { | 2807 | 24.1k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2808 | 24.1k | break; | 2809 | 23.8k | } | 2810 | | // Decode window size. | 2811 | | /* Reads 1..8 bits. */ | 2812 | 23.8k | result = DecodeWindowBits(&mut s.large_window, &mut s.window_bits, &mut s.br); | 2813 | 23.8k | match result { | 2814 | 23.8k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2815 | 66 | _ => break, | 2816 | | } | 2817 | 23.8k | if s.large_window { | 2818 | 462 | s.state = BrotliRunningState::BROTLI_STATE_LARGE_WINDOW_BITS; | 2819 | 23.3k | } else { | 2820 | 23.3k | s.state = BrotliRunningState::BROTLI_STATE_INITIALIZE; | 2821 | 23.3k | } | 2822 | | } | 2823 | | BrotliRunningState::BROTLI_STATE_LARGE_WINDOW_BITS => { | 2824 | 934 | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 6, &mut s.window_bits, local_input)) { | 2825 | 488 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2826 | 488 | break; | 2827 | 446 | } | 2828 | 446 | if (s.window_bits < kBrotliLargeMinWbits || | 2829 | 247 | s.window_bits > kBrotliLargeMaxWbits) { | 2830 | 201 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; | 2831 | 201 | break; | 2832 | 245 | } | 2833 | 245 | s.state = BrotliRunningState::BROTLI_STATE_INITIALIZE; | 2834 | | } | 2835 | | BrotliRunningState::BROTLI_STATE_INITIALIZE => { | 2836 | 23.6k | s.max_backward_distance = (1 << s.window_bits) - kBrotliWindowGap as i32; | 2837 | 23.6k | s.max_backward_distance_minus_custom_dict_size = (s.max_backward_distance as isize - | 2838 | 23.6k | s.custom_dict_size) as i32; | 2839 | | | 2840 | | // (formerly) Allocate memory for both block_type_trees and block_len_trees. | 2841 | 23.6k | s.block_type_length_state.block_type_trees = s.alloc_hc | 2842 | 23.6k | .alloc_cell(3 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize); | 2843 | 23.6k | if (s.block_type_length_state.block_type_trees.slice().len() == 0) { | 2844 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES; | 2845 | 0 | break; | 2846 | 23.6k | } | 2847 | 23.6k | s.block_type_length_state.block_len_trees = s.alloc_hc | 2848 | 23.6k | .alloc_cell(3 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as usize); | 2849 | | | 2850 | 23.6k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN; | 2851 | | // No break, continue to next state | 2852 | | } | 2853 | 30.5k | BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN => { | 2854 | 30.5k | s.BrotliStateMetablockBegin(); | 2855 | 30.5k | BROTLI_LOG_UINT!(s.pos); | 2856 | 30.5k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER; | 2857 | 30.5k | // No break, continue to next state | 2858 | 30.5k | } | 2859 | | BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER => { | 2860 | 51.7k | result = DecodeMetaBlockLength(&mut s, local_input); // Reads 2 - 31 bits. | 2861 | 51.7k | match result { | 2862 | 28.8k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2863 | 22.8k | _ => break, | 2864 | | } | 2865 | | BROTLI_LOG_UINT!(s.is_last_metablock); | 2866 | | BROTLI_LOG_UINT!(s.meta_block_remaining_len); | 2867 | | BROTLI_LOG_UINT!(s.is_metadata); | 2868 | | BROTLI_LOG_UINT!(s.is_uncompressed); | 2869 | 28.8k | if (s.is_metadata != 0 || s.is_uncompressed != 0) && | 2870 | 6.64k | !bit_reader::BrotliJumpToByteBoundary(&mut s.br) { | 2871 | 712 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_PADDING_2; | 2872 | 712 | break; | 2873 | 28.1k | } | 2874 | 28.1k | if s.is_metadata != 0 { | 2875 | 4.29k | s.state = BrotliRunningState::BROTLI_STATE_METADATA; | 2876 | 4.29k | break; | 2877 | 23.8k | } | 2878 | 23.8k | if s.meta_block_remaining_len == 0 { | 2879 | 1.10k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2880 | 1.10k | break; | 2881 | 22.7k | } | 2882 | 22.7k | if s.ringbuffer.slice().len() == 0 && !BrotliAllocateRingBuffer(&mut s, local_input) { | 2883 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2; | 2884 | 0 | break; | 2885 | 22.7k | } | 2886 | 22.7k | if s.is_uncompressed != 0 { | 2887 | 1.63k | s.state = BrotliRunningState::BROTLI_STATE_UNCOMPRESSED; | 2888 | 1.63k | break; | 2889 | 21.1k | } | 2890 | 21.1k | s.loop_counter = 0; | 2891 | 21.1k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0; | 2892 | 21.1k | break; | 2893 | | } | 2894 | | BrotliRunningState::BROTLI_STATE_UNCOMPRESSED => { | 2895 | 27.1k | let mut _bytes_copied = s.meta_block_remaining_len; | 2896 | 27.1k | result = CopyUncompressedBlockToOutput(&mut available_out, | 2897 | 27.1k | &mut output, | 2898 | 27.1k | &mut output_offset, | 2899 | 27.1k | &mut total_out, | 2900 | 27.1k | &mut s, | 2901 | 27.1k | local_input); | 2902 | 27.1k | _bytes_copied -= s.meta_block_remaining_len; | 2903 | 27.1k | match result { | 2904 | 598 | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2905 | 26.5k | _ => break, | 2906 | | } | 2907 | 598 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 2908 | 598 | break; | 2909 | | } | 2910 | | BrotliRunningState::BROTLI_STATE_METADATA => { | 2911 | 51.9k | while s.meta_block_remaining_len > 0 { | 2912 | 48.6k | let mut bits = 0u32; | 2913 | | // Read one byte and ignore it. | 2914 | 48.6k | if !bit_reader::BrotliSafeReadBits(&mut s.br, 8, &mut bits, local_input) { | 2915 | 3.27k | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 2916 | 3.27k | break; | 2917 | 45.3k | } | 2918 | 45.3k | s.meta_block_remaining_len -= 1; | 2919 | | } | 2920 | 6.55k | if let BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS = result { | 2921 | 3.28k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE | 2922 | 3.27k | } | 2923 | 6.55k | break; | 2924 | | } | 2925 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0 => { | 2926 | 85.6k | if s.loop_counter >= 3 { | 2927 | 19.2k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER_2; | 2928 | 19.2k | break; | 2929 | 66.3k | } | 2930 | | // Reads 1..11 bits. | 2931 | 66.3k | { | 2932 | 66.3k | let index = s.loop_counter as usize; | 2933 | 66.3k | result = | 2934 | 66.3k | DecodeVarLenUint8(&mut s.substate_decode_uint8, | 2935 | 66.3k | &mut s.br, | 2936 | 66.3k | &mut fast_mut!((s.block_type_length_state.num_block_types)[index]), | 2937 | 66.3k | local_input); | 2938 | 66.3k | } | 2939 | 66.3k | match result { | 2940 | 60.1k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2941 | 6.23k | _ => break, | 2942 | | } | 2943 | 60.1k | fast_mut!((s.block_type_length_state.num_block_types)[s.loop_counter as usize]) += 1; | 2944 | | BROTLI_LOG_UINT!(s.block_type_length_state.num_block_types[s.loop_counter as usize]); | 2945 | 60.1k | if fast!((s.block_type_length_state.num_block_types)[s.loop_counter as usize]) < 2 { | 2946 | 54.0k | s.loop_counter += 1; | 2947 | 54.0k | break; | 2948 | 6.09k | } | 2949 | 6.09k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_1; | 2950 | | // No break, continue to next state | 2951 | | } | 2952 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_1 => { | 2953 | 78.7k | let tree_offset = s.loop_counter as u32 * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as u32; | 2954 | 78.7k | let mut new_huffman_table = mem::replace(&mut s.block_type_length_state.block_type_trees, | 2955 | 78.7k | AllocHC::AllocatedMemory::default()); | 2956 | 78.7k | let loop_counter = s.loop_counter as usize; | 2957 | 78.7k | let alphabet_size = fast!((s.block_type_length_state.num_block_types)[loop_counter]) + 2; | 2958 | 78.7k | result = | 2959 | 78.7k | ReadHuffmanCode(alphabet_size, alphabet_size, | 2960 | 78.7k | new_huffman_table.slice_mut(), | 2961 | 78.7k | tree_offset as usize, | 2962 | 78.7k | None, | 2963 | 78.7k | &mut s, | 2964 | 78.7k | local_input); | 2965 | 78.7k | let _ = mem::replace(&mut s.block_type_length_state.block_type_trees, | 2966 | 78.7k | new_huffman_table); | 2967 | 78.7k | match result { | 2968 | 5.33k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2969 | 73.4k | _ => break, | 2970 | | } | 2971 | 5.33k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_2; | 2972 | | // No break, continue to next state | 2973 | | } | 2974 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_2 => { | 2975 | 7.61k | let tree_offset = s.loop_counter * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as i32; | 2976 | 7.61k | let mut new_huffman_table = mem::replace(&mut s.block_type_length_state.block_len_trees, | 2977 | 7.61k | AllocHC::AllocatedMemory::default()); | 2978 | 7.61k | result = ReadHuffmanCode(kNumBlockLengthCodes, kNumBlockLengthCodes, | 2979 | 7.61k | new_huffman_table.slice_mut(), | 2980 | 7.61k | tree_offset as usize, | 2981 | 7.61k | None, | 2982 | 7.61k | &mut s, | 2983 | 7.61k | local_input); | 2984 | 7.61k | let _ = mem::replace(&mut s.block_type_length_state.block_len_trees, | 2985 | 7.61k | new_huffman_table); | 2986 | 7.61k | match result { | 2987 | 4.93k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 2988 | 2.68k | _ => break, | 2989 | | } | 2990 | 4.93k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_3; | 2991 | | // No break, continue to next state | 2992 | | } | 2993 | | BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_3 => { | 2994 | 5.39k | let tree_offset = s.loop_counter * huffman::BROTLI_HUFFMAN_MAX_TABLE_SIZE as i32; | 2995 | | | 2996 | 5.39k | let mut block_length_out: u32 = 0; | 2997 | | let ind_ret: (bool, u32); | 2998 | | | 2999 | 5.39k | ind_ret = SafeReadBlockLengthIndex(&s.block_type_length_state.substate_read_block_length, | 3000 | 5.39k | s.block_type_length_state.block_length_index, | 3001 | 5.39k | fast_slice!((s.block_type_length_state.block_len_trees) | 3002 | 5.39k | [tree_offset as usize;]), | 3003 | 5.39k | &mut s.br, local_input); | 3004 | | | 3005 | 5.39k | if !SafeReadBlockLengthFromIndex(&mut s.block_type_length_state, | 3006 | 5.39k | &mut s.br, | 3007 | 5.39k | &mut block_length_out, | 3008 | 5.39k | ind_ret, | 3009 | 5.39k | local_input) { | 3010 | 611 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 3011 | 611 | break; | 3012 | 4.77k | } | 3013 | 4.77k | fast_mut!((s.block_type_length_state.block_length)[s.loop_counter as usize]) = | 3014 | 4.77k | block_length_out; | 3015 | | BROTLI_LOG_UINT!(s.block_type_length_state.block_length[s.loop_counter as usize]); | 3016 | 4.77k | s.loop_counter += 1; | 3017 | 4.77k | s.state = BrotliRunningState::BROTLI_STATE_HUFFMAN_CODE_0; | 3018 | 4.77k | break; | 3019 | | } | 3020 | | BrotliRunningState::BROTLI_STATE_METABLOCK_HEADER_2 => { | 3021 | 20.0k | let mut bits: u32 = 0; | 3022 | 20.0k | if (!bit_reader::BrotliSafeReadBits(&mut s.br, 6, &mut bits, local_input)) { | 3023 | 832 | result = BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT; | 3024 | 832 | break; | 3025 | 19.2k | } | 3026 | 19.2k | s.distance_postfix_bits = bits & bit_reader::BitMask(2); | 3027 | 19.2k | bits >>= 2; | 3028 | 19.2k | s.num_direct_distance_codes = NUM_DISTANCE_SHORT_CODES + | 3029 | 19.2k | (bits << s.distance_postfix_bits); | 3030 | | BROTLI_LOG_UINT!(s.num_direct_distance_codes); | 3031 | | BROTLI_LOG_UINT!(s.distance_postfix_bits); | 3032 | 19.2k | s.distance_postfix_mask = bit_reader::BitMask(s.distance_postfix_bits) as i32; | 3033 | 19.2k | s.context_modes = s.alloc_u8 | 3034 | 19.2k | .alloc_cell(fast!((s.block_type_length_state.num_block_types)[0]) as usize); | 3035 | 19.2k | if (s.context_modes.slice().len() == 0) { | 3036 | 0 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES; | 3037 | 0 | break; | 3038 | 19.2k | } | 3039 | 19.2k | s.loop_counter = 0; | 3040 | 19.2k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MODES; | 3041 | | // No break, continue to next state | 3042 | | } | 3043 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MODES => { | 3044 | 19.5k | result = ReadContextModes(&mut s, local_input); | 3045 | 19.5k | match result { | 3046 | 19.1k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3047 | 343 | _ => break, | 3048 | | } | 3049 | 19.1k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1; | 3050 | | // No break, continue to next state | 3051 | | } | 3052 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_1 => { | 3053 | 25.0k | result = | 3054 | 25.0k | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[0]) as usize) << | 3055 | 25.0k | kLiteralContextBits as usize, | 3056 | 25.0k | false, | 3057 | 25.0k | &mut s, | 3058 | 25.0k | local_input); | 3059 | 25.0k | match result { | 3060 | 18.5k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3061 | 6.45k | _ => break, | 3062 | | } | 3063 | 18.5k | DetectTrivialLiteralBlockTypes(s); | 3064 | 18.5k | s.state = BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2; | 3065 | | // No break, continue to next state | 3066 | | } | 3067 | | BrotliRunningState::BROTLI_STATE_CONTEXT_MAP_2 => { | 3068 | 29.0k | let num_direct_codes = | 3069 | 29.0k | s.num_direct_distance_codes - NUM_DISTANCE_SHORT_CODES; | 3070 | 29.0k | let num_distance_codes = BROTLI_DISTANCE_ALPHABET_SIZE( | 3071 | 29.0k | s.distance_postfix_bits, num_direct_codes, | 3072 | 29.0k | (if s.large_window { BROTLI_LARGE_MAX_DISTANCE_BITS } else { | 3073 | 28.2k | BROTLI_MAX_DISTANCE_BITS})); | 3074 | 29.0k | let max_distance_symbol = if s.large_window { | 3075 | 835 | BrotliMaxDistanceSymbol( | 3076 | 835 | num_direct_codes, s.distance_postfix_bits) | 3077 | | } else { | 3078 | 28.2k | num_distance_codes | 3079 | | }; | 3080 | 29.0k | result = | 3081 | 29.0k | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[2]) as usize) << | 3082 | 29.0k | kDistanceContextBits as usize, | 3083 | 29.0k | true, | 3084 | 29.0k | s, | 3085 | 29.0k | local_input); | 3086 | 29.0k | match result { | 3087 | 16.7k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3088 | 12.2k | _ => break, | 3089 | | } | 3090 | 16.7k | s.literal_hgroup.init(&mut s.alloc_u32, | 3091 | 16.7k | &mut s.alloc_hc, | 3092 | | kNumLiteralCodes, | 3093 | | kNumLiteralCodes, | 3094 | 16.7k | s.num_literal_htrees as u16); | 3095 | 16.7k | s.insert_copy_hgroup.init(&mut s.alloc_u32, | 3096 | 16.7k | &mut s.alloc_hc, | 3097 | | kNumInsertAndCopyCodes, | 3098 | | kNumInsertAndCopyCodes, | 3099 | 16.7k | fast!((s.block_type_length_state.num_block_types)[1]) as u16); | 3100 | 16.7k | s.distance_hgroup.init(&mut s.alloc_u32, | 3101 | 16.7k | &mut s.alloc_hc, | 3102 | 16.7k | num_distance_codes as u16, | 3103 | 16.7k | max_distance_symbol as u16, | 3104 | 16.7k | s.num_dist_htrees as u16); | 3105 | 16.7k | if (s.literal_hgroup.codes.slice().len() == 0 || | 3106 | 16.7k | s.insert_copy_hgroup.codes.slice().len() == 0 || | 3107 | 16.7k | s.distance_hgroup.codes.slice().len() == 0) { | 3108 | 0 | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_UNREACHABLE); | 3109 | 16.7k | } | 3110 | | | 3111 | | /*{ | 3112 | | let num_distance_codes: u32 = s.num_direct_distance_codes + | 3113 | | (48u32 << s.distance_postfix_bits); | 3114 | | result = | 3115 | | DecodeContextMap((fast!((s.block_type_length_state.num_block_types)[2]) as usize) << | 3116 | | kDistanceContextBits as usize, | 3117 | | true, | 3118 | | s, | 3119 | | local_input); | 3120 | | match result { | 3121 | | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3122 | | _ => break, | 3123 | | } | 3124 | | s.literal_hgroup.init(&mut s.alloc_u32, | 3125 | | &mut s.alloc_hc, | 3126 | | kNumLiteralCodes, | 3127 | | s.num_literal_htrees as u16); | 3128 | | s.insert_copy_hgroup.init(&mut s.alloc_u32, | 3129 | | &mut s.alloc_hc, | 3130 | | kNumInsertAndCopyCodes, | 3131 | | fast!((s.block_type_length_state.num_block_types)[1]) as u16); | 3132 | | s.distance_hgroup.init(&mut s.alloc_u32, | 3133 | | &mut s.alloc_hc, | 3134 | | num_distance_codes as u16, | 3135 | | s.num_dist_htrees as u16); | 3136 | | if (s.literal_hgroup.codes.slice().len() == 0 || | 3137 | | s.insert_copy_hgroup.codes.slice().len() == 0 || | 3138 | | s.distance_hgroup.codes.slice().len() == 0) { | 3139 | | return SaveErrorCode!(s, BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS); | 3140 | | } | 3141 | | }*/ | 3142 | 16.7k | s.loop_counter = 0; | 3143 | 16.7k | s.state = BrotliRunningState::BROTLI_STATE_TREE_GROUP; | 3144 | | // No break, continue to next state | 3145 | | } | 3146 | | BrotliRunningState::BROTLI_STATE_TREE_GROUP => { | 3147 | 51.5k | result = HuffmanTreeGroupDecode(s.loop_counter, &mut s, local_input); | 3148 | 51.5k | match result { | 3149 | 27.5k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3150 | 24.0k | _ => break, | 3151 | | } | 3152 | 27.5k | s.loop_counter += 1; | 3153 | 27.5k | if (s.loop_counter >= 3) { | 3154 | 8.15k | PrepareLiteralDecoding(s); | 3155 | 8.15k | s.dist_context_map_slice_index = 0; | 3156 | 8.15k | /* | 3157 | 8.15k | s.context_map_slice_index = 0; | 3158 | 8.15k | let context_mode_index = fast!((s.block_type_length_state.block_type_rb)[1]); | 3159 | 8.15k | let context_mode = fast_slice!((s.context_modes)[context_mode_index as usize]); | 3160 | 8.15k | s.context_lookup = &kContextLookup[context_mode as usize & 3]; | 3161 | 8.15k | */ | 3162 | 8.15k | s.htree_command_index = 0; | 3163 | 8.15k | // look it up each time s.literal_htree=s.literal_hgroup.htrees[s.literal_htree_index]; | 3164 | 8.15k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 3165 | 19.4k | } | 3166 | 27.5k | break; | 3167 | | } | 3168 | | BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN | | 3169 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER | | 3170 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS | | 3171 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY => { | 3172 | 118k | result = ProcessCommands(s, local_input); | 3173 | 118k | if let BrotliDecoderErrorCode::BROTLI_DECODER_NEEDS_MORE_INPUT = result { | 3174 | 107k | result = SafeProcessCommands(s, local_input) | 3175 | 10.6k | } | 3176 | 118k | break; | 3177 | | } | 3178 | | BrotliRunningState::BROTLI_STATE_COMMAND_INNER_WRITE | | 3179 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1 | | 3180 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2 => { | 3181 | 156k | let (xresult, _) = WriteRingBuffer(&mut available_out, | 3182 | 156k | Some(&mut output), | 3183 | 156k | &mut output_offset, | 3184 | 156k | &mut total_out, | 3185 | 156k | false, | 3186 | 156k | &mut s); | 3187 | 156k | result = xresult; | 3188 | 156k | match result { | 3189 | 16.4k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3190 | 140k | _ => break, | 3191 | | } | 3192 | 16.4k | WrapRingBuffer(s); | 3193 | 16.4k | if s.ringbuffer_size == 1 << s.window_bits { | 3194 | 16.4k | s.max_distance = s.max_backward_distance; | 3195 | 16.4k | } | 3196 | 16.4k | match s.state { | 3197 | | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_1 => { | 3198 | 689 | if (s.meta_block_remaining_len <= 0) { | 3199 | 0 | // Next metablock, if any | 3200 | 0 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 3201 | 689 | } else { | 3202 | 689 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_BEGIN; | 3203 | 689 | } | 3204 | 689 | break; | 3205 | | } | 3206 | 10.4k | BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRITE_2 => { | 3207 | 10.4k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_WRAP_COPY; | 3208 | 10.4k | } | 3209 | | _ => { | 3210 | | // BROTLI_STATE_COMMAND_INNER_WRITE | 3211 | 5.29k | if (s.loop_counter == 0) { | 3212 | 588 | if (s.meta_block_remaining_len <= 0) { | 3213 | 0 | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_DONE; | 3214 | 588 | } else { | 3215 | 588 | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_POST_DECODE_LITERALS; | 3216 | 588 | } | 3217 | 588 | break; | 3218 | 4.70k | } | 3219 | 4.70k | s.state = BrotliRunningState::BROTLI_STATE_COMMAND_INNER; | 3220 | | } | 3221 | | } | 3222 | 15.1k | break; | 3223 | | } | 3224 | | BrotliRunningState::BROTLI_STATE_METABLOCK_DONE => { | 3225 | 9.63k | s.BrotliStateCleanupAfterMetablock(); | 3226 | 9.63k | if (s.is_last_metablock == 0) { | 3227 | 6.95k | s.state = BrotliRunningState::BROTLI_STATE_METABLOCK_BEGIN; | 3228 | 6.95k | break; | 3229 | 2.68k | } | 3230 | 2.68k | if (!bit_reader::BrotliJumpToByteBoundary(&mut s.br)) { | 3231 | 927 | result = BrotliDecoderErrorCode::BROTLI_DECODER_ERROR_FORMAT_PADDING_2; | 3232 | 1.75k | } | 3233 | 2.68k | if (s.buffer_length == 0) { | 3234 | 2.65k | bit_reader::BrotliBitReaderUnload(&mut s.br); | 3235 | 2.65k | *available_in = s.br.avail_in as usize; | 3236 | 2.65k | *input_offset = s.br.next_in as usize; | 3237 | 2.65k | } | 3238 | 2.68k | s.state = BrotliRunningState::BROTLI_STATE_DONE; | 3239 | | // No break, continue to next state | 3240 | | } | 3241 | | BrotliRunningState::BROTLI_STATE_DONE => { | 3242 | 57.1k | if (s.ringbuffer.slice().len() != 0) { | 3243 | 55.9k | let (xresult, _) = WriteRingBuffer(&mut available_out, | 3244 | 55.9k | Some(&mut output), | 3245 | 55.9k | &mut output_offset, | 3246 | 55.9k | &mut total_out, | 3247 | 55.9k | true, | 3248 | 55.9k | &mut s); | 3249 | 55.9k | result = xresult; | 3250 | 55.9k | match result { | 3251 | 6.50k | BrotliDecoderErrorCode::BROTLI_DECODER_SUCCESS => {} | 3252 | 49.4k | _ => break, | 3253 | | } | 3254 | 1.20k | } | 3255 | 7.70k | return SaveErrorCode!(s, result); | 3256 | | } | 3257 | | } | 3258 | | } | 3259 | | } | 3260 | | | 3261 | 497k | SaveErrorCode!(s, result) | 3262 | 505k | } |
|
3263 | | |