Skip to content
This repository has been archived by the owner on Sep 4, 2022. It is now read-only.

Commit

Permalink
Make vector manipulation more efficient.
Browse files Browse the repository at this point in the history
  • Loading branch information
brinchj committed Aug 2, 2016
1 parent 6e90834 commit f509c90
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/marshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ pub fn marshal<T, F>(buf: &[u8],
) -> (Vec<u8>, T)
where F: Fn(*mut u8, *const u8, c_ulonglong) -> T {
let mut dst = Vec::with_capacity(buf.len() + padbefore);
for _ in 0..padbefore {
dst.push(0);
}
dst.extend(buf.into_iter());
dst.resize(padbefore, 0u8);
dst.extend_from_slice(&buf[..]);
let pdst = dst.as_mut_ptr();
let psrc = dst.as_ptr();
let res = f(pdst, psrc, dst.len() as c_ulonglong);
(dst.into_iter().skip(bytestodrop).collect(), res)
dst.drain(..bytestodrop);
(dst, res)
}

0 comments on commit f509c90

Please sign in to comment.