Skip to content

Commit c25ee16

Browse files
authored
Take crc instead of storing one in Parser
Signed-off-by: Jiahao XU <[email protected]>
1 parent 20a185e commit c25ee16

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

crates/compression-codecs/src/gzip/header.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ impl Default for State {
3737
pub(super) struct Parser {
3838
state: State,
3939
header: Header,
40-
crc: Crc,
4140
}
4241

4342
impl Header {
@@ -79,15 +78,15 @@ fn consume_cstr(crc: &mut Crc, input: &mut PartialBuffer<&[u8]>) -> Option<()> {
7978
}
8079

8180
impl Parser {
82-
pub(super) fn input(&mut self, input: &mut PartialBuffer<&[u8]>) -> io::Result<Option<Header>> {
81+
pub(super) fn input(&mut self, crc: &mut Crc, input: &mut PartialBuffer<&[u8]>) -> io::Result<Option<Header>> {
8382
loop {
8483
match &mut self.state {
8584
State::Fixed(data) => {
8685
data.copy_unwritten_from(input);
8786

8887
if data.unwritten().is_empty() {
8988
let data = data.get_mut();
90-
self.crc.update(data);
89+
crc.update(data);
9190
self.header = Header::parse(data)?;
9291
self.state = State::ExtraLen(<_>::default());
9392
} else {
@@ -105,7 +104,7 @@ impl Parser {
105104

106105
if data.unwritten().is_empty() {
107106
let data = data.get_mut();
108-
self.crc.update(data);
107+
crc.update(data);
109108
let len = u16::from_le_bytes(*data);
110109
self.state = State::Extra(len.into());
111110
} else {
@@ -116,7 +115,7 @@ impl Parser {
116115
State::Extra(bytes_to_consume) => {
117116
let n = input.unwritten().len().min(*bytes_to_consume);
118117
*bytes_to_consume -= n;
119-
consume_input(&mut self.crc, n, input);
118+
consume_input(crc, n, input);
120119

121120
if *bytes_to_consume == 0 {
122121
self.state = State::Filename;
@@ -131,7 +130,7 @@ impl Parser {
131130
continue;
132131
}
133132

134-
if consume_cstr(&mut self.crc, input).is_none() {
133+
if consume_cstr(crc, input).is_none() {
135134
break Ok(None);
136135
}
137136

@@ -144,7 +143,7 @@ impl Parser {
144143
continue;
145144
}
146145

147-
if consume_cstr(&mut self.crc, input).is_none() {
146+
if consume_cstr(crc, input).is_none() {
148147
break Ok(None);
149148
}
150149

@@ -164,7 +163,7 @@ impl Parser {
164163
break if data.unwritten().is_empty() {
165164
let data = data.take().into_inner();
166165
self.state = State::Done;
167-
let checksum = self.crc.sum().to_le_bytes();
166+
let checksum = crc.sum().to_le_bytes();
168167

169168
if data == checksum[..2] {
170169
Ok(Some(header))

0 commit comments

Comments
 (0)