Skip to content

Commit

Permalink
make special BulkStoreRange that may be optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrh committed Nov 28, 2018
1 parent a5ca617 commit a56f4fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/enc/backward_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ pub trait AnyHasher {
-> bool;
fn Store(&mut self, data: &[u8], mask: usize, ix: usize);
fn StoreRange(&mut self, data: &[u8], mask: usize, ix_start: usize, ix_end: usize);
fn BulkStoreRange(&mut self, data: &[u8], mask: usize, ix_start: usize, ix_end: usize);
fn Prepare(&mut self, one_shot: bool, input_size: usize, data: &[u8]) -> HowPrepared;
fn StitchToPreviousBlock(&mut self,
num_bytes: usize,
Expand All @@ -183,10 +184,8 @@ pub fn StitchToPreviousBlockInternal<T: AnyHasher>(handle: &mut T,

pub fn StoreLookaheadThenStore<T: AnyHasher>(hasher: &mut T, size: usize, dict: &[u8]) {
let overlap = hasher.StoreLookahead().wrapping_sub(1usize);
let mut i: usize = 0;
while i.wrapping_add(overlap) < size {
hasher.Store(dict, !(0usize), i);
i = i.wrapping_add(1 as (usize));
if size > overlap {
hasher.BulkStoreRange(dict, !(0usize), 0, size - overlap);
}
}

Expand Down Expand Up @@ -241,13 +240,13 @@ impl<T: SliceWrapperMut<u32> + SliceWrapper<u32> + BasicHashComputer> AnyHasher
self.buckets_.slice_mut()[key.wrapping_add(off) as (usize)] = ix as (u32);
}
fn StoreRange(&mut self, data: &[u8], mask: usize, ix_start: usize, ix_end: usize) {
let mut i: usize;
i = ix_start;
while i < ix_end {
{
for i in ix_start..ix_end {
self.Store(data, mask, i);
}
}
fn BulkStoreRange(&mut self, data: &[u8], mask: usize, ix_start: usize, ix_end: usize) {
for i in ix_start..ix_end {
self.Store(data, mask, i);
}
i = i.wrapping_add(1 as (usize));
}
}
fn Prepare(&mut self, one_shot: bool, input_size: usize, data: &[u8]) -> HowPrepared {
Expand Down Expand Up @@ -782,6 +781,11 @@ impl<Alloc: alloc::Allocator<u16> + alloc::Allocator<u32>> AnyHasher for H9<Allo
self.Store(data, mask, i);
}
}
fn BulkStoreRange(&mut self, data: &[u8], mask: usize, ix_start: usize, ix_end: usize) {
for i in ix_start..ix_end {
self.Store(data, mask, i);
}
}
fn Prepare(&mut self, _one_shot: bool, _input_size:usize, _data:&[u8]) ->HowPrepared {
if self.GetHasherCommon().is_prepared_ != 0 {
return HowPrepared::ALREADY_PREPARED;
Expand Down Expand Up @@ -950,6 +954,11 @@ impl<Specialization: AdvHashSpecialization, Alloc: alloc::Allocator<u16> + alloc
self.Store(data, mask, i);
}
}
fn BulkStoreRange(&mut self, data: &[u8], mask: usize, ix_start: usize, ix_end: usize) {
for i in ix_start..ix_end {
self.Store(data, mask, i);
}
}

fn FindLongestMatch(&mut self,
dictionary: Option<&BrotliDictionary>,
Expand Down Expand Up @@ -1393,6 +1402,9 @@ impl<Alloc: alloc::Allocator<u16> + alloc::Allocator<u32>> AnyHasher
fn StoreRange(&mut self, data: &[u8], mask: usize, ix_start: usize, ix_end: usize) {
return match_all_hashers_mut!(self, StoreRange, data, mask, ix_start, ix_end);
}
fn BulkStoreRange(&mut self, data: &[u8], mask: usize, ix_start: usize, ix_end: usize) {
return match_all_hashers_mut!(self, BulkStoreRange, data, mask, ix_start, ix_end);
}
}

impl<Alloc: alloc::Allocator<u16> + alloc::Allocator<u32>> UnionHasher<Alloc> {
Expand Down
5 changes: 5 additions & 0 deletions src/enc/hash_to_binary_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ impl<AllocU32: Allocator<u32>,
i = i.wrapping_add(1 as (usize));
}
}
fn BulkStoreRange(&mut self, data: &[u8], mask: usize, ix_start: usize, ix_end: usize) {
for i in ix_start..ix_end {
self.Store(data, mask, i);
}
}
fn Prepare(&mut self, _one_shot: bool, _input_size: usize, _data: &[u8]) -> HowPrepared {
if self.common.is_prepared_ != 0 {
return HowPrepared::ALREADY_PREPARED;
Expand Down

0 comments on commit a56f4fd

Please sign in to comment.