style: Remove servo/components/{hashglobe,fallible} in favor of try_reserve

Differential Revision: https://phabricator.services.mozilla.com/D134194
This commit is contained in:
Emilio Cobos Álvarez 2023-06-06 18:07:21 +02:00 committed by Oriol Brufau
parent 07d1bd560b
commit 2b6fce1e57
33 changed files with 157 additions and 7113 deletions

View file

@ -8,18 +8,17 @@
use crate::applicable_declarations::ApplicableDeclarationList;
use crate::context::QuirksMode;
use crate::dom::TElement;
use crate::hash::map as hash_map;
use crate::hash::{HashMap, HashSet};
use crate::rule_tree::CascadeLevel;
use crate::selector_parser::SelectorImpl;
use crate::stylist::{CascadeData, Rule};
use crate::AllocErr;
use crate::{Atom, LocalName, Namespace, WeakAtom};
use fallible::FallibleVec;
use hashglobe::FailedAllocationError;
use precomputed_hash::PrecomputedHash;
use selectors::matching::{matches_selector, ElementSelectorFlags, MatchingContext};
use selectors::parser::{Combinator, Component, SelectorIter};
use smallvec::SmallVec;
use std::collections::hash_map;
use std::collections::{HashMap, HashSet};
use std::hash::{BuildHasherDefault, Hash, Hasher};
/// A hasher implementation that doesn't hash anything, because it expects its
@ -322,11 +321,7 @@ impl SelectorMap<Rule> {
impl<T: SelectorMapEntry> SelectorMap<T> {
/// Inserts an entry into the correct bucket(s).
pub fn insert(
&mut self,
entry: T,
quirks_mode: QuirksMode,
) -> Result<(), FailedAllocationError> {
pub fn insert(&mut self, entry: T, quirks_mode: QuirksMode) -> Result<(), AllocErr> {
self.count += 1;
// NOTE(emilio): It'd be nice for this to be a separate function, but
@ -335,16 +330,16 @@ impl<T: SelectorMapEntry> SelectorMap<T> {
// common path.
macro_rules! insert_into_bucket {
($entry:ident, $bucket:expr) => {{
match $bucket {
let vec = match $bucket {
Bucket::Root => &mut self.root,
Bucket::ID(id) => self
.id_hash
.try_entry(id.clone(), quirks_mode)?
.or_insert_with(SmallVec::new),
.or_default(),
Bucket::Class(class) => self
.class_hash
.try_entry(class.clone(), quirks_mode)?
.or_insert_with(SmallVec::new),
.or_default(),
Bucket::Attribute { name, lower_name } |
Bucket::LocalName { name, lower_name } => {
// If the local name in the selector isn't lowercase,
@ -367,19 +362,22 @@ impl<T: SelectorMapEntry> SelectorMap<T> {
&mut self.local_name_hash
};
if name != lower_name {
hash.try_entry(lower_name.clone())?
.or_insert_with(SmallVec::new)
.try_push($entry.clone())?;
hash.try_reserve(1)?;
let vec = hash.entry(lower_name.clone()).or_default();
vec.try_reserve(1)?;
vec.push($entry.clone());
}
hash.try_entry(name.clone())?.or_insert_with(SmallVec::new)
hash.try_reserve(1)?;
hash.entry(name.clone()).or_default()
},
Bucket::Namespace(url) => {
self.namespace_hash.try_reserve(1)?;
self.namespace_hash.entry(url.clone()).or_default()
},
Bucket::Namespace(url) => self
.namespace_hash
.try_entry(url.clone())?
.or_insert_with(SmallVec::new),
Bucket::Universal => &mut self.other,
}
.try_push($entry)?;
};
vec.try_reserve(1)?;
vec.push($entry);
}};
}
@ -742,11 +740,12 @@ impl<V: 'static> MaybeCaseInsensitiveHashMap<Atom, V> {
&mut self,
mut key: Atom,
quirks_mode: QuirksMode,
) -> Result<hash_map::Entry<Atom, V>, FailedAllocationError> {
) -> Result<hash_map::Entry<Atom, V>, AllocErr> {
if quirks_mode == QuirksMode::Quirks {
key = key.to_ascii_lowercase()
}
self.0.try_entry(key)
self.0.try_reserve(1)?;
Ok(self.0.entry(key))
}
/// HashMap::is_empty