Skip to content

Commit

Permalink
Trace tests, don't re-allocate vec u8 all the time
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jan 26, 2024
1 parent 90ad152 commit 9366072
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 9 deletions.
115 changes: 108 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/rc-zip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ sync = []
file = ["positioned-io"]
deflate = ["flate2"]
lzma = ["lzma-rs"]

[dev-dependencies]
tracing-test = "0.2.4"
5 changes: 3 additions & 2 deletions crates/rc-zip/src/reader/sync/entry_reader/lzma_dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ where
dst_slice.copy_from_slice(src_slice);
}

// TODO: use a ring buffer instead
*write_buf = write_buf.split_off(write_count);
// copy the remaining bytes to the front of the buffer
write_buf.rotate_left(write_count);
write_buf.truncate(write_buf.len() - write_count);

self.total_write_count += write_count as u64;
Ok(write_count)
Expand Down
6 changes: 6 additions & 0 deletions crates/rc-zip/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use tracing_test::traced_test;

use crate::{
reader::sync::{HasCursor, SyncArchive, SyncStoredEntry},
Archive,
Expand Down Expand Up @@ -286,6 +288,7 @@ fn test_cases() -> Vec<ZipTest> {
}

#[test]
#[traced_test]
fn read_from_slice() {
let bytes = std::fs::read(zips_dir().join("test.zip")).unwrap();
let slice = &bytes[..];
Expand All @@ -294,20 +297,23 @@ fn read_from_slice() {
}

#[test]
#[traced_test]
fn read_from_file() {
let f = File::open(zips_dir().join("test.zip")).unwrap();
let archive = f.read_zip().unwrap();
assert_eq!(archive.entries().count(), 2);
}

#[test]
#[traced_test]
fn real_world_files() {
for case in test_cases() {
case.check(case.bytes().read_zip());
}
}

#[test]
#[traced_test]
fn test_fsm() {
use super::reader::{ArchiveReader, ArchiveReaderResult};

Expand Down

0 comments on commit 9366072

Please sign in to comment.