Commit 91fc0c8c authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Use a singleton CSSParserContext in SVGLength::SetValueAsString

Creating this object for each call represents a significant part of the
entire function. Using a singleton instead reduces the runtime of the
testcase "usingSetAttribute" from the referenced bug's comment #5 by
around 20% locally.

Bug: 978513
Change-Id: I5d3447baf04706e2c23da4ed07cb0197d0349ac7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1681766Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#673325}
parent 73436e9f
......@@ -179,6 +179,21 @@ float SVGLength::ScaleByPercentage(float input) const {
return result;
}
namespace {
const CSSParserContext* GetSVGAttributeParserContext() {
// NOTE(ikilpatrick): We will always parse SVG lengths in the insecure
// context mode. If a function/unit/etc will require a secure context check
// in the future, plumbing will need to be added.
DEFINE_STATIC_LOCAL(
const Persistent<CSSParserContext>, svg_parser_context,
(MakeGarbageCollected<CSSParserContext>(
kSVGAttributeMode, SecureContextMode::kInsecureContext)));
return svg_parser_context;
}
} // namespace
SVGParsingError SVGLength::SetValueAsString(const String& string) {
// TODO(fs): Preferably we wouldn't need to special-case the null
// string (which we'll get for example for removeAttribute.)
......@@ -189,13 +204,8 @@ SVGParsingError SVGLength::SetValueAsString(const String& string) {
return SVGParseStatus::kNoError;
}
// NOTE(ikilpatrick): We will always parse svg lengths in the insecure
// context mode. If a function/unit/etc will require a secure context check
// in the future, plumbing will need to be added.
auto* svg_parser_context = MakeGarbageCollected<CSSParserContext>(
kSVGAttributeMode, SecureContextMode::kInsecureContext);
const CSSValue* parsed = CSSParser::ParseSingleValue(
CSSPropertyID::kX, string, svg_parser_context);
CSSPropertyID::kX, string, GetSVGAttributeParserContext());
const auto* new_value = DynamicTo<CSSPrimitiveValue>(parsed);
if (!new_value)
return SVGParseStatus::kExpectedLength;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment