Skip to content

Commit 5c6eaec

Browse files
authored
Merge pull request #454 from CosminPerRam/feat/reduce_crc_sum_calls
feat: reduce CrcReader::sum calls in GzEncoder::read_footer
2 parents c675117 + 1ccce6e commit 5c6eaec

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/gz/bufread.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,18 @@ impl<R: BufRead> GzEncoder<R> {
8080
return Ok(0);
8181
}
8282
let crc = self.inner.get_ref().crc();
83-
let ref arr = [
84-
(crc.sum() >> 0) as u8,
85-
(crc.sum() >> 8) as u8,
86-
(crc.sum() >> 16) as u8,
87-
(crc.sum() >> 24) as u8,
83+
let calced_crc_bytes = crc.sum().to_le_bytes();
84+
let arr = [
85+
calced_crc_bytes[0],
86+
calced_crc_bytes[1],
87+
calced_crc_bytes[2],
88+
calced_crc_bytes[3],
8889
(crc.amount() >> 0) as u8,
8990
(crc.amount() >> 8) as u8,
9091
(crc.amount() >> 16) as u8,
9192
(crc.amount() >> 24) as u8,
9293
];
93-
Ok(copy(into, arr, &mut self.pos))
94+
Ok(copy(into, &arr, &mut self.pos))
9495
}
9596
}
9697

0 commit comments

Comments
 (0)