Skip to content

Commit 039592f

Browse files
committed
Bug 1682003 - Avoid UTF-8 -> UTF-16 conversion during CSSOM serialization. r=heycam
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
1 parent c2e233e commit 039592f

File tree

122 files changed

+671
-749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+671
-749
lines changed

accessible/base/StyleInfo.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ StyleInfo::StyleInfo(dom::Element* aElement) : mElement(aElement) {
2121

2222
void StyleInfo::Display(nsAString& aValue) {
2323
aValue.Truncate();
24-
mComputedStyle->GetComputedPropertyValue(eCSSProperty_display, aValue);
24+
nsAutoCString value;
25+
mComputedStyle->GetComputedPropertyValue(eCSSProperty_display, value);
26+
CopyUTF8toUTF16(value, aValue);
2527
}
2628

2729
void StyleInfo::TextAlign(nsAString& aValue) {
2830
aValue.Truncate();
29-
mComputedStyle->GetComputedPropertyValue(eCSSProperty_text_align, aValue);
31+
nsAutoCString value;
32+
mComputedStyle->GetComputedPropertyValue(eCSSProperty_text_align, value);
33+
CopyUTF8toUTF16(value, aValue);
3034
}
3135

3236
void StyleInfo::TextIndent(nsAString& aValue) {

accessible/windows/sdn/sdnAccessible.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ sdnAccessible::get_computedStyle(
220220
for (index = realIndex = 0; index < length && realIndex < aMaxStyleProperties;
221221
index++) {
222222
nsAutoCString property;
223-
nsAutoString value;
223+
nsAutoCString value;
224224

225225
// Ignore -moz-* properties.
226226
cssDecl->Item(index, property);
@@ -230,7 +230,8 @@ sdnAccessible::get_computedStyle(
230230
if (!value.IsEmpty()) {
231231
aStyleProperties[realIndex] =
232232
::SysAllocString(NS_ConvertUTF8toUTF16(property).get());
233-
aStyleValues[realIndex] = ::SysAllocString(value.get());
233+
aStyleValues[realIndex] =
234+
::SysAllocString(NS_ConvertUTF8toUTF16(value).get());
234235
++realIndex;
235236
}
236237
}
@@ -256,12 +257,12 @@ sdnAccessible::get_computedStyleForProperties(
256257

257258
uint32_t index = 0;
258259
for (index = 0; index < aNumStyleProperties; index++) {
259-
nsAutoString value;
260+
nsAutoCString value;
260261
if (aStyleProperties[index])
261262
cssDecl->GetPropertyValue(
262263
NS_ConvertUTF16toUTF8(nsDependentString(aStyleProperties[index])),
263264
value); // Get property value
264-
aStyleValues[index] = ::SysAllocString(value.get());
265+
aStyleValues[index] = ::SysAllocString(NS_ConvertUTF8toUTF16(value).get());
265266
}
266267

267268
return S_OK;

dom/animation/ComputedTimingFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ int32_t ComputedTimingFunction::Compare(
167167
return 0;
168168
}
169169

170-
void ComputedTimingFunction::AppendToString(nsAString& aResult) const {
170+
void ComputedTimingFunction::AppendToString(nsACString& aResult) const {
171171
nsTimingFunction timing;
172172
switch (mType) {
173173
case Type::CubicBezier:

dom/animation/ComputedTimingFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ComputedTimingFunction {
9494
return !(*this == aOther);
9595
}
9696
int32_t Compare(const ComputedTimingFunction& aRhs) const;
97-
void AppendToString(nsAString& aResult) const;
97+
void AppendToString(nsACString& aResult) const;
9898

9999
static double GetPortion(const Maybe<ComputedTimingFunction>& aFunction,
100100
double aPortion, BeforeFlag aBeforeFlag) {

dom/animation/KeyframeEffect.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,12 +1037,11 @@ void DumpAnimationProperties(
10371037
for (auto& p : aAnimationProperties) {
10381038
printf("%s\n", nsCString(nsCSSProps::GetStringValue(p.mProperty)).get());
10391039
for (auto& s : p.mSegments) {
1040-
nsString fromValue, toValue;
1040+
nsAutoCString fromValue, toValue;
10411041
s.mFromValue.SerializeSpecifiedValue(p.mProperty, aRawSet, fromValue);
10421042
s.mToValue.SerializeSpecifiedValue(p.mProperty, aRawSet, toValue);
1043-
printf(" %f..%f: %s..%s\n", s.mFromKey, s.mToKey,
1044-
NS_ConvertUTF16toUTF8(fromValue).get(),
1045-
NS_ConvertUTF16toUTF8(toValue).get());
1043+
printf(" %f..%f: %s..%s\n", s.mFromKey, s.mToKey, fromValue.get(),
1044+
toValue.get());
10461045
}
10471046
}
10481047
}
@@ -1131,7 +1130,7 @@ static void CreatePropertyValue(
11311130
aResult.mOffset = aOffset;
11321131

11331132
if (!aValue.IsNull()) {
1134-
nsString stringValue;
1133+
nsAutoCString stringValue;
11351134
aValue.SerializeSpecifiedValue(aProperty, aRawSet, stringValue);
11361135
aResult.mValue.Construct(stringValue);
11371136
}
@@ -1140,7 +1139,7 @@ static void CreatePropertyValue(
11401139
aResult.mEasing.Construct();
11411140
aTimingFunction->AppendToString(aResult.mEasing.Value());
11421141
} else {
1143-
aResult.mEasing.Construct(u"linear"_ns);
1142+
aResult.mEasing.Construct("linear"_ns);
11441143
}
11451144

11461145
aResult.mComposite = aComposite;
@@ -1298,7 +1297,7 @@ void KeyframeEffect::GetKeyframes(JSContext* aCx, nsTArray<JSObject*>& aResult,
12981297

12991298
JS::Rooted<JSObject*> keyframeObject(aCx, &keyframeJSValue.toObject());
13001299
for (const PropertyValuePair& propertyValue : keyframe.mPropertyValues) {
1301-
nsAutoString stringValue;
1300+
nsAutoCString stringValue;
13021301
// Don't serialize the custom properties for this keyframe.
13031302
if (propertyValue.mProperty ==
13041303
nsCSSPropertyID::eCSSPropertyExtra_variable) {
@@ -1338,7 +1337,7 @@ void KeyframeEffect::GetKeyframes(JSContext* aCx, nsTArray<JSObject*>& aResult,
13381337
}
13391338

13401339
JS::Rooted<JS::Value> value(aCx);
1341-
if (!ToJSValue(aCx, stringValue, &value) ||
1340+
if (!NonVoidUTF8StringToJsval(aCx, stringValue, &value) ||
13421341
!JS_DefineProperty(aCx, keyframeObject, name, value,
13431342
JSPROP_ENUMERATE)) {
13441343
aRv.Throw(NS_ERROR_FAILURE);

dom/animation/KeyframeUtils.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ enum class ListAllowance { eDisallow, eAllow };
6060
*/
6161
struct PropertyValuesPair {
6262
nsCSSPropertyID mProperty;
63-
nsTArray<nsString> mValues;
63+
nsTArray<nsCString> mValues;
6464
};
6565

6666
/**
@@ -153,13 +153,13 @@ static bool GetPropertyValuesPairs(JSContext* aCx,
153153
static bool AppendStringOrStringSequenceToArray(JSContext* aCx,
154154
JS::Handle<JS::Value> aValue,
155155
ListAllowance aAllowLists,
156-
nsTArray<nsString>& aValues);
156+
nsTArray<nsCString>& aValues);
157157

158-
static bool AppendValueAsString(JSContext* aCx, nsTArray<nsString>& aValues,
158+
static bool AppendValueAsString(JSContext* aCx, nsTArray<nsCString>& aValues,
159159
JS::Handle<JS::Value> aValue);
160160

161161
static Maybe<PropertyValuePair> MakePropertyValuePair(
162-
nsCSSPropertyID aProperty, const nsAString& aStringValue,
162+
nsCSSPropertyID aProperty, const nsACString& aStringValue,
163163
dom::Document* aDocument);
164164

165165
static bool HasValidOffsets(const nsTArray<Keyframe>& aKeyframes);
@@ -574,7 +574,7 @@ static bool GetPropertyValuesPairs(JSContext* aCx,
574574
static bool AppendStringOrStringSequenceToArray(JSContext* aCx,
575575
JS::Handle<JS::Value> aValue,
576576
ListAllowance aAllowLists,
577-
nsTArray<nsString>& aValues) {
577+
nsTArray<nsCString>& aValues) {
578578
if (aAllowLists == ListAllowance::eAllow && aValue.isObject()) {
579579
// The value is an object, and we want to allow lists; convert
580580
// aValue to (DOMString or sequence<DOMString>).
@@ -613,17 +613,17 @@ static bool AppendStringOrStringSequenceToArray(JSContext* aCx,
613613
/**
614614
* Converts aValue to DOMString and appends it to aValues.
615615
*/
616-
static bool AppendValueAsString(JSContext* aCx, nsTArray<nsString>& aValues,
616+
static bool AppendValueAsString(JSContext* aCx, nsTArray<nsCString>& aValues,
617617
JS::Handle<JS::Value> aValue) {
618618
return ConvertJSValueToString(aCx, aValue, dom::eStringify, dom::eStringify,
619619
*aValues.AppendElement());
620620
}
621621

622622
static void ReportInvalidPropertyValueToConsole(
623-
nsCSSPropertyID aProperty, const nsAString& aInvalidPropertyValue,
623+
nsCSSPropertyID aProperty, const nsACString& aInvalidPropertyValue,
624624
dom::Document* aDoc) {
625625
AutoTArray<nsString, 2> params;
626-
params.AppendElement(aInvalidPropertyValue);
626+
params.AppendElement(NS_ConvertUTF8toUTF16(aInvalidPropertyValue));
627627
CopyASCIItoUTF16(nsCSSProps::GetStringValue(aProperty),
628628
*params.AppendElement());
629629
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "Animation"_ns,
@@ -642,7 +642,7 @@ static void ReportInvalidPropertyValueToConsole(
642642
* an invalid property value.
643643
*/
644644
static Maybe<PropertyValuePair> MakePropertyValuePair(
645-
nsCSSPropertyID aProperty, const nsAString& aStringValue,
645+
nsCSSPropertyID aProperty, const nsACString& aStringValue,
646646
dom::Document* aDocument) {
647647
MOZ_ASSERT(aDocument);
648648
Maybe<PropertyValuePair> result;
@@ -1017,7 +1017,7 @@ static void GetKeyframeListFromPropertyIndexedKeyframe(
10171017
size_t n = pair.mValues.Length() - 1;
10181018
size_t i = 0;
10191019

1020-
for (const nsString& stringValue : pair.mValues) {
1020+
for (const nsCString& stringValue : pair.mValues) {
10211021
// For single-valued lists, the single value should be added to a
10221022
// keyframe with offset 1.
10231023
double offset = n ? i++ / double(n) : 1;
@@ -1097,7 +1097,7 @@ static void GetKeyframeListFromPropertyIndexedKeyframe(
10971097
// This corresponds to step 5, "Otherwise," branch, substeps 7-11 of
10981098
// https://drafts.csswg.org/web-animations/#processing-a-keyframes-argument
10991099
FallibleTArray<Maybe<ComputedTimingFunction>> easings;
1100-
auto parseAndAppendEasing = [&](const nsString& easingString,
1100+
auto parseAndAppendEasing = [&](const nsACString& easingString,
11011101
ErrorResult& aRv) {
11021102
auto easing = TimingParams::ParseEasing(easingString, aRv);
11031103
if (!aRv.Failed() && !easings.AppendElement(std::move(easing), fallible)) {
@@ -1106,14 +1106,14 @@ static void GetKeyframeListFromPropertyIndexedKeyframe(
11061106
};
11071107

11081108
auto& easing = keyframeDict.mEasing;
1109-
if (easing.IsString()) {
1110-
parseAndAppendEasing(easing.GetAsString(), aRv);
1109+
if (easing.IsUTF8String()) {
1110+
parseAndAppendEasing(easing.GetAsUTF8String(), aRv);
11111111
if (aRv.Failed()) {
11121112
aResult.Clear();
11131113
return;
11141114
}
11151115
} else {
1116-
for (const nsString& easingString : easing.GetAsStringSequence()) {
1116+
for (const auto& easingString : easing.GetAsUTF8StringSequence()) {
11171117
parseAndAppendEasing(easingString, aRv);
11181118
if (aRv.Failed()) {
11191119
aResult.Clear();

dom/animation/TimingParams.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,10 @@ TimingParams TimingParams::MergeOptionalEffectTiming(
190190

191191
/* static */
192192
Maybe<ComputedTimingFunction> TimingParams::ParseEasing(
193-
const nsAString& aEasing, ErrorResult& aRv) {
193+
const nsACString& aEasing, ErrorResult& aRv) {
194194
nsTimingFunction timingFunction;
195195
if (!ServoCSSParser::ParseEasing(aEasing, timingFunction)) {
196-
aRv.ThrowTypeError<dom::MSG_INVALID_EASING_ERROR>(
197-
NS_ConvertUTF16toUTF8(aEasing));
196+
aRv.ThrowTypeError<dom::MSG_INVALID_EASING_ERROR>(aEasing);
198197
return Nothing();
199198
}
200199

dom/animation/TimingParams.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct TimingParams {
119119
}
120120
}
121121

122-
static Maybe<ComputedTimingFunction> ParseEasing(const nsAString& aEasing,
122+
static Maybe<ComputedTimingFunction> ParseEasing(const nsACString& aEasing,
123123
ErrorResult& aRv);
124124

125125
static StickyTimeDuration CalcActiveDuration(

dom/base/AnonymousContent.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ bool AnonymousContent::WrapObject(JSContext* aCx,
179179

180180
void AnonymousContent::GetComputedStylePropertyValue(
181181
const nsAString& aElementId, const nsACString& aPropertyName,
182-
DOMString& aResult, ErrorResult& aRv) {
182+
nsACString& aResult, ErrorResult& aRv) {
183183
Element* element = GetElementById(aElementId);
184184
if (!element) {
185185
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
@@ -215,7 +215,7 @@ void AnonymousContent::SetStyle(const nsACString& aProperty,
215215

216216
nsGenericHTMLElement* element = nsGenericHTMLElement::FromNode(mContentNode);
217217
nsCOMPtr<nsICSSDeclaration> declaration = element->Style();
218-
declaration->SetProperty(aProperty, aValue, u""_ns, IgnoreErrors());
218+
declaration->SetProperty(aProperty, aValue, ""_ns, IgnoreErrors());
219219
}
220220

221221
} // namespace mozilla::dom

dom/base/AnonymousContent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class AnonymousContent final {
7575

7676
void GetComputedStylePropertyValue(const nsAString& aElementId,
7777
const nsACString& aPropertyName,
78-
DOMString& aResult, ErrorResult& aRv);
78+
nsACString& aResult, ErrorResult& aRv);
7979

8080
void GetTargetIdForEvent(Event& aEvent, DOMString& aResult);
8181

0 commit comments

Comments
 (0)