Skip to content

Commit 4c9d2fc

Browse files
Pr0metheangithub-code-quality[bot]amazon-q-developer[bot]
authored
test: Potential fixes for 3 code quality findings in benches/read-metadata.rs (#610)
* Apply suggested fix to benches/read_metadata.rs from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> * Apply suggested fix to benches/read_metadata.rs from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> * Apply suggested fix to benches/read_metadata.rs from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> * [skip ci] chore: run cargo fmt --all to apply standard formatting * cargo fmt --all --------- Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com>
1 parent 1cd9f73 commit 4c9d2fc

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

benches/read_metadata.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ fn generate_random_archive(count_files: usize, file_size: usize) -> ZipResult<Ve
1818

1919
let mut bytes = vec![0u8; file_size];
2020

21-
for i in 0..count_files {
22-
let name = format!("file_deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef_{i}.dat");
21+
for file_index in 0..count_files {
22+
let name =
23+
format!("file_deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef_{file_index}.dat");
2324
writer.start_file(name, options)?;
2425
getrandom::fill(&mut bytes)
2526
.map_err(|e| std::io::Error::other(format!("getrandom error: {}", e)))?;
@@ -79,9 +80,7 @@ fn generate_zip64_archive_with_random_comment(comment_length: usize) -> ZipResul
7980
let mut bytes = vec![0u8; comment_length];
8081
getrandom::fill(&mut bytes)
8182
.map_err(|e| std::io::Error::other(format!("getrandom error: {}", e)))?;
82-
// should use the line below but still works
83-
// writer.set_raw_zip64_comment(Some(comment));
84-
writer.set_raw_comment(bytes.into_boxed_slice());
83+
writer.set_raw_zip64_comment(Some(bytes.into_boxed_slice()));
8584

8685
writer.start_file("asdf.txt", options)?;
8786
writer.write_all(b"asdf")?;
@@ -105,7 +104,7 @@ fn parse_stream_archive(bench: &mut Bencher) {
105104

106105
let bytes = generate_random_archive(STREAM_ZIP_ENTRIES, STREAM_FILE_SIZE).unwrap();
107106

108-
/* Write to a temporary file path to incur some filesystem overhead from repeated reads */
107+
// Write to a temporary file path to incur some filesystem overhead from repeated reads
109108
let dir = TempDir::with_prefix("stream-bench").unwrap();
110109
let out = dir.path().join("bench-out.zip");
111110
fs::write(&out, &bytes).unwrap();
@@ -121,13 +120,13 @@ fn parse_stream_archive(bench: &mut Bencher) {
121120
}
122121

123122
fn parse_large_non_zip(bench: &mut Bencher) {
124-
const FILE_SIZE: usize = 17_000_000;
123+
const LARGE_FILE_SIZE: usize = 17_000_000;
125124

126125
// Create a large file that doesn't have a zip header (generating random data _might_ make a zip magic
127126
// number somewhere which is _not_ what we're trying to test).
128127
let dir = TempDir::with_prefix("large-non-zip-bench").unwrap();
129128
let file = dir.path().join("zeros");
130-
let buf = vec![0u8; FILE_SIZE];
129+
let buf = vec![0u8; LARGE_FILE_SIZE];
131130
fs::write(&file, &buf).unwrap();
132131

133132
bench.iter(|| {

0 commit comments

Comments
 (0)