mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
stylo: Add uses of fallible Vec, SmallVec and HashMap facilities.
Bug: 1395064 Reviewed-by: emilio
This commit is contained in:
parent
815fb6b058
commit
c85633f48e
10 changed files with 125 additions and 57 deletions
|
@ -7,6 +7,8 @@
|
|||
use {Atom, LocalName, Namespace};
|
||||
use context::QuirksMode;
|
||||
use element_state::ElementState;
|
||||
use fallible::FallibleVec;
|
||||
use hashglobe::FailedAllocationError;
|
||||
use selector_map::{MaybeCaseInsensitiveHashMap, SelectorMap, SelectorMapEntry};
|
||||
use selector_parser::SelectorImpl;
|
||||
use selectors::attr::NamespaceConstraint;
|
||||
|
@ -184,12 +186,13 @@ impl InvalidationMap {
|
|||
})
|
||||
}
|
||||
|
||||
/// Adds a selector to this `InvalidationMap`.
|
||||
/// Adds a selector to this `InvalidationMap`. Returns Err(..) to
|
||||
/// signify OOM.
|
||||
pub fn note_selector(
|
||||
&mut self,
|
||||
selector: &Selector<SelectorImpl>,
|
||||
quirks_mode: QuirksMode)
|
||||
{
|
||||
quirks_mode: QuirksMode
|
||||
) -> Result<(), FailedAllocationError> {
|
||||
self.collect_invalidations_for(selector, quirks_mode)
|
||||
}
|
||||
|
||||
|
@ -203,11 +206,12 @@ impl InvalidationMap {
|
|||
self.has_class_attribute_selectors = false;
|
||||
}
|
||||
|
||||
// Returns Err(..) to signify OOM.
|
||||
fn collect_invalidations_for(
|
||||
&mut self,
|
||||
selector: &Selector<SelectorImpl>,
|
||||
quirks_mode: QuirksMode)
|
||||
{
|
||||
quirks_mode: QuirksMode
|
||||
) -> Result<(), FailedAllocationError> {
|
||||
debug!("InvalidationMap::collect_invalidations_for({:?})", selector);
|
||||
|
||||
let mut iter = selector.iter();
|
||||
|
@ -246,20 +250,20 @@ impl InvalidationMap {
|
|||
self.class_to_selector
|
||||
.entry(class, quirks_mode)
|
||||
.or_insert_with(SmallVec::new)
|
||||
.push(Dependency {
|
||||
.try_push(Dependency {
|
||||
selector: selector.clone(),
|
||||
selector_offset: sequence_start,
|
||||
})
|
||||
})?;
|
||||
}
|
||||
|
||||
for id in compound_visitor.ids {
|
||||
self.id_to_selector
|
||||
.entry(id, quirks_mode)
|
||||
.or_insert_with(SmallVec::new)
|
||||
.push(Dependency {
|
||||
.try_push(Dependency {
|
||||
selector: selector.clone(),
|
||||
selector_offset: sequence_start,
|
||||
})
|
||||
})?;
|
||||
}
|
||||
|
||||
if !compound_visitor.state.is_empty() {
|
||||
|
@ -270,7 +274,7 @@ impl InvalidationMap {
|
|||
selector_offset: sequence_start,
|
||||
},
|
||||
state: compound_visitor.state,
|
||||
}, quirks_mode);
|
||||
}, quirks_mode)?;
|
||||
}
|
||||
|
||||
if compound_visitor.other_attributes {
|
||||
|
@ -278,7 +282,7 @@ impl InvalidationMap {
|
|||
.insert(Dependency {
|
||||
selector: selector.clone(),
|
||||
selector_offset: sequence_start,
|
||||
}, quirks_mode);
|
||||
}, quirks_mode)?;
|
||||
}
|
||||
|
||||
combinator = iter.next_sequence();
|
||||
|
@ -288,6 +292,8 @@ impl InvalidationMap {
|
|||
|
||||
index += 1; // Account for the combinator.
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Measures heap usage.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue