refactor: refine compact bytes interface

This commit is contained in:
Zixuan Chen 2023-07-14 12:51:06 +08:00
parent 3771566b9f
commit d26bb4e5c9
2 changed files with 5 additions and 1 deletions

View file

@ -6,6 +6,6 @@ pub fn main() {
for _ in 0..1000 {
let mut bytes = CompactBytes::new();
bytes.append(&black_box(data).as_bytes()[..data.len() / 2]);
bytes.alloc_advance(&black_box(&data.as_bytes()[data.len() / 2..]));
bytes.alloc_advance(black_box(&data.as_bytes()[data.len() / 2..]));
}
}

View file

@ -62,6 +62,10 @@ impl CompactBytes {
self.capacity
}
pub fn take(self) -> AppendOnlyBytes {
self.bytes
}
pub fn from_bytes(bytes: &[u8]) -> Self {
let mut compact_bytes = CompactBytes::new();
compact_bytes.append(bytes);