-
Notifications
You must be signed in to change notification settings - Fork 39
Closed
Description
When this will eventually become stable it will allow unsafe to be removed from here:
zstd-rs/src/decoding/decodebuffer.rs
Lines 117 to 144 in b093ade
/* | |
const BATCH_SIZE: usize = 32; | |
let full_copies = match_length / BATCH_SIZE; | |
let partial_copy_size = match_length % BATCH_SIZE; | |
let mut buf = [0u8; BATCH_SIZE]; | |
for x in 0..full_copies { | |
let idx = start_idx + x * BATCH_SIZE; | |
let source = &self.buffer.as_slice()[idx..idx + BATCH_SIZE]; | |
buf[0..BATCH_SIZE].copy_from_slice(source); | |
self.buffer.extend(&buf[0..BATCH_SIZE]); | |
} | |
let idx = start_idx + full_copies * BATCH_SIZE; | |
let source = &self.buffer.as_slice()[idx..idx + partial_copy_size]; | |
buf[0..partial_copy_size].copy_from_slice(source); | |
self.buffer.extend(&buf[0..partial_copy_size]); | |
*/ | |
// using this unsafe block instead of the above increases performance by ca 5% when decoding the enwik9 dataset | |
self.buffer.reserve(match_length); | |
unsafe { | |
self.buffer.set_len(self.buffer.len() + match_length); | |
let slice = &mut self.buffer[start_idx..]; | |
let src = slice.as_mut_ptr(); | |
let dst = src.add(slice.len() - match_length); | |
std::ptr::copy_nonoverlapping(src, dst, match_length); | |
} |
I just saw the tracking issue and I immediately remembered your crate could use something like this 😃
Metadata
Metadata
Assignees
Labels
No labels