| @@ -8,7 +8,6 @@ use std::{fs::File, io::{Cursor, Read}, path::PathBuf}; · 7 unmodified lines |
| 8 | 8 | use std::os::unix::fs::MetadataExt; |
| 9 | 9 | use deflate; |
| 10 | 10 | use object::parsed; |
| 11 | | −use miniz_oxide::inflate::core::inflate_flags::TINFL_FLAG_PARSE_ZLIB_HEADER; |
| 12 | 11 | |
| 13 | 12 | const HEADER_READ_COMPRESSED_BYTES: usize = 256; |
| 14 | 13 | const HEADER_READ_UNCOMPRESSED_BYTES: usize = 256; |
| @@ -37,27 +36,25 @@ impl Object { · 22 unmodified lines |
| 37 | 36 | let total_size = self.header_size + self.size; |
| 38 | 37 | let cap = self.decompressed_data.capacity(); |
| 39 | 38 | if cap < total_size { |
| 40 | | − self.decompressed_data |
| 41 | | − .reserve_exact(total_size - cap); |
| 39 | + self.decompressed_data.reserve_exact(total_size - cap); |
| 42 | 40 | } |
| 43 | 41 | unsafe { |
| 44 | 42 | debug_assert!(self.decompressed_data.capacity() >= total_size); |
| 45 | 43 | self.decompressed_data.set_len(total_size); |
| 46 | 44 | } |
| 47 | | − println!("out capacity: {}", self.decompressed_data.len()); |
| 48 | 45 | let mut cursor = Cursor::new(&mut self.decompressed_data[..]); |
| 46 | + // TODO Performance opportunity |
| 47 | + // here we do a lot of additional work, which could be saved if we |
| 48 | + // could re-use the previous state. This doesn't work for some reason. |
| 49 | 49 | self.deflate = Default::default(); |
| 50 | | − let (consumed_in, consumed_out) = self.deflate.to_end( |
| 51 | | − &self.compressed_data[..], |
| 52 | | − &mut cursor, |
| 53 | | − TINFL_FLAG_PARSE_ZLIB_HEADER, |
| 54 | | − )?; |
| 50 | + let (consumed_in, consumed_out) = |
| 51 | + self.deflate.to_end(&self.compressed_data[..], &mut cursor)?; |
| 55 | 52 | debug_assert!(self.deflate.is_done); |
| 56 | 53 | self.end_of_decompressed_bytes = consumed_out; |
| 57 | 54 | self.end_of_consumed_compressed_bytes = consumed_in; |
| 58 | 55 | debug_assert!(self.end_of_decompressed_bytes == total_size); |
| 59 | 56 | } |
| 60 | | − let bytes = &self.decompressed_data[..self.end_of_decompressed_bytes]; |
| 57 | + let bytes = &self.decompressed_data[self.header_size..]; |
| 61 | 58 | match self.kind { |
| 62 | 59 | Kind::Tag => parsed::Object::Tag(parsed::Tag::from_bytes(bytes)?), |
| 63 | 60 | _ => unimplemented!(), |
| @@ -129,11 +126,7 @@ impl Db { · 65 unmodified lines |
| 129 | 126 | |
| 130 | 127 | ( |
| 131 | 128 | deflate |
| 132 | | − .once( |
| 133 | | − &compressed[..bytes_read], |
| 134 | | − &mut out, |
| 135 | | − TINFL_FLAG_PARSE_ZLIB_HEADER, |
| 136 | | − ) |
| 129 | + .once(&compressed[..bytes_read], &mut out) |
| 137 | 130 | .with_context(|_| { |
| 138 | 131 | format!("ZIP inflating failed while reading '{}'", path.display()) |
| 139 | 132 | })?, |
| @@ -141,7 +134,6 @@ impl Db { · 1 unmodified line |
| 141 | 134 | istream, |
| 142 | 135 | ) |
| 143 | 136 | }; |
| 144 | | − println!("{:?} = stauts", _status); |
| 145 | 137 | |
| 146 | 138 | let (kind, size, header_size) = |
| 147 | 139 | parse::header(&decompressed[..consumed_out]).with_context(|_| { |
| @@ -208,7 +200,7 @@ pub mod parse { · 60 unmodified lines |
| 208 | 200 | (Some(kind), Some(size)) => Ok(( |
| 209 | 201 | object::Kind::from_bytes(kind)?, |
| 210 | 202 | str::from_utf8(size)?.parse()?, |
| 211 | | − header_end + 1 // account for 0 byte |
| 203 | + header_end + 1, // account for 0 byte |
| 212 | 204 | )), |
| 213 | 205 | _ => bail!("expected '<type> <size>'"), |
| 214 | 206 | } |