stylo: Replace all hashtable collections with ones from style::hash

This commit is contained in:
Manish Goregaokar 2017-08-31 15:28:01 -07:00
parent fae5e10643
commit 5cd296a264
No known key found for this signature in database
GPG key ID: 3BBF4D3E2EF79F98
9 changed files with 29 additions and 14 deletions

9
Cargo.lock generated
View file

@ -1242,6 +1242,14 @@ dependencies = [
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "hashglobe"
version = "0.1.0"
dependencies = [
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "heapsize" name = "heapsize"
version = "0.4.0" version = "0.4.0"
@ -3078,6 +3086,7 @@ dependencies = [
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"hashglobe 0.1.0",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"html5ever 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -14,7 +14,7 @@ use selectors::parser::SelectorParseError;
use servo_arc::Arc; use servo_arc::Arc;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::{Borrow, Cow}; use std::borrow::{Borrow, Cow};
use std::collections::{HashMap, HashSet}; use hash::{HashMap, HashSet};
use std::fmt; use std::fmt;
use std::hash::Hash; use std::hash::Hash;
use style_traits::{ToCss, StyleParseError, ParseError}; use style_traits::{ToCss, StyleParseError, ParseError};

View file

@ -28,7 +28,7 @@ use servo_arc::{Arc, ArcBorrow};
use shared_lock::Locked; use shared_lock::Locked;
use smallvec::VecLike; use smallvec::VecLike;
use std::fmt; use std::fmt;
#[cfg(feature = "gecko")] use std::collections::HashMap; #[cfg(feature = "gecko")] use hash::HashMap;
use std::fmt::Debug; use std::fmt::Debug;
use std::hash::Hash; use std::hash::Hash;
use std::ops::Deref; use std::ops::Deref;

View file

@ -83,7 +83,7 @@ use selectors::sink::Push;
use servo_arc::{Arc, ArcBorrow, RawOffsetArc}; use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
use shared_lock::Locked; use shared_lock::Locked;
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap; use hash::HashMap;
use std::fmt; use std::fmt;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::mem; use std::mem;
@ -1361,7 +1361,7 @@ impl<'le> TElement for GeckoElement<'le> {
after_change_style: &ComputedValues) after_change_style: &ComputedValues)
-> bool { -> bool {
use gecko_bindings::structs::nsCSSPropertyID; use gecko_bindings::structs::nsCSSPropertyID;
use std::collections::HashSet; use hash::HashSet;
debug_assert!(self.might_need_transitions_update(Some(before_change_style), debug_assert!(self.might_need_transitions_update(Some(before_change_style),
after_change_style), after_change_style),

View file

@ -31,7 +31,7 @@ use selectors::parser::SelectorParseError;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::borrow::Cow; use std::borrow::Cow;
use std::cmp; use std::cmp;
#[cfg(feature = "gecko")] use fnv::FnvHashMap; #[cfg(feature = "gecko")] use hash::FnvHashMap;
use style_traits::ParseError; use style_traits::ParseError;
use super::ComputedValues; use super::ComputedValues;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]

View file

@ -416,7 +416,7 @@ ${helpers.predefined_type("object-position",
products="gecko" products="gecko"
animation_value_type="discrete" animation_value_type="discrete"
boxed="True"> boxed="True">
use std::collections::HashMap; use hash::HashMap;
use std::fmt; use std::fmt;
use std::ops::Range; use std::ops::Range;
use str::HTML_SPACE_CHARACTERS; use str::HTML_SPACE_CHARACTERS;

View file

@ -13,7 +13,7 @@
#[cfg(feature = "servo")] use app_units::Au; #[cfg(feature = "servo")] use app_units::Au;
use servo_arc::{Arc, UniqueArc}; use servo_arc::{Arc, UniqueArc};
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::HashSet; use hash::HashSet;
use std::{fmt, mem, ops}; use std::{fmt, mem, ops};
#[cfg(feature = "gecko")] use std::ptr; #[cfg(feature = "gecko")] use std::ptr;

View file

@ -1000,7 +1000,7 @@ impl StrongRuleNode {
unsafe fn assert_free_list_has_no_duplicates_or_null(&self) { unsafe fn assert_free_list_has_no_duplicates_or_null(&self) {
assert!(cfg!(debug_assertions), "This is an expensive check!"); assert!(cfg!(debug_assertions), "This is an expensive check!");
use std::collections::HashSet; use hash::HashSet;
let me = &*self.ptr(); let me = &*self.ptr();
assert!(me.is_root()); assert!(me.is_root());

View file

@ -16,8 +16,8 @@ use selector_parser::SelectorImpl;
use selectors::matching::{matches_selector, MatchingContext, ElementSelectorFlags}; use selectors::matching::{matches_selector, MatchingContext, ElementSelectorFlags};
use selectors::parser::{Component, Combinator, SelectorIter}; use selectors::parser::{Component, Combinator, SelectorIter};
use smallvec::{SmallVec, VecLike}; use smallvec::{SmallVec, VecLike};
use std::collections::{HashMap, HashSet}; use hash::{HashMap, HashSet};
use std::collections::hash_map; use hash::map as hash_map;
use std::hash::{BuildHasherDefault, Hash, Hasher}; use std::hash::{BuildHasherDefault, Hash, Hasher};
use stylist::Rule; use stylist::Rule;
@ -93,7 +93,7 @@ pub trait SelectorMapEntry : Sized + Clone {
/// TODO: Tune the initial capacity of the HashMap /// TODO: Tune the initial capacity of the HashMap
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SelectorMap<T> { pub struct SelectorMap<T: 'static> {
/// A hash from an ID to rules which contain that ID selector. /// A hash from an ID to rules which contain that ID selector.
pub id_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>, pub id_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>,
/// A hash from a class name to rules which contain that class selector. /// A hash from a class name to rules which contain that class selector.
@ -111,7 +111,10 @@ fn sort_by_key<T, F: Fn(&T) -> K, K: Ord>(v: &mut [T], f: F) {
sort_by(v, |a, b| f(a).cmp(&f(b))) sort_by(v, |a, b| f(a).cmp(&f(b)))
} }
impl<T> SelectorMap<T> { // FIXME(Manishearth) the 'static bound can be removed when
// our HashMap fork (hashglobe) is able to use NonZero,
// or when stdlib gets fallible collections
impl<T: 'static> SelectorMap<T> {
/// Trivially constructs an empty `SelectorMap`. /// Trivially constructs an empty `SelectorMap`.
pub fn new() -> Self { pub fn new() -> Self {
SelectorMap { SelectorMap {
@ -461,9 +464,12 @@ fn find_push<Str: Eq + Hash, V, VL>(map: &mut PrecomputedHashMap<Str, VL>,
/// Wrapper for PrecomputedHashMap that does ASCII-case-insensitive lookup in quirks mode. /// Wrapper for PrecomputedHashMap that does ASCII-case-insensitive lookup in quirks mode.
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct MaybeCaseInsensitiveHashMap<K: PrecomputedHash + Hash + Eq, V>(PrecomputedHashMap<K, V>); pub struct MaybeCaseInsensitiveHashMap<K: PrecomputedHash + Hash + Eq, V: 'static>(PrecomputedHashMap<K, V>);
impl<V> MaybeCaseInsensitiveHashMap<Atom, V> { // FIXME(Manishearth) the 'static bound can be removed when
// our HashMap fork (hashglobe) is able to use NonZero,
// or when stdlib gets fallible collections
impl<V: 'static> MaybeCaseInsensitiveHashMap<Atom, V> {
/// Empty map /// Empty map
pub fn new() -> Self { pub fn new() -> Self {
MaybeCaseInsensitiveHashMap(PrecomputedHashMap::default()) MaybeCaseInsensitiveHashMap(PrecomputedHashMap::default())