From aaa0b3316b0f0486f4e526a9324fc57dbd592c20 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 26 Oct 2016 19:47:38 +0200 Subject: [PATCH] Implement selectors_bloom::BloomHash for Atom and Namespace. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This new dependency is temporary. With https://github.com/servo/string-cache/pull/136 it’ll go into html5ever. --- Cargo.toml | 3 ++- src/atom/mod.rs | 8 ++++++++ src/lib.rs | 1 + src/namespace.rs | 7 +++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0ece410..99a7c13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "string_cache" -version = "0.2.30" +version = "0.2.31" authors = [ "The Servo Project Developers" ] description = "A string interning library for Rust, developed as part of the Servo project." license = "MIT / Apache-2.0" @@ -29,6 +29,7 @@ lazy_static = "0.2" serde = ">=0.6, <0.9" phf_shared = "0.7.4" debug_unreachable = "0.1.1" +selectors-bloom = "0.1" [dev-dependencies] rand = "0.3" diff --git a/src/atom/mod.rs b/src/atom/mod.rs index 0e8f7ef..6c4aeb4 100644 --- a/src/atom/mod.rs +++ b/src/atom/mod.rs @@ -201,6 +201,7 @@ impl Atom { UnpackedAtom::from_packed(self.unsafe_data) } + #[inline] pub fn get_hash(&self) -> u32 { ((self.unsafe_data >> 32) ^ self.unsafe_data) as u32 } @@ -396,6 +397,13 @@ impl Deserialize for Atom { } } +impl ::selectors_bloom::BloomHash for Atom { + #[inline] + fn bloom_hash(&self) -> u32 { + self.get_hash() + } +} + // AsciiExt requires mutating methods, so we just implement the non-mutating ones. // We don't need to implement is_ascii because there's no performance improvement // over the one from &str. diff --git a/src/lib.rs b/src/lib.rs index b466a77..8701f64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ #[macro_use] extern crate debug_unreachable; extern crate serde; extern crate phf_shared; +extern crate selectors_bloom; pub use atom::{Atom, BorrowedAtom}; pub use namespace::{BorrowedNamespace, Namespace, QualName}; diff --git a/src/namespace.rs b/src/namespace.rs index 12bd718..911527e 100644 --- a/src/namespace.rs +++ b/src/namespace.rs @@ -44,6 +44,13 @@ impl fmt::Display for Namespace { } } +impl ::selectors_bloom::BloomHash for Namespace { + #[inline] + fn bloom_hash(&self) -> u32 { + self.0.get_hash() + } +} + /// A name with a namespace. #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)] pub struct QualName {