mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
style: Remove servo/components/{hashglobe,fallible} in favor of try_reserve
Differential Revision: https://phabricator.services.mozilla.com/D134194
This commit is contained in:
parent
07d1bd560b
commit
2b6fce1e57
33 changed files with 157 additions and 7113 deletions
|
@ -17,7 +17,7 @@ path = "lib.rs"
|
|||
doctest = false
|
||||
|
||||
[features]
|
||||
gecko = ["style_traits/gecko", "fallible/known_system_malloc", "bindgen", "regex", "toml",
|
||||
gecko = ["style_traits/gecko", "bindgen", "regex", "toml",
|
||||
"num_cpus", "thin-slice"]
|
||||
servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever",
|
||||
"cssparser/serde", "encoding_rs", "malloc_size_of/servo", "servo_url",
|
||||
|
@ -38,9 +38,7 @@ cssparser = "0.29"
|
|||
derive_more = "0.99"
|
||||
encoding_rs = { version = "0.8", optional = true }
|
||||
euclid = "0.22"
|
||||
fallible = { path = "../fallible" }
|
||||
fxhash = "0.2"
|
||||
hashglobe = { path = "../hashglobe" }
|
||||
html5ever = { version = "0.26", optional = true }
|
||||
indexmap = "1.0"
|
||||
itertools = "0.8"
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
//! [custom]: https://drafts.csswg.org/css-variables/
|
||||
|
||||
use crate::applicable_declarations::CascadePriority;
|
||||
use crate::hash::map::Entry;
|
||||
use crate::media_queries::Device;
|
||||
use crate::properties::{CSSWideKeyword, CustomDeclaration, CustomDeclarationValue};
|
||||
use crate::selector_map::{PrecomputedHashMap, PrecomputedHashSet, PrecomputedHasher};
|
||||
|
@ -21,6 +20,7 @@ use servo_arc::Arc;
|
|||
use smallvec::SmallVec;
|
||||
use std::borrow::Cow;
|
||||
use std::cmp;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::fmt::{self, Write};
|
||||
use std::hash::BuildHasherDefault;
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
|
|
|
@ -54,7 +54,6 @@ use crate::gecko_bindings::structs::{nsAtom, nsIContent, nsINode_BooleanFlag};
|
|||
use crate::gecko_bindings::structs::{nsINode as RawGeckoNode, Element as RawGeckoElement};
|
||||
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI};
|
||||
use crate::global_style_data::GLOBAL_STYLE_DATA;
|
||||
use crate::hash::FxHashMap;
|
||||
use crate::invalidation::element::restyle_hints::RestyleHint;
|
||||
use crate::media_queries::Device;
|
||||
use crate::properties::animated_properties::{AnimationValue, AnimationValueMap};
|
||||
|
@ -69,6 +68,7 @@ use crate::values::{AtomIdent, AtomString};
|
|||
use crate::CaseSensitivityExt;
|
||||
use crate::LocalName;
|
||||
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
|
||||
use fxhash::FxHashMap;
|
||||
use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator};
|
||||
use selectors::attr::{CaseSensitivity, NamespaceConstraint};
|
||||
use selectors::matching::VisitedHandlingMode;
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Reexports of hashglobe types in Gecko mode, and stdlib hashmap shims in Servo mode
|
||||
//!
|
||||
//! Can go away when the stdlib gets fallible collections
|
||||
//! https://github.com/rust-lang/rfcs/pull/2116
|
||||
|
||||
use fxhash;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use hashglobe::hash_map::HashMap;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use hashglobe::hash_set::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 = "servo")]
|
||||
pub use std::collections::hash_map::{Entry, Iter};
|
||||
}
|
||||
|
||||
/// Hash map that uses the Fx hasher
|
||||
pub type FxHashMap<K, V> = HashMap<K, V, fxhash::FxBuildHasher>;
|
||||
/// Hash set that uses the Fx hasher
|
||||
pub type FxHashSet<T> = HashSet<T, fxhash::FxBuildHasher>;
|
|
@ -10,9 +10,8 @@ use crate::selector_map::{
|
|||
MaybeCaseInsensitiveHashMap, PrecomputedHashMap, SelectorMap, SelectorMapEntry,
|
||||
};
|
||||
use crate::selector_parser::SelectorImpl;
|
||||
use crate::AllocErr;
|
||||
use crate::{Atom, LocalName, Namespace};
|
||||
use fallible::FallibleVec;
|
||||
use hashglobe::FailedAllocationError;
|
||||
use selectors::attr::NamespaceConstraint;
|
||||
use selectors::parser::{Combinator, Component};
|
||||
use selectors::parser::{Selector, SelectorIter};
|
||||
|
@ -244,7 +243,7 @@ impl InvalidationMap {
|
|||
&mut self,
|
||||
selector: &Selector<SelectorImpl>,
|
||||
quirks_mode: QuirksMode,
|
||||
) -> Result<(), FailedAllocationError> {
|
||||
) -> Result<(), AllocErr> {
|
||||
debug!("InvalidationMap::note_selector({:?})", selector);
|
||||
|
||||
let mut document_state = DocumentState::empty();
|
||||
|
@ -274,7 +273,8 @@ impl InvalidationMap {
|
|||
state: document_state,
|
||||
dependency: Dependency::for_full_selector_invalidation(selector.clone()),
|
||||
};
|
||||
self.document_state_selectors.try_push(dep)?;
|
||||
self.document_state_selectors.try_reserve(1)?;
|
||||
self.document_state_selectors.push(dep);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -325,7 +325,7 @@ struct SelectorDependencyCollector<'a> {
|
|||
compound_state: PerCompoundState,
|
||||
|
||||
/// The allocation error, if we OOM.
|
||||
alloc_error: &'a mut Option<FailedAllocationError>,
|
||||
alloc_error: &'a mut Option<AllocErr>,
|
||||
}
|
||||
|
||||
impl<'a> SelectorDependencyCollector<'a> {
|
||||
|
@ -361,7 +361,7 @@ impl<'a> SelectorDependencyCollector<'a> {
|
|||
self.quirks_mode,
|
||||
);
|
||||
if let Err(alloc_error) = result {
|
||||
*self.alloc_error = Some(alloc_error);
|
||||
*self.alloc_error = Some(alloc_error.into());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -378,21 +378,17 @@ impl<'a> SelectorDependencyCollector<'a> {
|
|||
let dependency = self.dependency();
|
||||
|
||||
let map = &mut self.map.other_attribute_affecting_selectors;
|
||||
let entry = match map.try_entry(name) {
|
||||
Ok(entry) => entry,
|
||||
Err(err) => {
|
||||
*self.alloc_error = Some(err);
|
||||
return false;
|
||||
},
|
||||
};
|
||||
|
||||
match entry.or_insert_with(SmallVec::new).try_push(dependency) {
|
||||
Ok(..) => true,
|
||||
Err(err) => {
|
||||
*self.alloc_error = Some(err);
|
||||
return false;
|
||||
},
|
||||
if let Err(err) = map.try_reserve(1) {
|
||||
*self.alloc_error = Some(err.into());
|
||||
return false;
|
||||
}
|
||||
let vec = map.entry(name).or_default();
|
||||
if let Err(err) = vec.try_reserve(1) {
|
||||
*self.alloc_error = Some(err.into());
|
||||
return false;
|
||||
}
|
||||
vec.push(dependency);
|
||||
true
|
||||
}
|
||||
|
||||
fn dependency(&self) -> Dependency {
|
||||
|
@ -481,17 +477,17 @@ impl<'a> SelectorVisitor for SelectorDependencyCollector<'a> {
|
|||
let entry = match map.try_entry(atom.0.clone(), self.quirks_mode) {
|
||||
Ok(entry) => entry,
|
||||
Err(err) => {
|
||||
*self.alloc_error = Some(err);
|
||||
*self.alloc_error = Some(err.into());
|
||||
return false;
|
||||
},
|
||||
};
|
||||
match entry.or_insert_with(SmallVec::new).try_push(dependency) {
|
||||
Ok(..) => true,
|
||||
Err(err) => {
|
||||
*self.alloc_error = Some(err);
|
||||
return false;
|
||||
},
|
||||
let vec = entry.or_insert_with(SmallVec::new);
|
||||
if let Err(err) = vec.try_reserve(1) {
|
||||
*self.alloc_error = Some(err.into());
|
||||
return false;
|
||||
}
|
||||
vec.push(dependency);
|
||||
true
|
||||
},
|
||||
Component::NonTSPseudoClass(ref pc) => {
|
||||
self.compound_state.element_state |= pc.state_flag();
|
||||
|
|
|
@ -484,16 +484,16 @@ impl StylesheetInvalidationSet {
|
|||
},
|
||||
Invalidation::LocalName { name, lower_name } => {
|
||||
let insert_lower = name != lower_name;
|
||||
let entry = match self.local_names.try_entry(name) {
|
||||
Ok(e) => e,
|
||||
Err(..) => return false,
|
||||
};
|
||||
if self.local_names.try_reserve(1).is_err() {
|
||||
return false;
|
||||
}
|
||||
let entry = self.local_names.entry(name);
|
||||
*entry.or_insert(InvalidationKind::None) |= kind;
|
||||
if insert_lower {
|
||||
let entry = match self.local_names.try_entry(lower_name) {
|
||||
Ok(e) => e,
|
||||
Err(..) => return false,
|
||||
};
|
||||
if self.local_names.try_reserve(1).is_err() {
|
||||
return false;
|
||||
}
|
||||
let entry = self.local_names.entry(lower_name);
|
||||
*entry.or_insert(InvalidationKind::None) |= kind;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -97,7 +97,6 @@ pub mod font_metrics;
|
|||
#[allow(unsafe_code)]
|
||||
pub mod gecko_bindings;
|
||||
pub mod global_style_data;
|
||||
pub mod hash;
|
||||
pub mod invalidation;
|
||||
#[allow(missing_docs)] // TODO.
|
||||
pub mod logical_geometry;
|
||||
|
@ -263,3 +262,27 @@ where
|
|||
*self == One::one()
|
||||
}
|
||||
}
|
||||
|
||||
/// An allocation error.
|
||||
///
|
||||
/// TODO(emilio): Would be nice to have more information here, or for SmallVec
|
||||
/// to return the standard error type (and then we can just return that).
|
||||
///
|
||||
/// But given we use these mostly to bail out and ignore them, it's not a big
|
||||
/// deal.
|
||||
#[derive(Debug)]
|
||||
pub struct AllocErr;
|
||||
|
||||
impl From<smallvec::CollectionAllocErr> for AllocErr {
|
||||
#[inline]
|
||||
fn from(_: smallvec::CollectionAllocErr) -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::collections::TryReserveError> for AllocErr {
|
||||
#[inline]
|
||||
fn from(_: std::collections::TryReserveError) -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ use servo_arc::Arc;
|
|||
use smallvec::SmallVec;
|
||||
use std::ptr;
|
||||
use std::mem;
|
||||
use crate::hash::FxHashMap;
|
||||
use fxhash::FxHashMap;
|
||||
use super::ComputedValues;
|
||||
use crate::values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
|
||||
use crate::values::animated::effects::AnimatedFilter;
|
||||
|
|
|
@ -29,7 +29,7 @@ use crate::context::QuirksMode;
|
|||
use crate::logical_geometry::WritingMode;
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use crate::computed_value_flags::*;
|
||||
use crate::hash::FxHashMap;
|
||||
use fxhash::FxHashMap;
|
||||
use crate::media_queries::Device;
|
||||
use crate::parser::ParserContext;
|
||||
use crate::selector_parser::PseudoElement;
|
||||
|
|
|
@ -128,7 +128,7 @@ impl RuleTree {
|
|||
return;
|
||||
}
|
||||
|
||||
let mut children_count = crate::hash::FxHashMap::default();
|
||||
let mut children_count = fxhash::FxHashMap::default();
|
||||
|
||||
let mut stack = SmallVec::<[_; 32]>::new();
|
||||
stack.push(self.root.clone());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -16,7 +16,6 @@ use crate::stylesheets::{CssRule, CssRules, Origin, UrlExtraData};
|
|||
use crate::use_counters::UseCounters;
|
||||
use crate::{Namespace, Prefix};
|
||||
use cssparser::{Parser, ParserInput, RuleListParser};
|
||||
use fallible::FallibleVec;
|
||||
use fxhash::FxHashMap;
|
||||
#[cfg(feature = "gecko")]
|
||||
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
|
||||
|
@ -506,9 +505,10 @@ impl Stylesheet {
|
|||
// Use a fallible push here, and if it fails, just fall
|
||||
// out of the loop. This will cause the page to be
|
||||
// shown incorrectly, but it's better than OOMing.
|
||||
if rules.try_push(rule).is_err() {
|
||||
if rules.try_reserve(1).is_err() {
|
||||
break;
|
||||
}
|
||||
rules.push(rule);
|
||||
},
|
||||
Err((error, slice)) => {
|
||||
let location = error.location;
|
||||
|
|
|
@ -40,10 +40,9 @@ use crate::stylesheets::{
|
|||
};
|
||||
use crate::stylesheets::{StyleRule, StylesheetContents, StylesheetInDocument};
|
||||
use crate::thread_state::{self, ThreadState};
|
||||
use crate::AllocErr;
|
||||
use crate::{Atom, LocalName, Namespace, WeakAtom};
|
||||
use fallible::FallibleVec;
|
||||
use fxhash::FxHashMap;
|
||||
use hashglobe::FailedAllocationError;
|
||||
use malloc_size_of::MallocSizeOf;
|
||||
#[cfg(feature = "gecko")]
|
||||
use malloc_size_of::{MallocShallowSizeOf, MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
|
||||
|
@ -113,7 +112,7 @@ trait CascadeDataCacheEntry: Sized {
|
|||
collection: SheetCollectionFlusher<S>,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
old_entry: &Self,
|
||||
) -> Result<Arc<Self>, FailedAllocationError>
|
||||
) -> Result<Arc<Self>, AllocErr>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static;
|
||||
/// Measures heap memory usage.
|
||||
|
@ -150,7 +149,7 @@ where
|
|||
collection: SheetCollectionFlusher<S>,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
old_entry: &Entry,
|
||||
) -> Result<Option<Arc<Entry>>, FailedAllocationError>
|
||||
) -> Result<Option<Arc<Entry>>, AllocErr>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
{
|
||||
|
@ -269,7 +268,7 @@ impl CascadeDataCacheEntry for UserAgentCascadeData {
|
|||
collection: SheetCollectionFlusher<S>,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
_old: &Self,
|
||||
) -> Result<Arc<Self>, FailedAllocationError>
|
||||
) -> Result<Arc<Self>, AllocErr>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
{
|
||||
|
@ -385,7 +384,7 @@ impl DocumentCascadeData {
|
|||
quirks_mode: QuirksMode,
|
||||
mut flusher: DocumentStylesheetFlusher<'a, S>,
|
||||
guards: &StylesheetGuards,
|
||||
) -> Result<(), FailedAllocationError>
|
||||
) -> Result<(), AllocErr>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
{
|
||||
|
@ -599,7 +598,7 @@ impl Stylist {
|
|||
old_data: &CascadeData,
|
||||
collection: SheetCollectionFlusher<S>,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
) -> Result<Option<Arc<CascadeData>>, FailedAllocationError>
|
||||
) -> Result<Option<Arc<CascadeData>>, AllocErr>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
{
|
||||
|
@ -1560,7 +1559,8 @@ impl<T: 'static> LayerOrderedVec<T> {
|
|||
self.0.push((v, id));
|
||||
}
|
||||
fn sort(&mut self, layers: &[CascadeLayer]) {
|
||||
self.0.sort_by_key(|&(_, ref id)| layers[id.0 as usize].order)
|
||||
self.0
|
||||
.sort_by_key(|&(_, ref id)| layers[id.0 as usize].order)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1569,17 +1569,24 @@ impl<T: 'static> LayerOrderedMap<T> {
|
|||
self.0.clear();
|
||||
}
|
||||
#[cfg(feature = "gecko")]
|
||||
fn try_insert(&mut self, name: Atom, v: T, id: LayerId) -> Result<(), FailedAllocationError> {
|
||||
fn try_insert(&mut self, name: Atom, v: T, id: LayerId) -> Result<(), AllocErr> {
|
||||
self.try_insert_with(name, v, id, |_, _| Ordering::Equal)
|
||||
}
|
||||
fn try_insert_with(&mut self, name: Atom, v: T, id: LayerId, cmp: impl Fn(&T, &T) -> Ordering) -> Result<(), FailedAllocationError> {
|
||||
let vec = self.0.try_entry(name)?.or_insert_with(Default::default);
|
||||
fn try_insert_with(
|
||||
&mut self,
|
||||
name: Atom,
|
||||
v: T,
|
||||
id: LayerId,
|
||||
cmp: impl Fn(&T, &T) -> Ordering,
|
||||
) -> Result<(), AllocErr> {
|
||||
self.0.try_reserve(1)?;
|
||||
let vec = self.0.entry(name).or_default();
|
||||
if let Some(&mut (ref mut val, ref last_id)) = vec.last_mut() {
|
||||
if *last_id == id {
|
||||
if cmp(&val, &v) != Ordering::Greater {
|
||||
*val = v;
|
||||
}
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
vec.push((v, id));
|
||||
|
@ -1639,7 +1646,11 @@ impl ExtraStyleData {
|
|||
}
|
||||
|
||||
/// Add the given @font-feature-values rule.
|
||||
fn add_font_feature_values(&mut self, rule: &Arc<Locked<FontFeatureValuesRule>>, layer: LayerId) {
|
||||
fn add_font_feature_values(
|
||||
&mut self,
|
||||
rule: &Arc<Locked<FontFeatureValuesRule>>,
|
||||
layer: LayerId,
|
||||
) {
|
||||
self.font_feature_values.push(rule.clone(), layer);
|
||||
}
|
||||
|
||||
|
@ -1649,7 +1660,7 @@ impl ExtraStyleData {
|
|||
guard: &SharedRwLockReadGuard,
|
||||
rule: &Arc<Locked<CounterStyleRule>>,
|
||||
layer: LayerId,
|
||||
) -> Result<(), FailedAllocationError> {
|
||||
) -> Result<(), AllocErr> {
|
||||
let name = rule.read_with(guard).name().0.clone();
|
||||
self.counter_styles.try_insert(name, rule.clone(), layer)
|
||||
}
|
||||
|
@ -1665,7 +1676,7 @@ impl ExtraStyleData {
|
|||
guard: &SharedRwLockReadGuard,
|
||||
rule: &Arc<Locked<ScrollTimelineRule>>,
|
||||
layer: LayerId,
|
||||
) -> Result<(), FailedAllocationError> {
|
||||
) -> Result<(), AllocErr> {
|
||||
let name = rule.read_with(guard).name.as_atom().clone();
|
||||
self.scroll_timelines.try_insert(name, rule.clone(), layer)
|
||||
}
|
||||
|
@ -2123,7 +2134,7 @@ impl CascadeData {
|
|||
quirks_mode: QuirksMode,
|
||||
collection: SheetCollectionFlusher<S>,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
) -> Result<(), FailedAllocationError>
|
||||
) -> Result<(), AllocErr>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
{
|
||||
|
@ -2262,7 +2273,8 @@ impl CascadeData {
|
|||
{
|
||||
self.extra_data.sort_by_layer(&self.layers);
|
||||
}
|
||||
self.animations.sort_with(&self.layers, compare_keyframes_in_same_layer);
|
||||
self.animations
|
||||
.sort_with(&self.layers, compare_keyframes_in_same_layer);
|
||||
}
|
||||
|
||||
/// Collects all the applicable media query results into `results`.
|
||||
|
@ -2323,7 +2335,7 @@ impl CascadeData {
|
|||
mut current_layer: &mut LayerName,
|
||||
current_layer_id: LayerId,
|
||||
mut precomputed_pseudo_element_decls: Option<&mut PrecomputedPseudoElementDeclarations>,
|
||||
) -> Result<(), FailedAllocationError>
|
||||
) -> Result<(), AllocErr>
|
||||
where
|
||||
S: StylesheetInDocument + 'static,
|
||||
{
|
||||
|
@ -2409,12 +2421,14 @@ impl CascadeData {
|
|||
// We choose the last one quite arbitrarily,
|
||||
// expecting it's slightly more likely to be more
|
||||
// specific.
|
||||
self.part_rules
|
||||
let map = self
|
||||
.part_rules
|
||||
.get_or_insert_with(|| Box::new(Default::default()))
|
||||
.for_insertion(pseudo_element)
|
||||
.try_entry(parts.last().unwrap().clone().0)?
|
||||
.or_insert_with(SmallVec::new)
|
||||
.try_push(rule)?;
|
||||
.for_insertion(pseudo_element);
|
||||
map.try_reserve(1)?;
|
||||
let vec = map.entry(parts.last().unwrap().clone().0).or_default();
|
||||
vec.try_reserve(1)?;
|
||||
vec.push(rule);
|
||||
} else {
|
||||
// NOTE(emilio): It's fine to look at :host and then at
|
||||
// ::slotted(..), since :host::slotted(..) could never
|
||||
|
@ -2444,13 +2458,19 @@ impl CascadeData {
|
|||
keyframes_rule.vendor_prefix.clone(),
|
||||
guard,
|
||||
);
|
||||
self.animations.try_insert_with(name, animation, current_layer_id, compare_keyframes_in_same_layer)?;
|
||||
self.animations.try_insert_with(
|
||||
name,
|
||||
animation,
|
||||
current_layer_id,
|
||||
compare_keyframes_in_same_layer,
|
||||
)?;
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
CssRule::ScrollTimeline(ref rule) => {
|
||||
// Note: Bug 1733260: we may drop @scroll-timeline rule once this spec issue
|
||||
// https://github.com/w3c/csswg-drafts/issues/6674 gets landed.
|
||||
self.extra_data.add_scroll_timeline(guard, rule, current_layer_id)?;
|
||||
self.extra_data
|
||||
.add_scroll_timeline(guard, rule, current_layer_id)?;
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
CssRule::FontFace(ref rule) => {
|
||||
|
@ -2458,11 +2478,13 @@ impl CascadeData {
|
|||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
CssRule::FontFeatureValues(ref rule) => {
|
||||
self.extra_data.add_font_feature_values(rule, current_layer_id);
|
||||
self.extra_data
|
||||
.add_font_feature_values(rule, current_layer_id);
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
CssRule::CounterStyle(ref rule) => {
|
||||
self.extra_data.add_counter_style(guard, rule, current_layer_id);
|
||||
self.extra_data
|
||||
.add_counter_style(guard, rule, current_layer_id)?;
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
CssRule::Page(ref rule) => {
|
||||
|
@ -2640,7 +2662,7 @@ impl CascadeData {
|
|||
guard: &SharedRwLockReadGuard,
|
||||
rebuild_kind: SheetRebuildKind,
|
||||
mut precomputed_pseudo_element_decls: Option<&mut PrecomputedPseudoElementDeclarations>,
|
||||
) -> Result<(), FailedAllocationError>
|
||||
) -> Result<(), AllocErr>
|
||||
where
|
||||
S: StylesheetInDocument + 'static,
|
||||
{
|
||||
|
@ -2820,7 +2842,7 @@ impl CascadeDataCacheEntry for CascadeData {
|
|||
collection: SheetCollectionFlusher<S>,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
old: &Self,
|
||||
) -> Result<Arc<Self>, FailedAllocationError>
|
||||
) -> Result<Arc<Self>, AllocErr>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
{
|
||||
|
|
|
@ -84,12 +84,12 @@ pub use self::resolution::Resolution;
|
|||
pub use self::svg::{DProperty, MozContextProperties};
|
||||
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind};
|
||||
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||
pub use self::text::HyphenateCharacter;
|
||||
pub use self::text::TextUnderlinePosition;
|
||||
pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight};
|
||||
pub use self::text::{OverflowWrap, RubyPosition, TextOverflow, WordBreak, WordSpacing};
|
||||
pub use self::text::{TextAlign, TextAlignLast, TextEmphasisPosition, TextEmphasisStyle};
|
||||
pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextJustify};
|
||||
pub use self::text::HyphenateCharacter;
|
||||
pub use self::time::Time;
|
||||
pub use self::transform::{Rotate, Scale, Transform, TransformOperation};
|
||||
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
||||
|
|
|
@ -21,10 +21,10 @@ use style_traits::{CssWriter, ToCss};
|
|||
pub use crate::values::specified::text::{
|
||||
MozControlCharacterVisibility, TextAlignLast, TextUnderlinePosition,
|
||||
};
|
||||
pub use crate::values::specified::HyphenateCharacter;
|
||||
pub use crate::values::specified::{LineBreak, OverflowWrap, RubyPosition, WordBreak};
|
||||
pub use crate::values::specified::{TextDecorationLine, TextEmphasisPosition};
|
||||
pub use crate::values::specified::{TextDecorationSkipInk, TextJustify, TextTransform};
|
||||
pub use crate::values::specified::HyphenateCharacter;
|
||||
|
||||
/// A computed value for the `initial-letter` property.
|
||||
pub type InitialLetter = GenericInitialLetter<CSSFloat, CSSInteger>;
|
||||
|
|
|
@ -244,8 +244,11 @@ impl FontRelativeLength {
|
|||
(reference_size, length)
|
||||
},
|
||||
FontRelativeLength::Ic(length) => {
|
||||
let metrics =
|
||||
query_font_metrics(context, base_size, FontMetricsOrientation::MatchContextPreferVertical);
|
||||
let metrics = query_font_metrics(
|
||||
context,
|
||||
base_size,
|
||||
FontMetricsOrientation::MatchContextPreferVertical,
|
||||
);
|
||||
let reference_size = metrics.ic_width.unwrap_or_else(|| {
|
||||
// https://drafts.csswg.org/css-values/#ic
|
||||
//
|
||||
|
|
|
@ -83,6 +83,7 @@ pub use self::svg::{DProperty, MozContextProperties};
|
|||
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint};
|
||||
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||
pub use self::svg_path::SVGPathData;
|
||||
pub use self::text::HyphenateCharacter;
|
||||
pub use self::text::RubyPosition;
|
||||
pub use self::text::TextAlignLast;
|
||||
pub use self::text::TextUnderlinePosition;
|
||||
|
@ -90,7 +91,6 @@ pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight, TextAl
|
|||
pub use self::text::{OverflowWrap, TextEmphasisPosition, TextEmphasisStyle, WordBreak};
|
||||
pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
|
||||
pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextJustify, TextTransform};
|
||||
pub use self::text::HyphenateCharacter;
|
||||
pub use self::time::Time;
|
||||
pub use self::transform::{Rotate, Scale, Transform};
|
||||
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
//! Specified @page at-rule properties and named-page style properties
|
||||
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::{generics, CustomIdent};
|
||||
use crate::values::generics::size::Size2D;
|
||||
use crate::values::specified::length::NonNegativeLength;
|
||||
use crate::values::{generics, CustomIdent};
|
||||
use cssparser::Parser;
|
||||
use style_traits::ParseError;
|
||||
|
||||
|
@ -50,7 +50,17 @@ impl Parse for PageSize {
|
|||
/// Page name value.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-page-3/#using-named-pages
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToCss,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum PageName {
|
||||
/// `auto` value.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue