mirror of
https://github.com/servo/servo.git
synced 2025-07-30 18:50:36 +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 {
|
||||
/// Construct inputs from previous cascade results, if any.
|
||||
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();
|
||||
for i in 0..EAGER_PSEUDO_COUNT {
|
||||
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 selector_parser::{EAGER_PSEUDO_COUNT, PseudoElement, RestyleDamage};
|
||||
use shared_lock::{Locked, StylesheetGuards};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use stylearc::Arc;
|
||||
|
||||
bitflags! {
|
||||
|
@ -100,22 +101,35 @@ impl RestyleData {
|
|||
|
||||
/// A list of styles for eagerly-cascaded pseudo-elements.
|
||||
/// Lazily-allocated.
|
||||
#[derive(Debug)]
|
||||
pub struct EagerPseudoStyles(pub Option<Box<[Option<Arc<ComputedValues>>; EAGER_PSEUDO_COUNT]>>);
|
||||
#[derive(Clone, Debug)]
|
||||
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
|
||||
// array types assumes the value inside is `Copy`.
|
||||
impl Clone for EagerPseudoStyles {
|
||||
impl Clone for EagerPseudoArray {
|
||||
fn clone(&self) -> Self {
|
||||
if self.0.is_none() {
|
||||
return EagerPseudoStyles(None)
|
||||
}
|
||||
let self_values = self.0.as_ref().unwrap();
|
||||
let mut values: [Option<Arc<ComputedValues>>; EAGER_PSEUDO_COUNT] = Default::default();
|
||||
let mut clone = Self::default();
|
||||
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()
|
||||
}
|
||||
|
||||
/// 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.
|
||||
pub fn get(&self, pseudo: &PseudoElement) -> Option<&Arc<ComputedValues>> {
|
||||
debug_assert!(pseudo.is_eager());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue