Skip to content

Commit

Permalink
fix(core): Buffer offset usage
Browse files Browse the repository at this point in the history
  • Loading branch information
George-Miao committed Apr 12, 2024
1 parent 22b9c62 commit 32fd080
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions core/src/types/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ impl Buffer {
parts, idx, offset, ..
} => {
let mut ret = Vec::with_capacity(parts.len() - *idx);
let mut new_offset = *offset;
for part in parts.iter().skip(*idx) {
ret.push(IoSlice::new(&part[*offset..]));
ret.push(IoSlice::new(&part[*new_offset..]));
new_offset = 0;
}
ret
}
Expand Down Expand Up @@ -368,16 +370,16 @@ impl Buf for Buffer {
return 0;
}

let mut i = 0;
for part in parts.iter().skip(*idx) {
if i >= dst.len() {
break;
}

dst[i] = IoSlice::new(&part[*offset..]);
i += 1;
}
i
let mut new_offset = *offset;
parts
.iter()
.skip(*idx)
.zip(dst.iter_mut())
.map(|(part, dst)| {
*dst = IoSlice::new(&part[*new_offset..]);
new_offset = 0;
})
.count()
}
}
}
Expand Down

0 comments on commit 32fd080

Please sign in to comment.