mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1346610 - Compute width and height only when necessary to avoid exponential time complexity r=longsonr
When only width is needed, we should not compute height, and vice versa. Otherwise there are exponentially repeated computations for nested svg elements, which will make the tab unresponsive due to 100% CPU usage for exponentially long time. Differential Revision: https://phabricator.services.mozilla.com/D20947 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
e84d7f028b
commit
6756284172
@ -205,19 +205,32 @@ float SVGViewportElement::GetLength(uint8_t aCtxType) {
|
||||
? &GetViewBoxInternal().GetAnimValue()
|
||||
: nullptr;
|
||||
|
||||
float h, w;
|
||||
float h = 0.0f, w = 0.0f;
|
||||
bool shouldComputeWidth =
|
||||
(aCtxType == SVGContentUtils::X || aCtxType == SVGContentUtils::XY),
|
||||
shouldComputeHeight =
|
||||
(aCtxType == SVGContentUtils::Y || aCtxType == SVGContentUtils::XY);
|
||||
|
||||
if (viewbox) {
|
||||
w = viewbox->width;
|
||||
h = viewbox->height;
|
||||
} else if (IsInner()) {
|
||||
SVGViewportElement* ctx = GetCtx();
|
||||
w = mLengthAttributes[ATTR_WIDTH].GetAnimValue(ctx);
|
||||
h = mLengthAttributes[ATTR_HEIGHT].GetAnimValue(ctx);
|
||||
if (shouldComputeWidth) {
|
||||
w = mLengthAttributes[ATTR_WIDTH].GetAnimValue(ctx);
|
||||
}
|
||||
if (shouldComputeHeight) {
|
||||
h = mLengthAttributes[ATTR_HEIGHT].GetAnimValue(ctx);
|
||||
}
|
||||
} else if (ShouldSynthesizeViewBox()) {
|
||||
w = ComputeSynthesizedViewBoxDimension(mLengthAttributes[ATTR_WIDTH],
|
||||
mViewportWidth, this);
|
||||
h = ComputeSynthesizedViewBoxDimension(mLengthAttributes[ATTR_HEIGHT],
|
||||
mViewportHeight, this);
|
||||
if (shouldComputeWidth) {
|
||||
w = ComputeSynthesizedViewBoxDimension(mLengthAttributes[ATTR_WIDTH],
|
||||
mViewportWidth, this);
|
||||
}
|
||||
if (shouldComputeHeight) {
|
||||
h = ComputeSynthesizedViewBoxDimension(mLengthAttributes[ATTR_HEIGHT],
|
||||
mViewportHeight, this);
|
||||
}
|
||||
} else {
|
||||
w = mViewportWidth;
|
||||
h = mViewportHeight;
|
||||
|
@ -91,3 +91,4 @@ load 1477853.html
|
||||
load 1486488.html
|
||||
load 1493447.html
|
||||
skip-if(Android) load 1507961-1.html # times out on Android due to the test size
|
||||
load test_nested_svg.html
|
||||
|
63
dom/svg/crashtests/test_nested_svg.html
Normal file
63
dom/svg/crashtests/test_nested_svg.html
Normal file
@ -0,0 +1,63 @@
|
||||
<!-- if not handled properly, this file will cause 100% CPU for exponentially long time -->
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
||||
<svg>
|
After Width: | Height: | Size: 464 B |
Loading…
Reference in New Issue
Block a user