From 8d617d72e747e467a30961bb8118405c513be801 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Tue, 14 Jan 2020 20:48:52 +0100 Subject: [PATCH] Drop byteorder dependency --- Cargo.toml | 3 +-- lib.rs | 14 ++++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3977102..141f6ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,7 @@ name = "fxhash" path = "bench.rs" [dependencies] -byteorder = "1.0.0" [dev-dependencies] seahash = "3.0.5" -fnv = "1.0.5" \ No newline at end of file +fnv = "1.0.5" diff --git a/lib.rs b/lib.rs index 1abff27..b4b4253 100644 --- a/lib.rs +++ b/lib.rs @@ -29,9 +29,7 @@ use std::collections::{HashMap, HashSet}; use std::default::Default; use std::hash::{BuildHasherDefault, Hash, Hasher}; use std::ops::BitXor; - -extern crate byteorder; -use byteorder::{ByteOrder, NativeEndian}; +use std::convert::TryInto; /// A builder for default Fx hashers. pub type FxBuildHasher = BuildHasherDefault; @@ -79,12 +77,12 @@ impl_hash_word!(usize = SEED, u32 = SEED32, u64 = SEED64); #[inline] fn write32(mut hash: u32, mut bytes: &[u8]) -> u32 { while bytes.len() >= 4 { - hash.hash_word(NativeEndian::read_u32(bytes)); + hash.hash_word(u32::from_ne_bytes(bytes[..4].try_into().unwrap())); bytes = &bytes[4..]; } if bytes.len() >= 2 { - hash.hash_word(u32::from(NativeEndian::read_u16(bytes))); + hash.hash_word(u32::from(u16::from_ne_bytes(bytes[..2].try_into().unwrap()))); bytes = &bytes[2..]; } @@ -98,17 +96,17 @@ fn write32(mut hash: u32, mut bytes: &[u8]) -> u32 { #[inline] fn write64(mut hash: u64, mut bytes: &[u8]) -> u64 { while bytes.len() >= 8 { - hash.hash_word(NativeEndian::read_u64(bytes)); + hash.hash_word(u64::from_ne_bytes(bytes[..8].try_into().unwrap())); bytes = &bytes[8..]; } if bytes.len() >= 4 { - hash.hash_word(u64::from(NativeEndian::read_u32(bytes))); + hash.hash_word(u64::from(u32::from_ne_bytes(bytes[..4].try_into().unwrap()))); bytes = &bytes[4..]; } if bytes.len() >= 2 { - hash.hash_word(u64::from(NativeEndian::read_u16(bytes))); + hash.hash_word(u64::from(u16::from_ne_bytes(bytes[..2].try_into().unwrap()))); bytes = &bytes[2..]; }