Revert "Diagnostic map semantics."

This reverts commit f5c5be00a7.
This commit is contained in:
Manish Goregaokar 2017-10-23 13:51:08 -07:00
parent d6bafde971
commit b118ba72d0
11 changed files with 70 additions and 298 deletions

View file

@ -10,7 +10,8 @@ use applicable_declarations::ApplicableDeclarationBlock;
use context::QuirksMode;
use dom::TElement;
use fallible::FallibleVec;
use hash::{HashMap, HashSet, DiagnosticHashMap};
use hash::{HashMap, HashSet};
use hash::map as hash_map;
use hashglobe::FailedAllocationError;
use precomputed_hash::PrecomputedHash;
use rule_tree::CascadeLevel;
@ -36,9 +37,6 @@ impl Default for PrecomputedHasher {
/// A simple alias for a hashmap using PrecomputedHasher.
pub type PrecomputedHashMap<K, V> = HashMap<K, V, BuildHasherDefault<PrecomputedHasher>>;
/// A simple alias for a hashmap using PrecomputedHasher.
pub type PrecomputedDiagnosticHashMap<K, V> = DiagnosticHashMap<K, V, BuildHasherDefault<PrecomputedHasher>>;
/// A simple alias for a hashset using PrecomputedHasher.
pub type PrecomputedHashSet<K> = HashSet<K, BuildHasherDefault<PrecomputedHasher>>;
@ -101,7 +99,7 @@ pub struct SelectorMap<T: 'static> {
/// A hash from a class name to rules which contain that class selector.
pub class_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>,
/// A hash from local name to rules which contain that local name selector.
pub local_name_hash: PrecomputedDiagnosticHashMap<LocalName, SmallVec<[T; 1]>>,
pub local_name_hash: PrecomputedHashMap<LocalName, SmallVec<[T; 1]>>,
/// Rules that don't have ID, class, or element selectors.
pub other: SmallVec<[T; 1]>,
/// The number of entries in this map.
@ -117,7 +115,7 @@ impl<T: 'static> SelectorMap<T> {
SelectorMap {
id_hash: MaybeCaseInsensitiveHashMap::new(),
class_hash: MaybeCaseInsensitiveHashMap::new(),
local_name_hash: DiagnosticHashMap::default(),
local_name_hash: HashMap::default(),
other: SmallVec::new(),
count: 0,
}
@ -141,20 +139,6 @@ impl<T: 'static> SelectorMap<T> {
pub fn len(&self) -> usize {
self.count
}
/// Allows mutation of this SelectorMap.
pub fn begin_mutation(&mut self) {
self.id_hash.begin_mutation();
self.class_hash.begin_mutation();
self.local_name_hash.begin_mutation();
}
/// Disallows mutation of this SelectorMap.
pub fn end_mutation(&mut self) {
self.id_hash.end_mutation();
self.class_hash.end_mutation();
self.local_name_hash.end_mutation();
}
}
impl SelectorMap<Rule> {
@ -264,10 +248,12 @@ impl<T: SelectorMapEntry> SelectorMap<T> {
let vector = match find_bucket(entry.selector()) {
Bucket::ID(id) => {
self.id_hash.try_get_or_insert_with(id.clone(), quirks_mode, SmallVec::new)?
self.id_hash.try_entry(id.clone(), quirks_mode)?
.or_insert_with(SmallVec::new)
}
Bucket::Class(class) => {
self.class_hash.try_get_or_insert_with(class.clone(), quirks_mode, SmallVec::new)?
self.class_hash.try_entry(class.clone(), quirks_mode)?
.or_insert_with(SmallVec::new)
}
Bucket::LocalName { name, lower_name } => {
// If the local name in the selector isn't lowercase, insert it
@ -283,10 +269,12 @@ impl<T: SelectorMapEntry> SelectorMap<T> {
// subsequent selector matching work will filter them out.
if name != lower_name {
self.local_name_hash
.try_get_or_insert_with(lower_name.clone(), SmallVec::new)?
.try_entry(lower_name.clone())?
.or_insert_with(SmallVec::new)
.try_push(entry.clone())?;
}
self.local_name_hash.try_get_or_insert_with(name.clone(), SmallVec::new)?
self.local_name_hash.try_entry(name.clone())?
.or_insert_with(SmallVec::new)
}
Bucket::Universal => {
&mut self.other
@ -473,7 +461,7 @@ fn find_bucket<'a>(mut iter: SelectorIter<'a, SelectorImpl>) -> Bucket<'a> {
/// Wrapper for PrecomputedHashMap that does ASCII-case-insensitive lookup in quirks mode.
#[derive(Debug, MallocSizeOf)]
pub struct MaybeCaseInsensitiveHashMap<K: PrecomputedHash + Hash + Eq, V: 'static>(PrecomputedDiagnosticHashMap<K, V>);
pub struct MaybeCaseInsensitiveHashMap<K: PrecomputedHash + Hash + Eq, V: 'static>(PrecomputedHashMap<K, V>);
// FIXME(Manishearth) the 'static bound can be removed when
// our HashMap fork (hashglobe) is able to use NonZero,
@ -481,20 +469,32 @@ pub struct MaybeCaseInsensitiveHashMap<K: PrecomputedHash + Hash + Eq, V: 'stati
impl<V: 'static> MaybeCaseInsensitiveHashMap<Atom, V> {
/// Empty map
pub fn new() -> Self {
MaybeCaseInsensitiveHashMap(PrecomputedDiagnosticHashMap::default())
MaybeCaseInsensitiveHashMap(PrecomputedHashMap::default())
}
/// DiagnosticHashMap::try_get_or_insert_with
pub fn try_get_or_insert_with<F: FnOnce() -> V>(
&mut self,
mut key: Atom,
quirks_mode: QuirksMode,
default: F,
) -> Result<&mut V, FailedAllocationError> {
/// HashMap::entry
pub fn entry(&mut self, mut key: Atom, quirks_mode: QuirksMode) -> hash_map::Entry<Atom, V> {
if quirks_mode == QuirksMode::Quirks {
key = key.to_ascii_lowercase()
}
self.0.try_get_or_insert_with(key, default)
self.0.entry(key)
}
/// HashMap::try_entry
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.try_entry(key)
}
/// HashMap::iter
pub fn iter(&self) -> hash_map::Iter<Atom, V> {
self.0.iter()
}
/// HashMap::clear
@ -510,14 +510,4 @@ impl<V: 'static> MaybeCaseInsensitiveHashMap<Atom, V> {
self.0.get(key)
}
}
/// DiagnosticHashMap::begin_mutation
pub fn begin_mutation(&mut self) {
self.0.begin_mutation();
}
/// DiagnosticHashMap::end_mutation
pub fn end_mutation(&mut self) {
self.0.end_mutation();
}
}