mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Auto merge of #16661 - emilio:alloc, r=bholley
style: Use SmallVec more in the style system. I expect this to improve the situation significantly in https://bugzilla.mozilla.org/show_bug.cgi?id=1360881 This is worth doing on its own, though. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16661) <!-- Reviewable:end -->
This commit is contained in:
commit
a75fa0825c
9 changed files with 68 additions and 57 deletions
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -987,7 +987,7 @@ dependencies = [
|
|||
"servo_geometry 0.0.1",
|
||||
"servo_url 0.0.1",
|
||||
"simd 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"style 0.0.1",
|
||||
"style_traits 0.0.1",
|
||||
"time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1385,7 +1385,7 @@ dependencies = [
|
|||
"servo_config 0.0.1",
|
||||
"servo_geometry 0.0.1",
|
||||
"servo_url 0.0.1",
|
||||
"smallvec 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"style 0.0.1",
|
||||
"style_traits 0.0.1",
|
||||
"unicode-bidi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1966,7 +1966,7 @@ dependencies = [
|
|||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -2293,7 +2293,7 @@ dependencies = [
|
|||
"servo_geometry 0.0.1",
|
||||
"servo_rand 0.0.1",
|
||||
"servo_url 0.0.1",
|
||||
"smallvec 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"style 0.0.1",
|
||||
"style_traits 0.0.1",
|
||||
"time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2389,7 +2389,7 @@ dependencies = [
|
|||
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"precomputed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2685,8 +2685,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "string_cache"
|
||||
|
@ -2762,7 +2765,7 @@ dependencies = [
|
|||
"servo_atoms 0.0.1",
|
||||
"servo_config 0.0.1",
|
||||
"servo_url 0.0.1",
|
||||
"smallvec 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"style_traits 0.0.1",
|
||||
"time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3520,7 +3523,7 @@ dependencies = [
|
|||
"checksum simd 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a94d14a2ae1f1f110937de5fb69e494372560181c7e1739a097fcc2cee37ba0"
|
||||
"checksum siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0df90a788073e8d0235a67e50441d47db7c8ad9debd91cbf43736a2a92d36537"
|
||||
"checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23"
|
||||
"checksum smallvec 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dca03f2f42500a9ef8ac0d16183dff8bed40e3dcf98f9d4147928548d5c4236e"
|
||||
"checksum smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4f8266519bc1d17d0b5b16f6c21295625d562841c708f6376f49028a43e9c11e"
|
||||
"checksum string_cache 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f55fba06c5e294108f22e8512eb598cb13388a117991e411a8df8f41a1219a75"
|
||||
"checksum string_cache_codegen 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "479cde50c3539481f33906a387f2bd17c8e87cb848c35b6021d41fb81ff9b4d7"
|
||||
"checksum string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc"
|
||||
|
|
|
@ -17,7 +17,7 @@ gecko = ["nsstring_vendor", "rayon/unstable", "num_cpus"]
|
|||
use_bindgen = ["bindgen", "regex"]
|
||||
servo = ["serde/unstable", "serde", "serde_derive", "heapsize", "heapsize_derive",
|
||||
"style_traits/servo", "servo_atoms", "servo_config", "html5ever-atoms",
|
||||
"cssparser/heapsize", "cssparser/serde", "encoding",
|
||||
"cssparser/heapsize", "cssparser/serde", "encoding", "smallvec/heapsizeof",
|
||||
"rayon/unstable", "servo_url"]
|
||||
testing = []
|
||||
gecko_debug = ["nsstring_vendor/gecko_debug"]
|
||||
|
@ -53,7 +53,7 @@ serde = {version = "0.9", optional = true}
|
|||
serde_derive = {version = "0.9", optional = true}
|
||||
servo_atoms = {path = "../atoms", optional = true}
|
||||
servo_config = {path = "../config", optional = true}
|
||||
smallvec = "0.3"
|
||||
smallvec = "0.3.3"
|
||||
style_traits = {path = "../style_traits"}
|
||||
servo_url = {path = "../url", optional = true}
|
||||
time = "0.1"
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
//! The context within which CSS code is parsed.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use context::QuirksMode;
|
||||
use cssparser::{Parser, SourcePosition, UnicodeRange};
|
||||
use error_reporting::ParseErrorReporter;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
use app_units::Au;
|
||||
use cssparser::{Color as CSSParserColor, RGBA};
|
||||
use values::specified::AllowQuirks;
|
||||
use smallvec::SmallVec;
|
||||
pub use values::specified::${type} as SpecifiedValue;
|
||||
pub mod computed_value {
|
||||
% if computed_type:
|
||||
|
@ -75,6 +76,7 @@
|
|||
delegate_animate=False, space_separated_allowed=False, **kwargs)">
|
||||
<%call expr="longhand(name, **kwargs)">
|
||||
% if not gecko_only:
|
||||
use smallvec::SmallVec;
|
||||
use std::fmt;
|
||||
use values::HasViewportPercentage;
|
||||
use style_traits::ToCss;
|
||||
|
@ -100,10 +102,11 @@
|
|||
pub mod computed_value {
|
||||
pub use super::single_value::computed_value as single_value;
|
||||
pub use self::single_value::T as SingleComputedValue;
|
||||
use smallvec::SmallVec;
|
||||
/// The computed value, effectively a list of single values.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Vec<single_value::T>);
|
||||
pub struct T(pub SmallVec<[single_value::T; 1]>);
|
||||
|
||||
% if delegate_animate:
|
||||
use properties::animated_properties::Interpolate;
|
||||
|
@ -179,9 +182,11 @@
|
|||
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
% if allow_empty:
|
||||
computed_value::T(vec![])
|
||||
computed_value::T(SmallVec::new())
|
||||
% else:
|
||||
computed_value::T(vec![single_value::get_initial_value()])
|
||||
let mut v = SmallVec::new();
|
||||
v.push(single_value::get_initial_value());
|
||||
computed_value::T(v)
|
||||
% endif
|
||||
}
|
||||
|
||||
|
@ -193,19 +198,16 @@
|
|||
if space_separated_allowed:
|
||||
parse_func = "parse_space_or_comma_separated"
|
||||
%>
|
||||
|
||||
% if allow_empty:
|
||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||
Ok(SpecifiedValue(Vec::new()))
|
||||
} else {
|
||||
${parse_func}(input, |parser| {
|
||||
single_value::parse(context, parser)
|
||||
}).map(SpecifiedValue)
|
||||
return Ok(SpecifiedValue(Vec::new()))
|
||||
}
|
||||
% else:
|
||||
% endif
|
||||
|
||||
${parse_func}(input, |parser| {
|
||||
single_value::parse(context, parser)
|
||||
}).map(SpecifiedValue)
|
||||
% endif
|
||||
}
|
||||
|
||||
pub use self::single_value::SpecifiedValue as SingleSpecifiedValue;
|
||||
|
@ -220,7 +222,7 @@
|
|||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||
SpecifiedValue(computed.0.iter()
|
||||
.map(|x| ToComputedValue::from_computed_value(x))
|
||||
.map(ToComputedValue::from_computed_value)
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ use properties::longhands::vertical_align::computed_value::T as VerticalAlign;
|
|||
use properties::longhands::visibility::computed_value::T as Visibility;
|
||||
#[cfg(feature = "gecko")] use properties::{PropertyDeclarationId, LonghandId};
|
||||
#[cfg(feature = "servo")] use servo_atoms::Atom;
|
||||
use smallvec::SmallVec;
|
||||
use std::cmp;
|
||||
#[cfg(feature = "gecko")] use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
|
@ -612,7 +613,7 @@ pub trait Interpolate: Sized {
|
|||
/// https://drafts.csswg.org/css-transitions/#animtype-repeatable-list
|
||||
pub trait RepeatableListInterpolate: Interpolate {}
|
||||
|
||||
impl<T: RepeatableListInterpolate> Interpolate for Vec<T> {
|
||||
impl<T: RepeatableListInterpolate> Interpolate for SmallVec<[T; 1]> {
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
use num_integer::lcm;
|
||||
let len = lcm(self.len(), other.len());
|
||||
|
@ -1065,7 +1066,12 @@ impl Interpolate for ClipRect {
|
|||
};
|
||||
|
||||
let max_len = cmp::max(self.0.len(), other.0.len());
|
||||
let mut result = Vec::with_capacity(max_len);
|
||||
|
||||
let mut result = if max_len > 1 {
|
||||
SmallVec::from_vec(Vec::with_capacity(max_len))
|
||||
} else {
|
||||
SmallVec::new()
|
||||
};
|
||||
|
||||
for i in 0..max_len {
|
||||
let shadow = match (self.0.get(i), other.0.get(i)) {
|
||||
|
@ -2192,7 +2198,7 @@ pub trait ComputeDistance: Sized {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: ComputeDistance> ComputeDistance for Vec<T> {
|
||||
impl<T: ComputeDistance> ComputeDistance for SmallVec<[T; 1]> {
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||
|
@ -2848,7 +2854,7 @@ impl <'a> From<<&'a IntermediateColor> for CSSParserColor {
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
/// Intermediate type for box-shadow list and text-shadow list.
|
||||
pub struct Intermediate${type}ShadowList(pub Vec<Intermediate${type}Shadow>);
|
||||
pub struct Intermediate${type}ShadowList(pub SmallVec<[Intermediate${type}Shadow; 1]>);
|
||||
|
||||
impl <'a> From<<&'a Intermediate${type}ShadowList> for ${type}ShadowList {
|
||||
fn from(shadow_list: &Intermediate${type}ShadowList) -> ${type}ShadowList {
|
||||
|
|
|
@ -145,7 +145,7 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style',
|
|||
match *computed {
|
||||
computed_value::T(Some(ref vec)) => {
|
||||
SpecifiedValue::Colors(vec.iter()
|
||||
.map(|c| ToComputedValue::from_computed_value((c)))
|
||||
.map(ToComputedValue::from_computed_value)
|
||||
.collect())
|
||||
},
|
||||
computed_value::T(None) => {
|
||||
|
@ -675,7 +675,7 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T {
|
||||
pub corners: Vec<NumberOrPercentage>,
|
||||
pub corners: [NumberOrPercentage; 4],
|
||||
pub fill: bool,
|
||||
}
|
||||
}
|
||||
|
@ -721,7 +721,7 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
|
|||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T {
|
||||
corners: vec![ComputedNumberOrPercentage::Percentage(Percentage(1.0)),
|
||||
corners: [ComputedNumberOrPercentage::Percentage(Percentage(1.0)),
|
||||
ComputedNumberOrPercentage::Percentage(Percentage(1.0)),
|
||||
ComputedNumberOrPercentage::Percentage(Percentage(1.0)),
|
||||
ComputedNumberOrPercentage::Percentage(Percentage(1.0))],
|
||||
|
@ -744,19 +744,19 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
|
|||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
let length = self.corners.len();
|
||||
let corners = match length {
|
||||
4 => vec![self.corners[0].to_computed_value(context),
|
||||
4 => [self.corners[0].to_computed_value(context),
|
||||
self.corners[1].to_computed_value(context),
|
||||
self.corners[2].to_computed_value(context),
|
||||
self.corners[3].to_computed_value(context)],
|
||||
3 => vec![self.corners[0].to_computed_value(context),
|
||||
3 => [self.corners[0].to_computed_value(context),
|
||||
self.corners[1].to_computed_value(context),
|
||||
self.corners[2].to_computed_value(context),
|
||||
self.corners[1].to_computed_value(context)],
|
||||
2 => vec![self.corners[0].to_computed_value(context),
|
||||
2 => [self.corners[0].to_computed_value(context),
|
||||
self.corners[1].to_computed_value(context),
|
||||
self.corners[0].to_computed_value(context),
|
||||
self.corners[1].to_computed_value(context)],
|
||||
1 => vec![self.corners[0].to_computed_value(context),
|
||||
1 => [self.corners[0].to_computed_value(context),
|
||||
self.corners[0].to_computed_value(context),
|
||||
self.corners[0].to_computed_value(context),
|
||||
self.corners[0].to_computed_value(context)],
|
||||
|
@ -791,11 +791,11 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
|
|||
}
|
||||
}
|
||||
|
||||
if fill == false {
|
||||
if !fill {
|
||||
fill = input.try(|input| input.expect_ident_matching("fill")).is_ok();
|
||||
}
|
||||
|
||||
if values.len() > 0 {
|
||||
if !values.is_empty() {
|
||||
Ok(SpecifiedValue {
|
||||
corners: values,
|
||||
fill: fill
|
||||
|
|
|
@ -753,10 +753,11 @@ ${helpers.single_keyword("text-align-last",
|
|||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
use cssparser::Color;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Vec<TextShadow>);
|
||||
pub struct T(pub SmallVec<[TextShadow; 1]>);
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
@ -833,7 +834,8 @@ ${helpers.single_keyword("text-align-last",
|
|||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(Vec::new())
|
||||
use smallvec::SmallVec;
|
||||
computed_value::T(SmallVec::new())
|
||||
}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
|
|
|
@ -214,7 +214,7 @@
|
|||
}
|
||||
Ok(())
|
||||
}));
|
||||
if any == false {
|
||||
if !any {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
|
|
|
@ -332,7 +332,7 @@ pub struct Shadow {
|
|||
/// A `<number>` value.
|
||||
pub type Number = CSSFloat;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum NumberOrPercentage {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue