mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Avoid UTF-8 -> UTF-16 conversion during CSSOM serialization.
This lifts a bunch of string conversions higher up the stack, but allows us to make the servo code use utf-8 unconditionally, and seemed faster in my benchmarking (see comment 0). It should also make a bunch of attribute setters faster too (like setting .cssText), now that we use UTF8String for them (we couldn't because we couldn't specify different string types for the getter and setters). Differential Revision: https://phabricator.services.mozilla.com/D99590
This commit is contained in:
parent
a3f84f85e3
commit
f58301ecbc
3 changed files with 15 additions and 101 deletions
|
@ -14,7 +14,7 @@ use crate::parser::ParserContext;
|
|||
use crate::properties::animated_properties::{AnimationValue, AnimationValueMap};
|
||||
use crate::selector_parser::SelectorImpl;
|
||||
use crate::shared_lock::Locked;
|
||||
use crate::str::{CssString, CssStringBorrow, CssStringWriter};
|
||||
use crate::str::{CssString, CssStringWriter};
|
||||
use crate::stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
use crate::values::computed::Context;
|
||||
use cssparser::{parse_important, CowRcStr, DeclarationListParser, ParserInput};
|
||||
|
@ -1093,7 +1093,11 @@ impl PropertyDeclarationBlock {
|
|||
}
|
||||
|
||||
AppendableValue::Css {
|
||||
css: CssStringBorrow::from(&v),
|
||||
// Safety: serialization only generates valid utf-8.
|
||||
#[cfg(feature = "gecko")]
|
||||
css: unsafe { v.as_str_unchecked() },
|
||||
#[cfg(feature = "servo")]
|
||||
css: &v,
|
||||
with_variables: false,
|
||||
}
|
||||
},
|
||||
|
@ -1179,7 +1183,7 @@ where
|
|||
/// or when storing a serialized shorthand value before appending directly.
|
||||
Css {
|
||||
/// The raw CSS string.
|
||||
css: CssStringBorrow<'a>,
|
||||
css: &'a str,
|
||||
/// Whether the original serialization contained variables or not.
|
||||
with_variables: bool,
|
||||
},
|
||||
|
@ -1207,7 +1211,7 @@ where
|
|||
I: Iterator<Item = &'a PropertyDeclaration>,
|
||||
{
|
||||
match appendable_value {
|
||||
AppendableValue::Css { css, .. } => css.append_to(dest),
|
||||
AppendableValue::Css { css, .. } => dest.write_str(css),
|
||||
AppendableValue::Declaration(decl) => decl.to_css(dest),
|
||||
AppendableValue::DeclarationsForShorthand(shorthand, decls) => {
|
||||
shorthand.longhands_to_css(decls, &mut CssWriter::new(dest))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue