Skip to content

Commit 2060bb7

Browse files
committed
refactor: calculate src size just once
1 parent e189f86 commit 2060bb7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/codec/lz4/encoder.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@ impl Lz4Encoder {
115115
return Ok(drained_before);
116116
}
117117

118+
let mut src_size = 0;
119+
118120
let min_dst_size = match &lz4_fn {
119121
Lz4Fn::Begin => LZ4F_HEADER_SIZE_MAX,
120122
Lz4Fn::Update { input } => {
121-
min_dst_size(input.unwritten().len().min(self.limit), &self.preferences)
123+
src_size = input.unwritten().len().min(self.limit);
124+
min_dst_size(src_size, &self.preferences)
122125
}
123126
Lz4Fn::Flush | Lz4Fn::End => self.flush_buffer_size,
124127
};
@@ -148,18 +151,17 @@ impl Lz4Encoder {
148151
len
149152
}
150153
Lz4Fn::Update { input } => {
151-
let size = input.unwritten().len().min(self.limit);
152154
let len = check_error(unsafe {
153155
LZ4F_compressUpdate(
154156
self.ctx.get_mut().ctx,
155157
dst_buffer,
156158
min_dst_size,
157159
input.unwritten().as_ptr(),
158-
size,
160+
src_size,
159161
core::ptr::null(),
160162
)
161163
})?;
162-
input.advance(size);
164+
input.advance(src_size);
163165
len
164166
}
165167
Lz4Fn::Flush => check_error(unsafe {

0 commit comments

Comments
 (0)