Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove byteorder dependency #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ license = "MIT OR Apache-2.0"
name = "hash32"
repository = "https://github.com/japaric/hash32"
version = "0.3.1"

[dependencies.byteorder]
default-features = false
version = "1.2.2"
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
#![deny(warnings)]
#![no_std]

extern crate byteorder;

use core::fmt;
use core::hash::BuildHasher;
use core::marker::PhantomData;
Expand Down
22 changes: 15 additions & 7 deletions src/murmur3.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use core::slice;
use core::mem::MaybeUninit;

use byteorder::{ByteOrder, LE};
use core::slice;

use crate::Hasher as _;

Expand Down Expand Up @@ -60,7 +58,11 @@ impl Hasher {
// self.buf.bytes[start..start+len].copy_from(buf);
for i in 0..len {
unsafe {
*self.buf.bytes.assume_init_mut().get_unchecked_mut(start + i) = *buf.get_unchecked(i);
*self
.buf
.bytes
.assume_init_mut()
.get_unchecked_mut(start + i) = *buf.get_unchecked(i);
}
}
self.index = Index::from(start + len);
Expand All @@ -71,7 +73,9 @@ impl Default for Hasher {
#[allow(deprecated)]
fn default() -> Self {
Hasher {
buf: Buffer { bytes: MaybeUninit::uninit() },
buf: Buffer {
bytes: MaybeUninit::uninit(),
},
index: Index::_0,
processed: 0,
state: State(0),
Expand Down Expand Up @@ -146,7 +150,11 @@ impl core::hash::Hasher for Hasher {
// self.buf.bytes[index..].copy_from_slice(head);
for i in 0..4 - index {
unsafe {
*self.buf.bytes.assume_init_mut().get_unchecked_mut(index + i) = *head.get_unchecked(i);
*self
.buf
.bytes
.assume_init_mut()
.get_unchecked_mut(index + i) = *head.get_unchecked(i);
}
}

Expand Down Expand Up @@ -192,7 +200,7 @@ const R1: u32 = 15;

impl State {
fn process_block(&mut self, block: &MaybeUninit<[u8; 4]>) {
self.0 ^= pre_mix(LE::read_u32(unsafe { block.assume_init_ref() }));
self.0 ^= pre_mix(u32::from_le_bytes(unsafe { *block.assume_init_ref() }));
self.0 = self.0.rotate_left(13);
self.0 = 5u32.wrapping_mul(self.0).wrapping_add(0xe6546b64);
}
Expand Down