Permalink
Browse files

Move PrecomputedHash bounds to where they’re actually needed.

  • Loading branch information...
SimonSapin committed Jan 12, 2018
1 parent b0003f7 commit 5d920df460191aac756541000fcb321300d8e8a2
Showing with 22 additions and 18 deletions.
  1. +22 −13 components/selectors/parser.rs
  2. +0 −5 components/selectors/size_of_tests.rs
@@ -86,10 +86,10 @@ macro_rules! with_all_bounds {
pub trait SelectorImpl: Clone + Sized + 'static {
type ExtraMatchingData: Sized + Default + 'static;
type AttrValue: $($InSelector)*;
type Identifier: $($InSelector)* + PrecomputedHash;
type ClassName: $($InSelector)* + PrecomputedHash;
type LocalName: $($InSelector)* + Borrow<Self::BorrowedLocalName> + PrecomputedHash;
type NamespaceUrl: $($CommonBounds)* + Default + Borrow<Self::BorrowedNamespaceUrl> + PrecomputedHash;
type Identifier: $($InSelector)*;
type ClassName: $($InSelector)*;
type LocalName: $($InSelector)* + Borrow<Self::BorrowedLocalName>;
type NamespaceUrl: $($CommonBounds)* + Default + Borrow<Self::BorrowedNamespaceUrl>;
type NamespacePrefix: $($InSelector)* + Default;
type BorrowedNamespaceUrl: ?Sized + Eq;
type BorrowedLocalName: ?Sized + Eq;
@@ -275,14 +275,24 @@ impl AncestorHashes {
pub fn new<Impl: SelectorImpl>(
selector: &Selector<Impl>,
quirks_mode: QuirksMode,
) -> Self {
) -> Self
where Impl::Identifier: PrecomputedHash,
Impl::ClassName: PrecomputedHash,
Impl::LocalName: PrecomputedHash,
Impl::NamespaceUrl: PrecomputedHash,
{
Self::from_iter(selector.iter(), quirks_mode)
}
fn from_iter<Impl: SelectorImpl>(
iter: SelectorIter<Impl>,
quirks_mode: QuirksMode,
) -> Self {
) -> Self
where Impl::Identifier: PrecomputedHash,
Impl::ClassName: PrecomputedHash,
Impl::LocalName: PrecomputedHash,
Impl::NamespaceUrl: PrecomputedHash,
{
// Compute ancestor hashes for the bloom filter.
let mut hashes = [0u32; 4];
let mut hash_iter = AncestorIter::new(iter)
@@ -789,7 +799,12 @@ pub enum Component<Impl: SelectorImpl> {
impl<Impl: SelectorImpl> Component<Impl> {
/// Compute the ancestor hash to check against the bloom filter.
fn ancestor_hash(&self, quirks_mode: QuirksMode) -> Option<u32> {
fn ancestor_hash(&self, quirks_mode: QuirksMode) -> Option<u32>
where Impl::Identifier: PrecomputedHash,
Impl::ClassName: PrecomputedHash,
Impl::LocalName: PrecomputedHash,
Impl::NamespaceUrl: PrecomputedHash,
{
match *self {
Component::LocalName(LocalName { ref name, ref lower_name }) => {
// Only insert the local-name into the filter if it's all
@@ -2068,12 +2083,6 @@ pub mod tests {
}
}
impl PrecomputedHash for DummyAtom {
fn precomputed_hash(&self) -> u32 {
return 0
}
}
impl<'i> Parser<'i> for DummyParser {
type Impl = DummySelectorImpl;
type Error = SelectorParseErrorKind<'i>;
@@ -7,7 +7,6 @@ use gecko_like_types;
use gecko_like_types::*;
use parser;
use parser::*;
use precomputed_hash::PrecomputedHash;
use std::fmt;
use visitor::SelectorVisitor;
@@ -68,7 +67,3 @@ impl From<String> for Atom {
impl<'a> From<&'a str> for Atom {
fn from(_: &'a str) -> Self { unimplemented!() }
}
impl PrecomputedHash for Atom {
fn precomputed_hash(&self) -> u32 { unimplemented!() }
}

0 comments on commit 5d920df

Please sign in to comment.