1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-04 10:34:11 +02:00

use more optimized way to store things in state

This commit is contained in:
Robin Appelman 2019-08-29 16:47:32 +02:00
commit 33b8d76e88
5 changed files with 55 additions and 8 deletions

40
src/nullhasher.rs Normal file
View file

@ -0,0 +1,40 @@
use std::hash::{BuildHasher, Hasher};
/// A dummy hasher that maps simply returns the hashed u64
///
/// trying to hash anything but a u64 will result in a panic
pub struct NullHasher {
data: u64,
}
impl Hasher for NullHasher {
#[inline]
fn finish(&self) -> u64 {
self.data
}
#[inline]
fn write(&mut self, _msg: &[u8]) {
panic!("can only hash u64 as u32");
}
#[inline]
fn write_u32(&mut self, data: u32) {
self.data = data as u64
}
#[inline]
fn write_u64(&mut self, data: u64) {
self.data = data;
}
}
pub struct NullHasherBuilder;
impl BuildHasher for NullHasherBuilder {
type Hasher = NullHasher;
fn build_hasher(&self) -> Self::Hasher {
NullHasher { data: 0 }
}
}