diff --git a/components/style/restyle_hints.rs b/components/style/restyle_hints.rs index ba69870d53a..2d5d9aed27c 100644 --- a/components/style/restyle_hints.rs +++ b/components/style/restyle_hints.rs @@ -16,7 +16,7 @@ use element_state::*; use gecko_bindings::structs::nsRestyleHint; #[cfg(feature = "servo")] use heapsize::HeapSizeOf; -use selector_map::SelectorMap; +use selector_map::{SelectorMap, SelectorMapEntry}; use selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl, Snapshot, SnapshotMap, AttrValue}; use selectors::Element; use selectors::attr::{AttrSelectorOperation, NamespaceConstraint}; @@ -25,7 +25,6 @@ use selectors::matching::matches_selector; use selectors::parser::{Combinator, Component, Selector, SelectorInner, SelectorMethods}; use selectors::visitor::SelectorVisitor; use smallvec::SmallVec; -use std::borrow::Borrow; use std::cell::Cell; use std::clone::Clone; use std::cmp; @@ -759,8 +758,8 @@ pub struct Dependency { pub sensitivities: Sensitivities, } -impl Borrow> for Dependency { - fn borrow(&self) -> &SelectorInner { +impl SelectorMapEntry for Dependency { + fn selector(&self) -> &SelectorInner { &self.selector } } diff --git a/components/style/selector_map.rs b/components/style/selector_map.rs index 47a236f3d88..497baf2f914 100644 --- a/components/style/selector_map.rs +++ b/components/style/selector_map.rs @@ -20,6 +20,18 @@ use std::collections::HashMap; use std::hash::Hash; use stylist::{ApplicableDeclarationBlock, Rule}; +/// A trait to abstract over a given selector map entry. +pub trait SelectorMapEntry : Sized + Clone { + /// Get the selector we should use to index in the selector map. + fn selector(&self) -> &SelectorInner; +} + +impl SelectorMapEntry for SelectorInner { + fn selector(&self) -> &SelectorInner { + self + } +} + /// Map element data to selector-providing objects for which the last simple /// selector starts with them. /// @@ -44,7 +56,7 @@ use stylist::{ApplicableDeclarationBlock, Rule}; /// TODO: Tune the initial capacity of the HashMap #[derive(Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -pub struct SelectorMap>> { +pub struct SelectorMap { /// A hash from an ID to rules which contain that ID selector. pub id_hash: FnvHashMap>, /// A hash from a class name to rules which contain that class selector. @@ -62,7 +74,7 @@ fn sort_by_key K, K: Ord>(v: &mut [T], f: F) { sort_by(v, |a, b| f(a).cmp(&f(b))) } -impl SelectorMap where T: Clone + Borrow> { +impl SelectorMap { /// Trivially constructs an empty `SelectorMap`. pub fn new() -> Self { SelectorMap { @@ -217,22 +229,22 @@ impl SelectorMap { } } -impl SelectorMap where T: Clone + Borrow> { +impl SelectorMap { /// Inserts into the correct hash, trying id, class, and localname. pub fn insert(&mut self, entry: T) { self.count += 1; - if let Some(id_name) = get_id_name(entry.borrow()) { + if let Some(id_name) = get_id_name(entry.selector()) { find_push(&mut self.id_hash, id_name, entry); return; } - if let Some(class_name) = get_class_name(entry.borrow()) { + if let Some(class_name) = get_class_name(entry.selector()) { find_push(&mut self.class_hash, class_name, entry); return; } - if let Some(LocalNameSelector { name, lower_name }) = get_local_name(entry.borrow()) { + if let Some(LocalNameSelector { name, lower_name }) = get_local_name(entry.selector()) { // If the local name in the selector isn't lowercase, insert it into // the rule hash twice. This means that, during lookup, we can always // find the rules based on the local name of the element, regardless diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 9fd06ee16c5..7fb64c8acf5 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -22,7 +22,7 @@ use properties::INHERIT_ALL; use properties::PropertyDeclarationBlock; use restyle_hints::{HintComputationContext, DependencySet, RestyleHint}; use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource}; -use selector_map::SelectorMap; +use selector_map::{SelectorMap, SelectorMapEntry}; use selector_parser::{SelectorImpl, PseudoElement}; use selectors::attr::NamespaceConstraint; use selectors::bloom::BloomFilter; @@ -33,7 +33,6 @@ use selectors::visitor::SelectorVisitor; use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards}; use sink::Push; use smallvec::{SmallVec, VecLike}; -use std::borrow::Borrow; #[cfg(feature = "servo")] use std::marker::PhantomData; use style_traits::viewport::ViewportConstraints; @@ -1252,8 +1251,8 @@ pub struct Rule { pub source_order: usize, } -impl Borrow> for Rule { - fn borrow(&self) -> &SelectorInner { +impl SelectorMapEntry for Rule { + fn selector(&self) -> &SelectorInner { &self.selector.inner } }