mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
style: Derive more.
Differential Revision: https://phabricator.services.mozilla.com/D17029
This commit is contained in:
parent
137e735d9d
commit
af1bbd7b06
8 changed files with 14 additions and 91 deletions
|
@ -23,7 +23,6 @@ use servo_arc::{Arc, HeaderWithLength, ThinArc};
|
||||||
use smallvec::{self, SmallVec};
|
use smallvec::{self, SmallVec};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::ops::{Add, AddAssign};
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
|
@ -222,44 +221,13 @@ impl SpecificityAndFlags {
|
||||||
|
|
||||||
const MAX_10BIT: u32 = (1u32 << 10) - 1;
|
const MAX_10BIT: u32 = (1u32 << 10) - 1;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
|
#[derive(Add, AddAssign, Clone, Copy, Default, Eq, Ord, PartialEq, PartialOrd)]
|
||||||
struct Specificity {
|
struct Specificity {
|
||||||
id_selectors: u32,
|
id_selectors: u32,
|
||||||
class_like_selectors: u32,
|
class_like_selectors: u32,
|
||||||
element_selectors: u32,
|
element_selectors: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddAssign for Specificity {
|
|
||||||
#[inline]
|
|
||||||
fn add_assign(&mut self, rhs: Self) {
|
|
||||||
self.id_selectors += rhs.id_selectors;
|
|
||||||
self.class_like_selectors += rhs.class_like_selectors;
|
|
||||||
self.element_selectors += rhs.element_selectors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Add for Specificity {
|
|
||||||
type Output = Specificity;
|
|
||||||
|
|
||||||
fn add(self, rhs: Specificity) -> Specificity {
|
|
||||||
Specificity {
|
|
||||||
id_selectors: self.id_selectors + rhs.id_selectors,
|
|
||||||
class_like_selectors: self.class_like_selectors + rhs.class_like_selectors,
|
|
||||||
element_selectors: self.element_selectors + rhs.element_selectors,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Specificity {
|
|
||||||
fn default() -> Specificity {
|
|
||||||
Specificity {
|
|
||||||
id_selectors: 0,
|
|
||||||
class_like_selectors: 0,
|
|
||||||
element_selectors: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u32> for Specificity {
|
impl From<u32> for Specificity {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(value: u32) -> Specificity {
|
fn from(value: u32) -> Specificity {
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
extern crate bitflags;
|
extern crate bitflags;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate cssparser;
|
extern crate cssparser;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate derive_more;
|
||||||
extern crate fxhash;
|
extern crate fxhash;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
|
|
@ -304,7 +304,7 @@ impl ElementCascadeInputs {
|
||||||
/// Statistics gathered during the traversal. We gather statistics on each
|
/// Statistics gathered during the traversal. We gather statistics on each
|
||||||
/// thread and then combine them after the threads join via the Add
|
/// thread and then combine them after the threads join via the Add
|
||||||
/// implementation below.
|
/// implementation below.
|
||||||
#[derive(Default)]
|
#[derive(AddAssign, Clone, Default)]
|
||||||
pub struct PerThreadTraversalStatistics {
|
pub struct PerThreadTraversalStatistics {
|
||||||
/// The total number of elements traversed.
|
/// The total number of elements traversed.
|
||||||
pub elements_traversed: u32,
|
pub elements_traversed: u32,
|
||||||
|
@ -319,20 +319,6 @@ pub struct PerThreadTraversalStatistics {
|
||||||
pub styles_reused: u32,
|
pub styles_reused: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation of Add to aggregate statistics across different threads.
|
|
||||||
impl<'a> ops::Add for &'a PerThreadTraversalStatistics {
|
|
||||||
type Output = PerThreadTraversalStatistics;
|
|
||||||
fn add(self, other: Self) -> PerThreadTraversalStatistics {
|
|
||||||
PerThreadTraversalStatistics {
|
|
||||||
elements_traversed: self.elements_traversed + other.elements_traversed,
|
|
||||||
elements_styled: self.elements_styled + other.elements_styled,
|
|
||||||
elements_matched: self.elements_matched + other.elements_matched,
|
|
||||||
styles_shared: self.styles_shared + other.styles_shared,
|
|
||||||
styles_reused: self.styles_reused + other.styles_reused,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Statistics gathered during the traversal plus some information from
|
/// Statistics gathered during the traversal plus some information from
|
||||||
/// other sources including stylist.
|
/// other sources including stylist.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
@ -161,10 +161,11 @@ pub fn traverse_dom<E, D>(
|
||||||
let parallel = maybe_tls.is_some();
|
let parallel = maybe_tls.is_some();
|
||||||
if let Some(ref mut tls) = maybe_tls {
|
if let Some(ref mut tls) = maybe_tls {
|
||||||
let slots = unsafe { tls.unsafe_get() };
|
let slots = unsafe { tls.unsafe_get() };
|
||||||
aggregate = slots.iter().fold(aggregate, |acc, t| match *t.borrow() {
|
for slot in slots {
|
||||||
None => acc,
|
if let Some(ref cx) = *slot.borrow() {
|
||||||
Some(ref cx) => &cx.statistics + &acc,
|
aggregate += cx.statistics.clone();
|
||||||
});
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if report_stats {
|
if report_stats {
|
||||||
|
|
|
@ -37,6 +37,8 @@ extern crate crossbeam_channel;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate cssparser;
|
extern crate cssparser;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
extern crate derive_more;
|
||||||
|
#[macro_use]
|
||||||
extern crate debug_unreachable;
|
extern crate debug_unreachable;
|
||||||
extern crate euclid;
|
extern crate euclid;
|
||||||
extern crate fallible;
|
extern crate fallible;
|
||||||
|
|
|
@ -9,13 +9,12 @@ use crate::values::CSSFloat;
|
||||||
use num_traits::Zero;
|
use num_traits::Zero;
|
||||||
use std::f64::consts::PI;
|
use std::f64::consts::PI;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::ops::Add;
|
|
||||||
use std::{f32, f64};
|
use std::{f32, f64};
|
||||||
use style_traits::{CssWriter, ToCss};
|
use style_traits::{CssWriter, ToCss};
|
||||||
|
|
||||||
/// A computed angle in degrees.
|
/// A computed angle in degrees.
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
#[derive(Animate, Clone, Copy, Debug, MallocSizeOf, PartialEq, PartialOrd, ToAnimatedZero)]
|
#[derive(Add, Animate, Clone, Copy, Debug, MallocSizeOf, PartialEq, PartialOrd, ToAnimatedZero)]
|
||||||
pub struct Angle(CSSFloat);
|
pub struct Angle(CSSFloat);
|
||||||
|
|
||||||
impl ToCss for Angle {
|
impl ToCss for Angle {
|
||||||
|
@ -66,15 +65,6 @@ impl Angle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add for Angle {
|
|
||||||
type Output = Self;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn add(self, rhs: Self) -> Self {
|
|
||||||
Angle(self.0 + rhs.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Zero for Angle {
|
impl Zero for Angle {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn zero() -> Self {
|
fn zero() -> Self {
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub trait ComputeSquaredDistance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A distance between two animatable values.
|
/// A distance between two animatable values.
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Add, Clone, Copy, Debug, From)]
|
||||||
pub struct SquaredDistance {
|
pub struct SquaredDistance {
|
||||||
value: f64,
|
value: f64,
|
||||||
}
|
}
|
||||||
|
@ -114,24 +114,6 @@ impl SquaredDistance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SquaredDistance> for f64 {
|
|
||||||
#[inline]
|
|
||||||
fn from(distance: SquaredDistance) -> Self {
|
|
||||||
distance.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Add for SquaredDistance {
|
|
||||||
type Output = Self;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn add(self, rhs: Self) -> Self {
|
|
||||||
SquaredDistance {
|
|
||||||
value: self.value + rhs.value,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Sum for SquaredDistance {
|
impl Sum for SquaredDistance {
|
||||||
fn sum<I>(iter: I) -> Self
|
fn sum<I>(iter: I) -> Self
|
||||||
where
|
where
|
||||||
|
|
|
@ -11,7 +11,6 @@ use crate::values::CSSFloat;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::iter::{Cloned, Peekable};
|
use std::iter::{Cloned, Peekable};
|
||||||
use std::ops::AddAssign;
|
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use style_traits::values::SequenceWriter;
|
use style_traits::values::SequenceWriter;
|
||||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||||
|
@ -491,6 +490,7 @@ impl IsAbsolute {
|
||||||
|
|
||||||
/// The path coord type.
|
/// The path coord type.
|
||||||
#[derive(
|
#[derive(
|
||||||
|
AddAssign,
|
||||||
Animate,
|
Animate,
|
||||||
Clone,
|
Clone,
|
||||||
ComputeSquaredDistance,
|
ComputeSquaredDistance,
|
||||||
|
@ -513,14 +513,6 @@ impl CoordPair {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddAssign for CoordPair {
|
|
||||||
#[inline]
|
|
||||||
fn add_assign(&mut self, other: Self) {
|
|
||||||
self.0 += other.0;
|
|
||||||
self.1 += other.1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The EllipticalArc flag type.
|
/// The EllipticalArc flag type.
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue