Skip to content

Commit

Permalink
style: Temporarily use OrderMap on Gecko.
Browse files Browse the repository at this point in the history
This will allow us to discard std hash map as a source of crashes.
  • Loading branch information
emilio committed Jan 31, 2018
1 parent a2c2d34 commit 4d9ce6b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
13 changes: 10 additions & 3 deletions components/style/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@

use fnv;

// #[cfg(feature = "gecko")]
// pub use hashglobe::hash_map::HashMap;
// #[cfg(feature = "gecko")]
// pub use hashglobe::hash_set::HashSet;
#[cfg(feature = "gecko")]
pub use hashglobe::hash_map::HashMap;
pub use hashglobe::order::HashMap;
#[cfg(feature = "gecko")]
pub use hashglobe::hash_set::HashSet;
pub use hashglobe::order::HashSet;


#[cfg(feature = "servo")]
pub use hashglobe::fake::{HashMap, HashSet};


/// Appropriate reexports of hash_map types
pub mod map {
// #[cfg(feature = "gecko")]
// pub use hashglobe::hash_map::{Entry, Iter};
#[cfg(feature = "gecko")]
pub use hashglobe::hash_map::{Entry, Iter};
pub use hashglobe::order::{Entry, MapIter as Iter};
#[cfg(feature = "servo")]
pub use std::collections::hash_map::{Entry, Iter};
}
Expand Down
4 changes: 2 additions & 2 deletions components/style/invalidation/element/invalidation_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl InvalidationMap {

for class in compound_visitor.classes {
self.class_to_selector
.entry(class, quirks_mode)
.try_entry(class, quirks_mode)?
.or_insert_with(SmallVec::new)
.try_push(Dependency {
selector: selector.clone(),
Expand All @@ -283,7 +283,7 @@ impl InvalidationMap {

for id in compound_visitor.ids {
self.id_to_selector
.entry(id, quirks_mode)
.try_entry(id, quirks_mode)?
.or_insert_with(SmallVec::new)
.try_push(Dependency {
selector: selector.clone(),
Expand Down
19 changes: 14 additions & 5 deletions components/style/selector_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,20 +512,29 @@ impl<V: 'static> MaybeCaseInsensitiveHashMap<Atom, V> {
MaybeCaseInsensitiveHashMap(PrecomputedHashMap::default())
}

/// HashMap::entry
pub fn entry(&mut self, mut key: Atom, quirks_mode: QuirksMode) -> hash_map::Entry<Atom, V> {
/// HashMap::try_entry
#[cfg(not(feature = "gecko"))]
pub fn try_entry(
&mut self,
mut key: Atom,
quirks_mode: QuirksMode,
) -> Result<hash_map::Entry<Atom, V>, FailedAllocationError> {
if quirks_mode == QuirksMode::Quirks {
key = key.to_ascii_lowercase()
}
self.0.entry(key)
self.0.try_entry(key)
}

/// HashMap::try_entry
///
/// FIXME(emilio): Remove the extra Entry parameter and unify when ordermap
/// 0.4 is released.
#[cfg(feature = "gecko")]
pub fn try_entry(
&mut self,
mut key: Atom,
quirks_mode: QuirksMode
) -> Result<hash_map::Entry<Atom, V>, FailedAllocationError> {
quirks_mode: QuirksMode,
) -> Result<hash_map::Entry<Atom, V, BuildHasherDefault<PrecomputedHasher>>, FailedAllocationError> {
if quirks_mode == QuirksMode::Quirks {
key = key.to_ascii_lowercase()
}
Expand Down

0 comments on commit 4d9ce6b

Please sign in to comment.