summaryrefslogtreecommitdiffstats
path: root/servo/components/style/stylesheets
diff options
context:
space:
mode:
Diffstat (limited to 'servo/components/style/stylesheets')
-rw-r--r--servo/components/style/stylesheets/font_feature_values_rule.rs34
-rw-r--r--servo/components/style/stylesheets/margin_rule.rs42
2 files changed, 49 insertions, 27 deletions
diff --git a/servo/components/style/stylesheets/font_feature_values_rule.rs b/servo/components/style/stylesheets/font_feature_values_rule.rs
index 06016ec2bd..73d499c041 100644
--- a/servo/components/style/stylesheets/font_feature_values_rule.rs
+++ b/servo/components/style/stylesheets/font_feature_values_rule.rs
@@ -10,7 +10,7 @@ use crate::error_reporting::ContextualParseError;
#[cfg(feature = "gecko")]
use crate::gecko_bindings::bindings::Gecko_AppendFeatureValueHashEntry;
#[cfg(feature = "gecko")]
-use crate::gecko_bindings::structs::{self, gfxFontFeatureValueSet, nsTArray};
+use crate::gecko_bindings::structs::{self, gfxFontFeatureValueSet};
use crate::parser::{Parse, ParserContext};
use crate::shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use crate::str::CssStringWriter;
@@ -24,6 +24,7 @@ use cssparser::{
};
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
+use thin_vec::ThinVec;
/// A @font-feature-values block declaration.
/// It is `<ident>: <integer>+`.
@@ -54,8 +55,8 @@ impl<T: ToCss> ToCss for FFVDeclaration<T> {
/// A trait for @font-feature-values rule to gecko values conversion.
#[cfg(feature = "gecko")]
pub trait ToGeckoFontFeatureValues {
- /// Sets the equivalent of declaration to gecko `nsTArray<u32>` array.
- fn to_gecko_font_feature_values(&self, array: &mut nsTArray<u32>);
+ /// Sets the equivalent of declaration to gecko `ThinVec<u32>` array.
+ fn to_gecko_font_feature_values(&self) -> ThinVec<u32>;
}
/// A @font-feature-values block declaration value that keeps one value.
@@ -79,11 +80,8 @@ impl Parse for SingleValue {
#[cfg(feature = "gecko")]
impl ToGeckoFontFeatureValues for SingleValue {
- fn to_gecko_font_feature_values(&self, array: &mut nsTArray<u32>) {
- unsafe {
- array.set_len_pod(1);
- }
- array[0] = self.0 as u32;
+ fn to_gecko_font_feature_values(&self) -> ThinVec<u32> {
+ thin_vec::thin_vec![self.0 as u32]
}
}
@@ -118,16 +116,12 @@ impl Parse for PairValues {
#[cfg(feature = "gecko")]
impl ToGeckoFontFeatureValues for PairValues {
- fn to_gecko_font_feature_values(&self, array: &mut nsTArray<u32>) {
- let len = if self.1.is_some() { 2 } else { 1 };
-
- unsafe {
- array.set_len_pod(len);
- }
- array[0] = self.0 as u32;
+ fn to_gecko_font_feature_values(&self) -> ThinVec<u32> {
+ let mut result = thin_vec::thin_vec![self.0 as u32];
if let Some(second) = self.1 {
- array[1] = second as u32;
- };
+ result.push(second as u32);
+ }
+ result
}
}
@@ -165,8 +159,8 @@ impl Parse for VectorValues {
#[cfg(feature = "gecko")]
impl ToGeckoFontFeatureValues for VectorValues {
- fn to_gecko_font_feature_values(&self, array: &mut nsTArray<u32>) {
- array.assign_from_iter_pod(self.0.iter().map(|v| *v));
+ fn to_gecko_font_feature_values(&self) -> ThinVec<u32> {
+ self.0.iter().copied().collect()
}
}
@@ -338,7 +332,7 @@ macro_rules! font_feature_values_blocks {
)
};
unsafe {
- val.value.to_gecko_font_feature_values(&mut *array);
+ *array = val.value.to_gecko_font_feature_values();
}
}
}
diff --git a/servo/components/style/stylesheets/margin_rule.rs b/servo/components/style/stylesheets/margin_rule.rs
index ab46283151..19928c04ba 100644
--- a/servo/components/style/stylesheets/margin_rule.rs
+++ b/servo/components/style/stylesheets/margin_rule.rs
@@ -21,19 +21,21 @@ macro_rules! margin_rule_types {
/// [`@margin`][margin] rule names.
///
/// https://drafts.csswg.org/css-page-3/#margin-at-rules
- #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToShmem)]
+ #[derive(Clone, Copy, Eq, MallocSizeOf, PartialEq, ToShmem)]
#[repr(u8)]
pub enum MarginRuleType {
$($(#[$($meta)+])* $id,)+
}
+ /// All [`@margin`][margin] rule names, with a preceding '@'.
+ ///
+ /// This array lets us have just one single memory region used for
+ /// to_str, name, and the Debug implementation.
+ const MARGIN_RULE_AT_NAMES:&[&'static str] = &[
+ $( concat!('@', $val), )+
+ ];
+
impl MarginRuleType {
- #[inline]
- fn to_str(&self) -> &'static str {
- match *self {
- $(MarginRuleType::$id => concat!('@', $val),)+
- }
- }
/// Matches the rule type for this name. This does not expect a
/// leading '@'.
pub fn match_name(name: &str) -> Option<Self> {
@@ -113,6 +115,27 @@ margin_rule_types! {
RightBottom => "right-bottom",
}
+impl MarginRuleType {
+ #[inline]
+ fn to_str(&self) -> &'static str {
+ &MARGIN_RULE_AT_NAMES[*self as usize]
+ }
+ #[inline]
+ fn name(&self) -> &'static str {
+ // Use the at-name array, skipping the first character to get
+ // the name without the @ sign.
+ &MARGIN_RULE_AT_NAMES[*self as usize][1..]
+ }
+}
+
+// Implement Debug manually so that it will share the same string memory as
+// MarginRuleType::name and MarginRuleType::to_str.
+impl fmt::Debug for MarginRuleType {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
+ f.write_str(self.name())
+ }
+}
+
/// A [`@margin`][margin] rule.
///
/// [margin]: https://drafts.csswg.org/css-page-3/#margin-at-rules
@@ -134,6 +157,11 @@ impl MarginRule {
self.block.unconditional_shallow_size_of(ops) +
self.block.read_with(guard).size_of(ops)
}
+ /// Gets the name for this margin rule.
+ #[inline]
+ pub fn name(&self) -> &'static str {
+ self.rule_type.name()
+ }
}
impl ToCssWithGuard for MarginRule {