| 21 | *h.finalize().as_bytes() |
| 22 | } |
| 23 | fn predict(bytes: &[u8]) -> usize { |
| 24 | let cap = bytes.len().min(4096); |
| 25 | let mut width = cap.min(16); |
| 26 | loop { |
| 27 | let window = &bytes[..width]; |
| 28 | let ascii = window |
| 29 | .iter() |
| 30 | .position(|b| !b.is_ascii()) |
| 31 | .unwrap_or(window.len()); |
| 32 | if ascii == 0 { |
| 33 | return usize::from(!bytes.is_empty()); |
| 34 | } |
| 35 | let length = Tokenizer::new(&window[..ascii]) |
| 36 | .next() |
| 37 | .map_or(0, |token| token.len()); |
| 38 | if length < ascii || ascii < width || width == cap { |
| 39 | return length; |
| 40 | } |
| 41 | width = (width * 2).min(cap); |
| 42 | } |
| 43 | } |
| 44 | fn offset(tag: u64, refs: &mut &[u8], previous: &mut u64, cursor: usize) -> Result<usize> { |
| 45 | if tag == 0 { |
| 46 | return Ok(cursor); |