src/backup/chunker.rs: simplify code

This commit is contained in:
Dietmar Maurer 2019-02-20 11:17:19 +01:00
parent 1b9c959c32
commit fa4ebf0fce

View File

@ -147,21 +147,21 @@ impl Chunker {
if self.window_size < window_len { if self.window_size < window_len {
let need = window_len - self.window_size; let need = window_len - self.window_size;
let copy_len = if need < data_len { need } else { data_len }; let copy_len = if need < data_len { need } else { data_len };
unsafe {
let src_ptr = data.as_ptr().add(pos); for _i in 0..copy_len {
let dest_ptr = self.window.as_mut_ptr().add(self.window_size); let byte = data[pos];
std::ptr::copy_nonoverlapping(src_ptr, dest_ptr, copy_len); self.window[self.window_size] = byte;
self.h = self.h.rotate_left(1) ^ BUZHASH_TABLE[byte as usize];
pos += 1;
self.window_size += 1;
} }
pos += copy_len;
self.window_size += copy_len;
self.chunk_size += copy_len; self.chunk_size += copy_len;
// return if window is still not full // return if window is still not full
if self.window_size < window_len { if self.window_size < window_len {
return 0; return 0;
} }
self.start();
} }
let mut idx = self.chunk_size % CA_CHUNKER_WINDOW_SIZE; let mut idx = self.chunk_size % CA_CHUNKER_WINDOW_SIZE;
@ -218,18 +218,6 @@ impl Chunker {
(self.h % self.discriminator) == (self.discriminator - 1) (self.h % self.discriminator) == (self.discriminator - 1)
} }
*/ */
fn start(&mut self) {
let window_len = self.window.len();
let mut h: u32 = 0;
for i in 0..window_len {
let byte = self.window[i];
h = h.rotate_left(1) ^ BUZHASH_TABLE[byte as usize];
}
self.h = h;
}
} }
#[test] #[test]