Skip to content

Commit

Permalink
stylo: use FnvHashMap everywhere, remove default HashMap construction…
Browse files Browse the repository at this point in the history
… methods
  • Loading branch information
Manishearth committed Oct 3, 2017
1 parent 0b69887 commit 8bce37e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 98 deletions.
18 changes: 0 additions & 18 deletions components/hashglobe/src/fake.rs
Expand Up @@ -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>
where K: Eq + Hash,
S: BuildHasher
Expand Down
36 changes: 0 additions & 36 deletions components/hashglobe/src/hash_map.rs
Expand Up @@ -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>
where K: Eq + Hash,
S: BuildHasher
Expand Down
32 changes: 0 additions & 32 deletions components/hashglobe/src/hash_set.rs
Expand Up @@ -121,38 +121,6 @@ pub struct HashSet<T, S = RandomState> {
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>
where T: Eq + Hash,
S: BuildHasher
Expand Down
8 changes: 4 additions & 4 deletions components/style/dom.rs
Expand Up @@ -28,7 +28,7 @@ use selectors::sink::Push;
use servo_arc::{Arc, ArcBorrow};
use shared_lock::Locked;
use std::fmt;
#[cfg(feature = "gecko")] use hash::HashMap;
#[cfg(feature = "gecko")] use hash::FnvHashMap;
use std::fmt::Debug;
use std::hash::Hash;
use std::ops::Deref;
Expand Down Expand Up @@ -648,10 +648,10 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
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")]
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
/// will quickly return false for the common case of no transitions specified or running. If
Expand Down Expand Up @@ -684,7 +684,7 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
combined_duration: f32,
before_change_style: &ComputedValues,
after_change_style: &ComputedValues,
existing_transitions: &HashMap<TransitionProperty, Arc<AnimationValue>>
existing_transitions: &FnvHashMap<TransitionProperty, Arc<AnimationValue>>
) -> bool;

/// Returns the value of the `xml:lang=""` attribute (or, if appropriate,
Expand Down
8 changes: 4 additions & 4 deletions components/style/gecko/wrapper.rs
Expand Up @@ -66,7 +66,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::HashMap;
use hash::FnvHashMap;
use logical_geometry::WritingMode;
use media_queries::Device;
use properties::{ComputedValues, LonghandId, parse_style_attribute};
Expand Down Expand Up @@ -1303,14 +1303,14 @@ impl<'le> TElement for GeckoElement<'le> {

fn get_css_transitions_info(
&self,
) -> HashMap<TransitionProperty, Arc<AnimationValue>> {
) -> FnvHashMap<TransitionProperty, Arc<AnimationValue>> {
use gecko_bindings::bindings::Gecko_ElementTransitions_EndValueAt;
use gecko_bindings::bindings::Gecko_ElementTransitions_Length;
use gecko_bindings::bindings::Gecko_ElementTransitions_PropertyAt;

let collection_length =
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 {
let (property, raw_end_value) = unsafe {
(Gecko_ElementTransitions_PropertyAt(self.0, i as usize).into(),
Expand Down Expand Up @@ -1447,7 +1447,7 @@ impl<'le> TElement for GeckoElement<'le> {
combined_duration: f32,
before_change_style: &ComputedValues,
after_change_style: &ComputedValues,
existing_transitions: &HashMap<TransitionProperty, Arc<AnimationValue>>,
existing_transitions: &FnvHashMap<TransitionProperty, Arc<AnimationValue>>,
) -> bool {
use values::animated::{Animate, Procedure};

Expand Down
4 changes: 2 additions & 2 deletions components/style/properties/longhand/position.mako.rs
Expand Up @@ -414,7 +414,7 @@ ${helpers.predefined_type("object-position",
products="gecko"
animation_value_type="discrete"
boxed="True">
use hash::HashMap;
use hash::FnvHashMap;
use std::fmt;
use std::ops::Range;
use str::HTML_SPACE_CHARACTERS;
Expand Down Expand Up @@ -478,7 +478,7 @@ ${helpers.predefined_type("object-position",
let mut width = 0;
{
let mut row = 0u32;
let mut area_indices = HashMap::<(&str), usize>::new();
let mut area_indices = FnvHashMap::<(&str), usize>::default();
for string in &strings {
let mut current_area_index: Option<usize> = None;
row += 1;
Expand Down
4 changes: 2 additions & 2 deletions components/style/rule_tree/mod.rs
Expand Up @@ -1016,13 +1016,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::HashSet;
use hash::FnvHashSet;

let me = &*self.ptr();
assert!(me.is_root());

let mut current = self.ptr();
let mut seen = HashSet::new();
let mut seen = FnvHashSet::default();
while current != FREE_LIST_SENTINEL {
let next = (*current).next_free.load(Ordering::Relaxed);
assert!(!next.is_null());
Expand Down

0 comments on commit 8bce37e

Please sign in to comment.