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

Implement selectors_bloom::BloomHash for Atom and Namespace. #177

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions src/atom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
7 changes: 7 additions & 0 deletions src/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down