Bug 1477628 - Convert FnvHash{Set,Map} instances to FxHash{Set,Map} (attempt 2). r=heycam

This commit is contained in:
Nicholas Nethercote 2018-07-27 16:49:04 +10:00
Родитель 38f29ba537
Коммит 6a531f189d
19 изменённых файлов: 51 добавлений и 45 удалений

3
Cargo.lock сгенерированный
Просмотреть файл

@ -1805,6 +1805,7 @@ dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1952,7 +1953,7 @@ dependencies = [
"cssparser 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fallible 0.0.1",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"hashglobe 0.1.0",
"itertools 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",

Просмотреть файл

@ -25,6 +25,7 @@ matches = "0.1"
cssparser = "0.24.0"
log = "0.4"
fnv = "1.0"
fxhash = "0.2"
phf = "0.7.18"
precomputed-hash = "0.1"
servo_arc = { version = "0.1", path = "../servo_arc" }

Просмотреть файл

@ -297,6 +297,9 @@ impl Clone for BloomStorageBool {
}
fn hash<T: Hash>(elem: &T) -> u32 {
// We generally use FxHasher in Stylo because it's faster than FnvHasher,
// but the increased collision rate has outsized effect on the bloom
// filter, so we use FnvHasher instead here.
let mut hasher = FnvHasher::default();
elem.hash(&mut hasher);
let hash: u64 = hasher.finish();

Просмотреть файл

@ -10,6 +10,7 @@ extern crate bitflags;
#[macro_use]
extern crate cssparser;
extern crate fnv;
extern crate fxhash;
#[macro_use]
extern crate log;
#[macro_use]

Просмотреть файл

@ -2,7 +2,7 @@
* 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/. */
use fnv::FnvHashMap;
use fxhash::FxHashMap;
use tree::OpaqueElement;
/// A cache to speed up matching of nth-index-like selectors.
@ -32,7 +32,7 @@ impl NthIndexCache {
/// The concrete per-pseudo-class cache.
#[derive(Default)]
pub struct NthIndexCacheInner(FnvHashMap<OpaqueElement, i32>);
pub struct NthIndexCacheInner(FxHashMap<OpaqueElement, i32>);
impl NthIndexCacheInner {
/// Does a lookup for a given element in the cache.

Просмотреть файл

@ -36,7 +36,7 @@ new_debug_unreachable = "1.0"
encoding_rs = {version = "0.7", optional = true}
euclid = "0.18"
fallible = { path = "../fallible" }
fnv = "1.0"
fxhash = "0.2"
hashglobe = { path = "../hashglobe" }
html5ever = {version = "0.22", optional = true}
itertools = "0.7.6"

Просмотреть файл

@ -14,7 +14,7 @@ use dom::{SendElement, TElement};
use dom::OpaqueNode;
use euclid::Size2D;
use euclid::TypedScale;
use fnv::FnvHashMap;
use fxhash::FxHashMap;
use font_metrics::FontMetricsProvider;
#[cfg(feature = "gecko")]
use gecko_bindings::structs;
@ -173,11 +173,11 @@ pub struct SharedStyleContext<'a> {
/// The animations that are currently running.
#[cfg(feature = "servo")]
pub running_animations: Arc<RwLock<FnvHashMap<OpaqueNode, Vec<Animation>>>>,
pub running_animations: Arc<RwLock<FxHashMap<OpaqueNode, Vec<Animation>>>>,
/// The list of animations that have expired since the last style recalculation.
#[cfg(feature = "servo")]
pub expired_animations: Arc<RwLock<FnvHashMap<OpaqueNode, Vec<Animation>>>>,
pub expired_animations: Arc<RwLock<FxHashMap<OpaqueNode, Vec<Animation>>>>,
/// Paint worklets
#[cfg(feature = "servo")]
@ -570,7 +570,7 @@ type CacheItem<E> = (SendElement<E>, ElementSelectorFlags);
/// flags until after the traversal.
pub struct SelectorFlagsMap<E: TElement> {
/// The hashmap storing the flags to apply.
map: FnvHashMap<SendElement<E>, ElementSelectorFlags>,
map: FxHashMap<SendElement<E>, ElementSelectorFlags>,
/// An LRU cache to avoid hashmap lookups, which can be slow if the map
/// gets big.
cache: LRUCache<[Entry<CacheItem<E>>; 4 + 1]>,
@ -587,7 +587,7 @@ impl<E: TElement> SelectorFlagsMap<E> {
/// Creates a new empty SelectorFlagsMap.
pub fn new() -> Self {
SelectorFlagsMap {
map: FnvHashMap::default(),
map: FxHashMap::default(),
cache: LRUCache::default(),
}
}
@ -833,7 +833,7 @@ pub trait RegisteredSpeculativePainter: SpeculativePainter {
/// The name it was registered with
fn name(&self) -> Atom;
/// The properties it was registered with
fn properties(&self) -> &FnvHashMap<Atom, PropertyId>;
fn properties(&self) -> &FxHashMap<Atom, PropertyId>;
}
/// A set of registered painters

Просмотреть файл

@ -62,7 +62,7 @@ use gecko_bindings::structs::nsChangeHint;
use gecko_bindings::structs::nsIDocument_DocumentTheme as DocumentTheme;
use gecko_bindings::structs::nsRestyleHint;
use gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI};
use hash::FnvHashMap;
use hash::FxHashMap;
use logical_geometry::WritingMode;
use media_queries::Device;
use properties::{ComputedValues, LonghandId};
@ -867,12 +867,12 @@ impl<'le> GeckoElement<'le> {
}
}
fn css_transitions_info(&self) -> FnvHashMap<LonghandId, Arc<AnimationValue>> {
fn css_transitions_info(&self) -> FxHashMap<LonghandId, Arc<AnimationValue>> {
use gecko_bindings::bindings::Gecko_ElementTransitions_EndValueAt;
use gecko_bindings::bindings::Gecko_ElementTransitions_Length;
let collection_length = unsafe { Gecko_ElementTransitions_Length(self.0) } as usize;
let mut map = FnvHashMap::with_capacity_and_hasher(collection_length, Default::default());
let mut map = FxHashMap::with_capacity_and_hasher(collection_length, Default::default());
for i in 0..collection_length {
let raw_end_value = unsafe { Gecko_ElementTransitions_EndValueAt(self.0, i) };
@ -893,7 +893,7 @@ impl<'le> GeckoElement<'le> {
combined_duration: f32,
before_change_style: &ComputedValues,
after_change_style: &ComputedValues,
existing_transitions: &FnvHashMap<LonghandId, Arc<AnimationValue>>,
existing_transitions: &FxHashMap<LonghandId, Arc<AnimationValue>>,
) -> bool {
use values::animated::{Animate, Procedure};
debug_assert!(!longhand_id.is_logical());

Просмотреть файл

@ -7,7 +7,7 @@
//! Can go away when the stdlib gets fallible collections
//! https://github.com/rust-lang/rfcs/pull/2116
use fnv;
use fxhash;
#[cfg(feature = "gecko")]
pub use hashglobe::hash_map::HashMap;
@ -25,7 +25,7 @@ pub mod map {
pub use std::collections::hash_map::{Entry, Iter};
}
/// Hash map that uses the FNV hasher
pub type FnvHashMap<K, V> = HashMap<K, V, fnv::FnvBuildHasher>;
/// Hash set that uses the FNV hasher
pub type FnvHashSet<T> = HashSet<T, fnv::FnvBuildHasher>;
/// Hash map that uses the Fx hasher
pub type FxHashMap<K, V> = HashMap<K, V, fxhash::FxBuildHasher>;
/// Hash set that uses the Fx hasher
pub type FxHashSet<T> = HashSet<T, fxhash::FxBuildHasher>;

Просмотреть файл

@ -5,7 +5,7 @@
//! Code related to the invalidation of media-query-affected rules.
use context::QuirksMode;
use fnv::FnvHashSet;
use fxhash::FxHashSet;
use media_queries::Device;
use shared_lock::SharedRwLockReadGuard;
use stylesheets::{DocumentRule, ImportRule, MediaRule};
@ -54,14 +54,14 @@ impl ToMediaListKey for MediaRule {}
#[derive(Debug, MallocSizeOf, PartialEq)]
pub struct EffectiveMediaQueryResults {
/// The set of media lists that matched last time.
set: FnvHashSet<MediaListKey>,
set: FxHashSet<MediaListKey>,
}
impl EffectiveMediaQueryResults {
/// Trivially constructs an empty `EffectiveMediaQueryResults`.
pub fn new() -> Self {
Self {
set: FnvHashSet::default(),
set: FxHashSet::default(),
}
}

Просмотреть файл

@ -11,7 +11,7 @@ use Atom;
use CaseSensitivityExt;
use LocalName as SelectorLocalName;
use dom::{TDocument, TElement, TNode};
use fnv::FnvHashSet;
use fxhash::FxHashSet;
use invalidation::element::element_wrapper::{ElementSnapshot, ElementWrapper};
use invalidation::element::restyle_hints::RestyleHint;
use media_queries::Device;
@ -106,9 +106,9 @@ impl Invalidation {
#[derive(MallocSizeOf)]
pub struct StylesheetInvalidationSet {
/// The subtrees we know we have to restyle so far.
invalid_scopes: FnvHashSet<Invalidation>,
invalid_scopes: FxHashSet<Invalidation>,
/// The elements we know we have to restyle so far.
invalid_elements: FnvHashSet<Invalidation>,
invalid_elements: FxHashSet<Invalidation>,
/// Whether the whole document should be restyled.
fully_invalid: bool,
}
@ -117,8 +117,8 @@ impl StylesheetInvalidationSet {
/// Create an empty `StylesheetInvalidationSet`.
pub fn new() -> Self {
Self {
invalid_scopes: FnvHashSet::default(),
invalid_elements: FnvHashSet::default(),
invalid_scopes: FxHashSet::default(),
invalid_elements: FxHashSet::default(),
fully_invalid: false,
}
}

Просмотреть файл

@ -42,7 +42,7 @@ extern crate cssparser;
extern crate debug_unreachable;
extern crate euclid;
extern crate fallible;
extern crate fnv;
extern crate fxhash;
#[cfg(feature = "gecko")]
#[macro_use]
pub mod gecko_string_cache;

Просмотреть файл

@ -25,7 +25,7 @@ use servo_arc::Arc;
use smallvec::SmallVec;
use std::{cmp, ptr};
use std::mem::{self, ManuallyDrop};
use hash::FnvHashMap;
use hash::FxHashMap;
use super::ComputedValues;
use values::CSSFloat;
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
@ -232,7 +232,7 @@ impl AnimatedProperty {
/// A collection of AnimationValue that were composed on an element.
/// This HashMap stores the values that are the last AnimationValue to be
/// composed for each TransitionProperty.
pub type AnimationValueMap = FnvHashMap<LonghandId, AnimationValue>;
pub type AnimationValueMap = FxHashMap<LonghandId, AnimationValue>;
#[cfg(feature = "gecko")]
unsafe impl HasFFI for AnimationValueMap {

Просмотреть файл

@ -2387,7 +2387,7 @@ pub use gecko_properties::style_structs;
/// The module where all the style structs are defined.
#[cfg(feature = "servo")]
pub mod style_structs {
use fnv::FnvHasher;
use fx::FxHasher;
use super::longhands;
use std::hash::{Hash, Hasher};
use logical_geometry::WritingMode;
@ -2534,7 +2534,7 @@ pub mod style_structs {
pub fn compute_font_hash(&mut self) {
// Corresponds to the fields in
// `gfx::font_template::FontTemplateDescriptor`.
let mut hasher: FnvHasher = Default::default();
let mut hasher: FxHasher = Default::default();
self.font_weight.hash(&mut hasher);
self.font_stretch.hash(&mut hasher);
self.font_style.hash(&mut hasher);

Просмотреть файл

@ -5,7 +5,7 @@
//! A cache from rule node to computed values, in order to cache reset
//! properties.
use fnv::FnvHashMap;
use fxhash::FxHashMap;
use logical_geometry::WritingMode;
use properties::{ComputedValues, StyleBuilder};
use rule_tree::StrongRuleNode;
@ -71,14 +71,14 @@ impl RuleCacheConditions {
/// A TLS cache from rules matched to computed values.
pub struct RuleCache {
// FIXME(emilio): Consider using LRUCache or something like that?
map: FnvHashMap<StrongRuleNode, SmallVec<[(RuleCacheConditions, Arc<ComputedValues>); 1]>>,
map: FxHashMap<StrongRuleNode, SmallVec<[(RuleCacheConditions, Arc<ComputedValues>); 1]>>,
}
impl RuleCache {
/// Creates an empty `RuleCache`.
pub fn new() -> Self {
Self {
map: FnvHashMap::default(),
map: FxHashMap::default(),
}
}

Просмотреть файл

@ -1146,13 +1146,13 @@ impl StrongRuleNode {
unsafe fn assert_free_list_has_no_duplicates_or_null(&self) {
assert!(cfg!(debug_assertions), "This is an expensive check!");
use hash::FnvHashSet;
use hash::FxHashSet;
let me = &*self.ptr();
assert!(me.is_root());
let mut current = self.ptr();
let mut seen = FnvHashSet::default();
let mut seen = FxHashSet::default();
while current != FREE_LIST_SENTINEL {
let next = (*current).next_free.load(Ordering::Relaxed);
assert!(!next.is_null());

Просмотреть файл

@ -11,7 +11,7 @@ use attr::{AttrIdentifier, AttrValue};
use cssparser::{serialize_identifier, CowRcStr, Parser as CssParser, SourceLocation, ToCss};
use dom::{OpaqueNode, TElement, TNode};
use element_state::{DocumentState, ElementState};
use fnv::FnvHashMap;
use fxhash::FxHashMap;
use invalidation::element::document_state::InvalidationMatchingData;
use invalidation::element::element_wrapper::ElementSnapshot;
use properties::{ComputedValues, PropertyFlags};
@ -617,12 +617,12 @@ impl SelectorImpl {
/// A map from elements to snapshots for the Servo style back-end.
#[derive(Debug)]
pub struct SnapshotMap(FnvHashMap<OpaqueNode, ServoElementSnapshot>);
pub struct SnapshotMap(FxHashMap<OpaqueNode, ServoElementSnapshot>);
impl SnapshotMap {
/// Create a new empty `SnapshotMap`.
pub fn new() -> Self {
SnapshotMap(FnvHashMap::default())
SnapshotMap(FxHashMap::default())
}
/// Get a snapshot given an element.
@ -632,7 +632,7 @@ impl SnapshotMap {
}
impl Deref for SnapshotMap {
type Target = FnvHashMap<OpaqueNode, ServoElementSnapshot>;
type Target = FxHashMap<OpaqueNode, ServoElementSnapshot>;
fn deref(&self) -> &Self::Target {
&self.0

Просмотреть файл

@ -7,7 +7,7 @@ use context::QuirksMode;
use cssparser::{Parser, ParserInput, RuleListParser};
use error_reporting::{ContextualParseError, ParseErrorReporter};
use fallible::FallibleVec;
use fnv::FnvHashMap;
use fxhash::FxHashMap;
use invalidation::media_queries::{MediaListKey, ToMediaListKey};
#[cfg(feature = "gecko")]
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
@ -42,7 +42,7 @@ pub struct UserAgentStylesheets {
#[allow(missing_docs)]
pub struct Namespaces {
pub default: Option<Namespace>,
pub prefixes: FnvHashMap<Prefix, Namespace>,
pub prefixes: FxHashMap<Prefix, Namespace>,
}
/// The contents of a given stylesheet. This effectively maps to a

Просмотреть файл

@ -8,7 +8,7 @@
//! [position]: https://drafts.csswg.org/css-backgrounds-3/#position
use cssparser::Parser;
use hash::FnvHashMap;
use hash::FxHashMap;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseErrorKind;
use servo_arc::Arc;
@ -548,7 +548,7 @@ impl TemplateAreas {
let mut width = 0;
{
let mut row = 0u32;
let mut area_indices = FnvHashMap::<&str, usize>::default();
let mut area_indices = FxHashMap::<&str, usize>::default();
for string in &strings {
let mut current_area_index: Option<usize> = None;
row += 1;