Eliminate the recursive call

This commit is contained in:
zypeh 2022-08-25 17:38:39 +08:00 committed by Lucas
parent 09ae98065c
commit f997a6250c
1 changed files with 11 additions and 11 deletions

View File

@ -278,6 +278,7 @@ impl Encoder {
/// After reaching the end of the buffer we write a 0 byte. Only write 0 if the byte array is empty. /// After reaching the end of the buffer we write a 0 byte. Only write 0 if the byte array is empty.
/// This is byte alignment agnostic. /// This is byte alignment agnostic.
fn write_blk(&mut self, arr: &[u8], src_ptr: &mut usize) { fn write_blk(&mut self, arr: &[u8], src_ptr: &mut usize) {
loop {
let src_len = arr.len() - *src_ptr; let src_len = arr.len() - *src_ptr;
let blk_len = src_len.min(255); let blk_len = src_len.min(255);
@ -290,7 +291,6 @@ impl Encoder {
self.buffer.extend(&arr[*src_ptr..blk_len]); self.buffer.extend(&arr[*src_ptr..blk_len]);
*src_ptr += blk_len; *src_ptr += blk_len;
}
self.write_blk(arr, src_ptr);
} }
} }