mirror of
https://github.com/servo/servo.git
synced 2025-07-19 13:23:46 +01:00
style: Hash less stuff in the bloom filter, using the precomputed hashes we have.
This commit is contained in:
parent
65ebbb7c56
commit
e29b84de18
10 changed files with 129 additions and 63 deletions
|
@ -44,6 +44,7 @@ num-traits = "0.1.32"
|
|||
ordered-float = "0.4"
|
||||
parking_lot = "0.3.3"
|
||||
pdqsort = "0.1.0"
|
||||
precomputed-hash = "0.1"
|
||||
rayon = "0.6"
|
||||
selectors = { path = "../selectors" }
|
||||
serde = {version = "0.9", optional = true}
|
||||
|
|
|
@ -10,6 +10,7 @@ use gecko_bindings::bindings::Gecko_AddRefAtom;
|
|||
use gecko_bindings::bindings::Gecko_Atomize;
|
||||
use gecko_bindings::bindings::Gecko_ReleaseAtom;
|
||||
use gecko_bindings::structs::nsIAtom;
|
||||
use precomputed_hash::PrecomputedHash;
|
||||
use std::borrow::{Cow, Borrow};
|
||||
use std::char::{self, DecodeUtf16};
|
||||
use std::fmt::{self, Write};
|
||||
|
@ -56,6 +57,13 @@ impl Deref for Atom {
|
|||
}
|
||||
}
|
||||
|
||||
impl PrecomputedHash for Atom {
|
||||
#[inline]
|
||||
fn precomputed_hash(&self) -> u32 {
|
||||
self.get_hash()
|
||||
}
|
||||
}
|
||||
|
||||
impl Borrow<WeakAtom> for Atom {
|
||||
#[inline]
|
||||
fn borrow(&self) -> &WeakAtom {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
//! A type to represent a namespace.
|
||||
|
||||
use gecko_bindings::structs::nsIAtom;
|
||||
use precomputed_hash::PrecomputedHash;
|
||||
use std::borrow::{Borrow, Cow};
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
@ -19,10 +20,27 @@ macro_rules! ns {
|
|||
#[derive(Debug, PartialEq, Eq, Clone, Default, Hash)]
|
||||
pub struct Namespace(pub Atom);
|
||||
|
||||
impl PrecomputedHash for Namespace {
|
||||
#[inline]
|
||||
fn precomputed_hash(&self) -> u32 {
|
||||
self.0.precomputed_hash()
|
||||
}
|
||||
}
|
||||
|
||||
/// A Gecko WeakNamespace is a wrapped WeakAtom.
|
||||
#[derive(Hash)]
|
||||
pub struct WeakNamespace(WeakAtom);
|
||||
|
||||
impl Deref for WeakNamespace {
|
||||
type Target = WeakAtom;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &WeakAtom {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Deref for Namespace {
|
||||
type Target = WeakNamespace;
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ extern crate num_traits;
|
|||
extern crate ordered_float;
|
||||
extern crate parking_lot;
|
||||
extern crate pdqsort;
|
||||
#[cfg(feature = "gecko")] extern crate precomputed_hash;
|
||||
extern crate rayon;
|
||||
extern crate selectors;
|
||||
#[cfg(feature = "servo")] #[macro_use] extern crate serde_derive;
|
||||
|
|
|
@ -1175,23 +1175,30 @@ pub trait MatchMethods : TElement {
|
|||
/// Therefore, each node must have its matching selectors inserted _after_
|
||||
/// its own selector matching and _before_ its children start.
|
||||
fn insert_into_bloom_filter(&self, bf: &mut BloomFilter) {
|
||||
bf.insert(&*self.get_local_name());
|
||||
bf.insert(&*self.get_namespace());
|
||||
self.get_id().map(|id| bf.insert(&id));
|
||||
|
||||
bf.insert_hash(self.get_local_name().get_hash());
|
||||
bf.insert_hash(self.get_namespace().get_hash());
|
||||
if let Some(id) = self.get_id() {
|
||||
bf.insert_hash(id.get_hash());
|
||||
}
|
||||
// TODO: case-sensitivity depends on the document type and quirks mode
|
||||
self.each_class(|class| bf.insert(class));
|
||||
self.each_class(|class| {
|
||||
bf.insert_hash(class.get_hash())
|
||||
});
|
||||
}
|
||||
|
||||
/// After all the children are done css selector matching, this must be
|
||||
/// called to reset the bloom filter after an `insert`.
|
||||
fn remove_from_bloom_filter(&self, bf: &mut BloomFilter) {
|
||||
bf.remove(&*self.get_local_name());
|
||||
bf.remove(&*self.get_namespace());
|
||||
self.get_id().map(|id| bf.remove(&id));
|
||||
bf.remove_hash(self.get_local_name().get_hash());
|
||||
bf.remove_hash(self.get_namespace().get_hash());
|
||||
if let Some(id) = self.get_id() {
|
||||
bf.remove_hash(id.get_hash());
|
||||
}
|
||||
|
||||
// TODO: case-sensitivity depends on the document type and quirks mode
|
||||
self.each_class(|class| bf.remove(class));
|
||||
self.each_class(|class| {
|
||||
bf.remove_hash(class.get_hash())
|
||||
});
|
||||
}
|
||||
|
||||
/// Given the old and new style of this element, and whether it's a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue