mirror of
https://github.com/servo/servo.git
synced 2025-08-01 11:40:30 +01:00
Use a newtype within EagerPseudoValues.
MozReview-Commit-ID: IIDxBJ8mqvJ
This commit is contained in:
parent
e2a26e7bd0
commit
af89c74ab7
2 changed files with 33 additions and 11 deletions
|
@ -332,7 +332,7 @@ impl Clone for EagerPseudoCascadeInputs {
|
||||||
impl EagerPseudoCascadeInputs {
|
impl EagerPseudoCascadeInputs {
|
||||||
/// Construct inputs from previous cascade results, if any.
|
/// Construct inputs from previous cascade results, if any.
|
||||||
fn new_from_style(styles: &EagerPseudoStyles) -> Self {
|
fn new_from_style(styles: &EagerPseudoStyles) -> Self {
|
||||||
EagerPseudoCascadeInputs(styles.0.as_ref().map(|styles| {
|
EagerPseudoCascadeInputs(styles.as_array().map(|styles| {
|
||||||
let mut inputs: [Option<CascadeInputs>; EAGER_PSEUDO_COUNT] = Default::default();
|
let mut inputs: [Option<CascadeInputs>; EAGER_PSEUDO_COUNT] = Default::default();
|
||||||
for i in 0..EAGER_PSEUDO_COUNT {
|
for i in 0..EAGER_PSEUDO_COUNT {
|
||||||
inputs[i] = styles[i].as_ref().map(|s| CascadeInputs::new_from_style(s));
|
inputs[i] = styles[i].as_ref().map(|s| CascadeInputs::new_from_style(s));
|
||||||
|
|
|
@ -13,6 +13,7 @@ use properties::longhands::display::computed_value as display;
|
||||||
use rule_tree::StrongRuleNode;
|
use rule_tree::StrongRuleNode;
|
||||||
use selector_parser::{EAGER_PSEUDO_COUNT, PseudoElement, RestyleDamage};
|
use selector_parser::{EAGER_PSEUDO_COUNT, PseudoElement, RestyleDamage};
|
||||||
use shared_lock::{Locked, StylesheetGuards};
|
use shared_lock::{Locked, StylesheetGuards};
|
||||||
|
use std::ops::{Deref, DerefMut};
|
||||||
use stylearc::Arc;
|
use stylearc::Arc;
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
@ -100,22 +101,35 @@ impl RestyleData {
|
||||||
|
|
||||||
/// A list of styles for eagerly-cascaded pseudo-elements.
|
/// A list of styles for eagerly-cascaded pseudo-elements.
|
||||||
/// Lazily-allocated.
|
/// Lazily-allocated.
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct EagerPseudoStyles(pub Option<Box<[Option<Arc<ComputedValues>>; EAGER_PSEUDO_COUNT]>>);
|
pub struct EagerPseudoStyles(Option<Box<EagerPseudoArray>>);
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
struct EagerPseudoArray(EagerPseudoArrayInner);
|
||||||
|
type EagerPseudoArrayInner = [Option<Arc<ComputedValues>>; EAGER_PSEUDO_COUNT];
|
||||||
|
|
||||||
|
impl Deref for EagerPseudoArray {
|
||||||
|
type Target = EagerPseudoArrayInner;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DerefMut for EagerPseudoArray {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Manually implement `Clone` here because the derived impl of `Clone` for
|
// Manually implement `Clone` here because the derived impl of `Clone` for
|
||||||
// array types assumes the value inside is `Copy`.
|
// array types assumes the value inside is `Copy`.
|
||||||
impl Clone for EagerPseudoStyles {
|
impl Clone for EagerPseudoArray {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
if self.0.is_none() {
|
let mut clone = Self::default();
|
||||||
return EagerPseudoStyles(None)
|
|
||||||
}
|
|
||||||
let self_values = self.0.as_ref().unwrap();
|
|
||||||
let mut values: [Option<Arc<ComputedValues>>; EAGER_PSEUDO_COUNT] = Default::default();
|
|
||||||
for i in 0..EAGER_PSEUDO_COUNT {
|
for i in 0..EAGER_PSEUDO_COUNT {
|
||||||
values[i] = self_values[i].clone();
|
clone[i] = self.0[i].clone();
|
||||||
}
|
}
|
||||||
EagerPseudoStyles(Some(Box::new(values)))
|
clone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +139,14 @@ impl EagerPseudoStyles {
|
||||||
self.0.is_none()
|
self.0.is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Grabs a reference to the list of styles, if they exist.
|
||||||
|
pub fn as_array(&self) -> Option<&EagerPseudoArrayInner> {
|
||||||
|
match self.0 {
|
||||||
|
None => None,
|
||||||
|
Some(ref x) => Some(&x.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a reference to the style for a given eager pseudo, if it exists.
|
/// Returns a reference to the style for a given eager pseudo, if it exists.
|
||||||
pub fn get(&self, pseudo: &PseudoElement) -> Option<&Arc<ComputedValues>> {
|
pub fn get(&self, pseudo: &PseudoElement) -> Option<&Arc<ComputedValues>> {
|
||||||
debug_assert!(pseudo.is_eager());
|
debug_assert!(pseudo.is_eager());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue