servo: Merge #18011 - style: Avoid hashing hashes (from emilio:less-dumb-hash); r=nox
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 08 Aug 2017 10:06:32 -0500
changeset 642653 a0f8b7a90139c3a459e26aa02dd9ee8c2cc3f570
parent 642652 84755985ba136a4afa2ea7d3e84626a3948417df
child 642654 309b1b63eb48ded8573cafdcc21602765fce3d9e
push id72833
push userbmo:emilio+bugs@crisal.io
push dateTue, 08 Aug 2017 16:50:16 +0000
reviewersnox
milestone57.0a1
servo: Merge #18011 - style: Avoid hashing hashes (from emilio:less-dumb-hash); r=nox These are the last instances I can find of us hashing the atoms hash. Source-Repo: https://github.com/servo/servo Source-Revision: dec4ba8ea6adb2477e4d3ba4916c886ac8b1dc0e
servo/components/style/gecko/data.rs
servo/components/style/stylist.rs
--- a/servo/components/style/gecko/data.rs
+++ b/servo/components/style/gecko/data.rs
@@ -2,26 +2,26 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! Data needed to style a Gecko document.
 
 use Atom;
 use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
 use dom::TElement;
-use fnv::FnvHashMap;
 use gecko::rules::{CounterStyleRule, FontFaceRule};
 use gecko_bindings::bindings::{self, RawServoStyleSet};
 use gecko_bindings::structs::{ServoStyleSheet, StyleSheetInfo, ServoStyleSheetInner};
 use gecko_bindings::structs::RawGeckoPresContextOwned;
 use gecko_bindings::structs::nsIDocument;
 use gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI};
 use invalidation::media_queries::{MediaListKey, ToMediaListKey};
 use media_queries::{Device, MediaList};
 use properties::ComputedValues;
+use selector_map::PrecomputedHashMap;
 use servo_arc::Arc;
 use shared_lock::{Locked, StylesheetGuards, SharedRwLockReadGuard};
 use stylesheet_set::StylesheetSet;
 use stylesheets::{Origin, StylesheetContents, StylesheetInDocument};
 use stylist::{ExtraStyleData, Stylist};
 
 /// Little wrapper to a Gecko style sheet.
 #[derive(PartialEq, Eq, Debug)]
@@ -119,17 +119,17 @@ pub struct PerDocumentStyleDataImpl {
 
     /// List of stylesheets, mirrored from Gecko.
     pub stylesheets: StylesheetSet<GeckoStyleSheet>,
 
     /// List of effective font face rules.
     pub font_faces: Vec<(Arc<Locked<FontFaceRule>>, Origin)>,
 
     /// Map for effective counter style rules.
-    pub counter_styles: FnvHashMap<Atom, Arc<Locked<CounterStyleRule>>>,
+    pub counter_styles: PrecomputedHashMap<Atom, Arc<Locked<CounterStyleRule>>>,
 }
 
 /// The data itself is an `AtomicRefCell`, which guarantees the proper semantics
 /// and unexpected races while trying to mutate it.
 pub struct PerDocumentStyleData(AtomicRefCell<PerDocumentStyleDataImpl>);
 
 impl PerDocumentStyleData {
     /// Create a dummy `PerDocumentStyleData`.
@@ -138,17 +138,17 @@ impl PerDocumentStyleData {
         let quirks_mode = unsafe {
             (*device.pres_context().mDocument.raw::<nsIDocument>()).mCompatMode
         };
 
         PerDocumentStyleData(AtomicRefCell::new(PerDocumentStyleDataImpl {
             stylist: Stylist::new(device, quirks_mode.into()),
             stylesheets: StylesheetSet::new(),
             font_faces: vec![],
-            counter_styles: FnvHashMap::default(),
+            counter_styles: PrecomputedHashMap::default(),
         }))
     }
 
     /// Get an immutable reference to this style data.
     pub fn borrow(&self) -> AtomicRef<PerDocumentStyleDataImpl> {
         self.0.borrow()
     }
 
--- a/servo/components/style/stylist.rs
+++ b/servo/components/style/stylist.rs
@@ -17,17 +17,17 @@ use invalidation::element::invalidation_
 use invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey};
 use media_queries::Device;
 use properties::{self, CascadeFlags, ComputedValues};
 use properties::{AnimationRules, PropertyDeclarationBlock};
 #[cfg(feature = "servo")]
 use properties::INHERIT_ALL;
 use properties::IS_LINK;
 use rule_tree::{CascadeLevel, RuleTree, StyleSource};
-use selector_map::{SelectorMap, SelectorMapEntry};
+use selector_map::{PrecomputedHashMap, SelectorMap, SelectorMapEntry};
 use selector_parser::{SelectorImpl, PerPseudoElementMap, PseudoElement};
 use selectors::attr::NamespaceConstraint;
 use selectors::bloom::BloomFilter;
 use selectors::matching::{ElementSelectorFlags, matches_selector, MatchingContext, MatchingMode};
 use selectors::matching::VisitedHandlingMode;
 use selectors::parser::{AncestorHashes, Combinator, Component, Selector};
 use selectors::parser::{SelectorIter, SelectorMethods};
 use selectors::sink::Push;
@@ -93,17 +93,17 @@ pub struct Stylist {
     /// evalutaing media rules against the current device, split out per
     /// cascade level.
     cascade_data: CascadeData,
 
     /// The rule tree, that stores the results of selector matching.
     rule_tree: RuleTree,
 
     /// A map with all the animations indexed by name.
-    animations: FnvHashMap<Atom, KeyframesAnimation>,
+    animations: PrecomputedHashMap<Atom, KeyframesAnimation>,
 
     /// Applicable declarations for a given non-eagerly cascaded pseudo-element.
     /// These are eagerly computed once, and then used to resolve the new
     /// computed values on the fly on layout.
     ///
     /// FIXME(emilio): Use the rule tree!
     precomputed_pseudo_element_decls: PerPseudoElementMap<Vec<ApplicableDeclarationBlock>>,
 
@@ -163,17 +163,17 @@ pub struct Stylist {
 
 /// This struct holds data which user of Stylist may want to extract
 /// from stylesheets which can be done at the same time as updating.
 #[cfg(feature = "gecko")]
 pub struct ExtraStyleData<'a> {
     /// A list of effective font-face rules and their origin.
     pub font_faces: &'a mut Vec<(Arc<Locked<FontFaceRule>>, Origin)>,
     /// A map of effective counter-style rules.
-    pub counter_styles: &'a mut FnvHashMap<Atom, Arc<Locked<CounterStyleRule>>>,
+    pub counter_styles: &'a mut PrecomputedHashMap<Atom, Arc<Locked<CounterStyleRule>>>,
 }
 
 #[cfg(feature = "gecko")]
 impl<'a> ExtraStyleData<'a> {
     /// Clear the internal data.
     fn clear(&mut self) {
         self.font_faces.clear();
         self.counter_styles.clear();
@@ -1324,17 +1324,17 @@ impl Stylist {
     /// media type have changed (for now).
     #[inline]
     pub fn is_device_dirty(&self) -> bool {
         self.is_device_dirty
     }
 
     /// Returns the map of registered `@keyframes` animations.
     #[inline]
-    pub fn animations(&self) -> &FnvHashMap<Atom, KeyframesAnimation> {
+    pub fn animations(&self) -> &PrecomputedHashMap<Atom, KeyframesAnimation> {
         &self.animations
     }
 
     /// Computes the match results of a given element against the set of
     /// revalidation selectors.
     pub fn match_revalidation_selectors<E, F>(&self,
                                               element: &E,
                                               bloom: Option<&BloomFilter>,