stylo: use FnvHashMap everywhere, remove default HashMap construction methods

This commit is contained in:
Manish Goregaokar 2017-10-02 10:34:00 -07:00
parent 0b69887387
commit 8bce37e6ba
7 changed files with 12 additions and 98 deletions

View file

@ -43,24 +43,6 @@ impl<K, V, S> DerefMut for HashMap<K, V, S> {
} }
} }
impl<K: Hash + Eq, V> HashMap<K, V, RandomState> {
#[inline]
pub fn new() -> HashMap<K, V, RandomState> {
HashMap(StdMap::new())
}
#[inline]
pub fn with_capacity(capacity: usize) -> HashMap<K, V, RandomState> {
HashMap(StdMap::with_capacity(capacity))
}
#[inline]
pub fn try_with_capacity(capacity: usize) -> Result<HashMap<K, V, RandomState>, FailedAllocationError> {
Ok(HashMap(StdMap::with_capacity(capacity)))
}
}
impl<K, V, S> HashMap<K, V, S> impl<K, V, S> HashMap<K, V, S>
where K: Eq + Hash, where K: Eq + Hash,
S: BuildHasher S: BuildHasher

View file

@ -583,42 +583,6 @@ impl<K, V, S> HashMap<K, V, S>
} }
} }
impl<K: Hash + Eq, V> HashMap<K, V, RandomState> {
/// Creates an empty `HashMap`.
///
/// # Examples
///
/// ```
/// use std::collections::HashMap;
/// let mut map: HashMap<&str, isize> = HashMap::new();
/// ```
#[inline]
pub fn new() -> HashMap<K, V, RandomState> {
Default::default()
}
/// Creates an empty `HashMap` with the specified capacity.
///
/// The hash map will be able to hold at least `capacity` elements without
/// reallocating. If `capacity` is 0, the hash map will not allocate.
///
/// # Examples
///
/// ```
/// use std::collections::HashMap;
/// let mut map: HashMap<&str, isize> = HashMap::with_capacity(10);
/// ```
#[inline]
pub fn with_capacity(capacity: usize) -> HashMap<K, V, RandomState> {
HashMap::with_capacity_and_hasher(capacity, Default::default())
}
#[inline]
pub fn try_with_capacity(capacity: usize) -> Result<HashMap<K, V, RandomState>, FailedAllocationError> {
HashMap::try_with_capacity_and_hasher(capacity, Default::default())
}
}
impl<K, V, S> HashMap<K, V, S> impl<K, V, S> HashMap<K, V, S>
where K: Eq + Hash, where K: Eq + Hash,
S: BuildHasher S: BuildHasher

View file

@ -121,38 +121,6 @@ pub struct HashSet<T, S = RandomState> {
map: HashMap<T, (), S>, map: HashMap<T, (), S>,
} }
impl<T: Hash + Eq> HashSet<T, RandomState> {
/// Creates an empty `HashSet`.
///
/// # Examples
///
/// ```
/// use std::collections::HashSet;
/// let set: HashSet<i32> = HashSet::new();
/// ```
#[inline]
pub fn new() -> HashSet<T, RandomState> {
HashSet { map: HashMap::new() }
}
/// Creates an empty `HashSet` with the specified capacity.
///
/// The hash set will be able to hold at least `capacity` elements without
/// reallocating. If `capacity` is 0, the hash set will not allocate.
///
/// # Examples
///
/// ```
/// use std::collections::HashSet;
/// let set: HashSet<i32> = HashSet::with_capacity(10);
/// assert!(set.capacity() >= 10);
/// ```
#[inline]
pub fn with_capacity(capacity: usize) -> HashSet<T, RandomState> {
HashSet { map: HashMap::with_capacity(capacity) }
}
}
impl<T, S> HashSet<T, S> impl<T, S> HashSet<T, S>
where T: Eq + Hash, where T: Eq + Hash,
S: BuildHasher S: BuildHasher

View file

@ -28,7 +28,7 @@ use selectors::sink::Push;
use servo_arc::{Arc, ArcBorrow}; use servo_arc::{Arc, ArcBorrow};
use shared_lock::Locked; use shared_lock::Locked;
use std::fmt; use std::fmt;
#[cfg(feature = "gecko")] use hash::HashMap; #[cfg(feature = "gecko")] use hash::FnvHashMap;
use std::fmt::Debug; use std::fmt::Debug;
use std::hash::Hash; use std::hash::Hash;
use std::ops::Deref; use std::ops::Deref;
@ -648,10 +648,10 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
false false
} }
/// Gets the current existing CSS transitions, by |property, end value| pairs in a HashMap. /// Gets the current existing CSS transitions, by |property, end value| pairs in a FnvHashMap.
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn get_css_transitions_info(&self) fn get_css_transitions_info(&self)
-> HashMap<TransitionProperty, Arc<AnimationValue>>; -> FnvHashMap<TransitionProperty, Arc<AnimationValue>>;
/// Does a rough (and cheap) check for whether or not transitions might need to be updated that /// Does a rough (and cheap) check for whether or not transitions might need to be updated that
/// will quickly return false for the common case of no transitions specified or running. If /// will quickly return false for the common case of no transitions specified or running. If
@ -684,7 +684,7 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
combined_duration: f32, combined_duration: f32,
before_change_style: &ComputedValues, before_change_style: &ComputedValues,
after_change_style: &ComputedValues, after_change_style: &ComputedValues,
existing_transitions: &HashMap<TransitionProperty, Arc<AnimationValue>> existing_transitions: &FnvHashMap<TransitionProperty, Arc<AnimationValue>>
) -> bool; ) -> bool;
/// Returns the value of the `xml:lang=""` attribute (or, if appropriate, /// Returns the value of the `xml:lang=""` attribute (or, if appropriate,

View file

@ -66,7 +66,7 @@ use gecko_bindings::structs::nsChangeHint;
use gecko_bindings::structs::nsIDocument_DocumentTheme as DocumentTheme; use gecko_bindings::structs::nsIDocument_DocumentTheme as DocumentTheme;
use gecko_bindings::structs::nsRestyleHint; use gecko_bindings::structs::nsRestyleHint;
use gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI}; use gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI};
use hash::HashMap; use hash::FnvHashMap;
use logical_geometry::WritingMode; use logical_geometry::WritingMode;
use media_queries::Device; use media_queries::Device;
use properties::{ComputedValues, LonghandId, parse_style_attribute}; use properties::{ComputedValues, LonghandId, parse_style_attribute};
@ -1303,14 +1303,14 @@ impl<'le> TElement for GeckoElement<'le> {
fn get_css_transitions_info( fn get_css_transitions_info(
&self, &self,
) -> HashMap<TransitionProperty, Arc<AnimationValue>> { ) -> FnvHashMap<TransitionProperty, Arc<AnimationValue>> {
use gecko_bindings::bindings::Gecko_ElementTransitions_EndValueAt; use gecko_bindings::bindings::Gecko_ElementTransitions_EndValueAt;
use gecko_bindings::bindings::Gecko_ElementTransitions_Length; use gecko_bindings::bindings::Gecko_ElementTransitions_Length;
use gecko_bindings::bindings::Gecko_ElementTransitions_PropertyAt; use gecko_bindings::bindings::Gecko_ElementTransitions_PropertyAt;
let collection_length = let collection_length =
unsafe { Gecko_ElementTransitions_Length(self.0) }; unsafe { Gecko_ElementTransitions_Length(self.0) };
let mut map = HashMap::with_capacity(collection_length); let mut map = FnvHashMap::with_capacity_and_hasher(collection_length, Default::default());
for i in 0..collection_length { for i in 0..collection_length {
let (property, raw_end_value) = unsafe { let (property, raw_end_value) = unsafe {
(Gecko_ElementTransitions_PropertyAt(self.0, i as usize).into(), (Gecko_ElementTransitions_PropertyAt(self.0, i as usize).into(),
@ -1447,7 +1447,7 @@ impl<'le> TElement for GeckoElement<'le> {
combined_duration: f32, combined_duration: f32,
before_change_style: &ComputedValues, before_change_style: &ComputedValues,
after_change_style: &ComputedValues, after_change_style: &ComputedValues,
existing_transitions: &HashMap<TransitionProperty, Arc<AnimationValue>>, existing_transitions: &FnvHashMap<TransitionProperty, Arc<AnimationValue>>,
) -> bool { ) -> bool {
use values::animated::{Animate, Procedure}; use values::animated::{Animate, Procedure};

View file

@ -414,7 +414,7 @@ ${helpers.predefined_type("object-position",
products="gecko" products="gecko"
animation_value_type="discrete" animation_value_type="discrete"
boxed="True"> boxed="True">
use hash::HashMap; use hash::FnvHashMap;
use std::fmt; use std::fmt;
use std::ops::Range; use std::ops::Range;
use str::HTML_SPACE_CHARACTERS; use str::HTML_SPACE_CHARACTERS;
@ -478,7 +478,7 @@ ${helpers.predefined_type("object-position",
let mut width = 0; let mut width = 0;
{ {
let mut row = 0u32; let mut row = 0u32;
let mut area_indices = HashMap::<(&str), usize>::new(); let mut area_indices = FnvHashMap::<(&str), usize>::default();
for string in &strings { for string in &strings {
let mut current_area_index: Option<usize> = None; let mut current_area_index: Option<usize> = None;
row += 1; row += 1;

View file

@ -1016,13 +1016,13 @@ 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 hash::HashSet; use hash::FnvHashSet;
let me = &*self.ptr(); let me = &*self.ptr();
assert!(me.is_root()); assert!(me.is_root());
let mut current = self.ptr(); let mut current = self.ptr();
let mut seen = HashSet::new(); let mut seen = FnvHashSet::default();
while current != FREE_LIST_SENTINEL { while current != FREE_LIST_SENTINEL {
let next = (*current).next_free.load(Ordering::Relaxed); let next = (*current).next_free.load(Ordering::Relaxed);
assert!(!next.is_null()); assert!(!next.is_null());