Use SVGLength-references in the SVGLengthContext API
Convert all the PassRefPtrWillBeRawPtr<SVGLength>-typed arguments to
const SVGLength&. This avoids unnecessary ref-count churn (the caller will
always own a reference anyway). As a side-effect footprint is reduced by
~2k. (resolveRectangle<T> can now be properly inlined and other methods
shrink a bit.)
Review URL: https://codereview.chromium.org/921823002
git-svn-id: svn://svn.chromium.org/blink/trunk@190070 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourceLinearGradient.cpp b/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourceLinearGradient.cpp
index 837e462..1c54159 100644
--- a/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourceLinearGradient.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourceLinearGradient.cpp
@@ -50,12 +50,12 @@
FloatPoint LayoutSVGResourceLinearGradient::startPoint(const LinearGradientAttributes& attributes) const
{
- return SVGLengthContext::resolvePoint(element(), attributes.gradientUnits(), attributes.x1(), attributes.y1());
+ return SVGLengthContext::resolvePoint(element(), attributes.gradientUnits(), *attributes.x1(), *attributes.y1());
}
FloatPoint LayoutSVGResourceLinearGradient::endPoint(const LinearGradientAttributes& attributes) const
{
- return SVGLengthContext::resolvePoint(element(), attributes.gradientUnits(), attributes.x2(), attributes.y2());
+ return SVGLengthContext::resolvePoint(element(), attributes.gradientUnits(), *attributes.x2(), *attributes.y2());
}
void LayoutSVGResourceLinearGradient::buildGradient(GradientData* gradientData) const
diff --git a/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourcePattern.cpp b/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourcePattern.cpp
index 527eda2..23ad0b7 100644
--- a/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourcePattern.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourcePattern.cpp
@@ -93,7 +93,7 @@
FloatRect clientBoundingBox = object.objectBoundingBox();
FloatRect tileBounds = SVGLengthContext::resolveRectangle(element(),
attributes.patternUnits(), clientBoundingBox,
- attributes.x(), attributes.y(), attributes.width(), attributes.height());
+ *attributes.x(), *attributes.y(), *attributes.width(), *attributes.height());
if (tileBounds.isEmpty())
return nullptr;
diff --git a/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourceRadialGradient.cpp b/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourceRadialGradient.cpp
index d16461f7..3725146 100644
--- a/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourceRadialGradient.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/LayoutSVGResourceRadialGradient.cpp
@@ -51,22 +51,22 @@
FloatPoint LayoutSVGResourceRadialGradient::centerPoint(const RadialGradientAttributes& attributes) const
{
- return SVGLengthContext::resolvePoint(element(), attributes.gradientUnits(), attributes.cx(), attributes.cy());
+ return SVGLengthContext::resolvePoint(element(), attributes.gradientUnits(), *attributes.cx(), *attributes.cy());
}
FloatPoint LayoutSVGResourceRadialGradient::focalPoint(const RadialGradientAttributes& attributes) const
{
- return SVGLengthContext::resolvePoint(element(), attributes.gradientUnits(), attributes.fx(), attributes.fy());
+ return SVGLengthContext::resolvePoint(element(), attributes.gradientUnits(), *attributes.fx(), *attributes.fy());
}
float LayoutSVGResourceRadialGradient::radius(const RadialGradientAttributes& attributes) const
{
- return SVGLengthContext::resolveLength(element(), attributes.gradientUnits(), attributes.r());
+ return SVGLengthContext::resolveLength(element(), attributes.gradientUnits(), *attributes.r());
}
float LayoutSVGResourceRadialGradient::focalRadius(const RadialGradientAttributes& attributes) const
{
- return SVGLengthContext::resolveLength(element(), attributes.gradientUnits(), attributes.fr());
+ return SVGLengthContext::resolveLength(element(), attributes.gradientUnits(), *attributes.fr());
}
void LayoutSVGResourceRadialGradient::buildGradient(GradientData* gradientData) const
diff --git a/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp b/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp
index 447df21..8f51cf5 100644
--- a/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp
@@ -36,54 +36,44 @@
{
}
-FloatRect SVGLengthContext::resolveRectangle(const SVGElement* context, SVGUnitTypes::SVGUnitType type, const FloatRect& viewport, PassRefPtrWillBeRawPtr<SVGLength> passX, PassRefPtrWillBeRawPtr<SVGLength> passY, PassRefPtrWillBeRawPtr<SVGLength> passWidth, PassRefPtrWillBeRawPtr<SVGLength> passHeight)
+FloatRect SVGLengthContext::resolveRectangle(const SVGElement* context, SVGUnitTypes::SVGUnitType type, const FloatRect& viewport, const SVGLength& x, const SVGLength& y, const SVGLength& width, const SVGLength& height)
{
- RefPtrWillBeRawPtr<SVGLength> x = passX;
- RefPtrWillBeRawPtr<SVGLength> y = passY;
- RefPtrWillBeRawPtr<SVGLength> width = passWidth;
- RefPtrWillBeRawPtr<SVGLength> height = passHeight;
-
ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN);
if (type != SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE && !viewport.isEmpty()) {
const FloatSize& viewportSize = viewport.size();
return FloatRect(
- convertValueFromPercentageToUserUnits(*x, viewportSize) + viewport.x(),
- convertValueFromPercentageToUserUnits(*y, viewportSize) + viewport.y(),
- convertValueFromPercentageToUserUnits(*width, viewportSize),
- convertValueFromPercentageToUserUnits(*height, viewportSize));
+ convertValueFromPercentageToUserUnits(x, viewportSize) + viewport.x(),
+ convertValueFromPercentageToUserUnits(y, viewportSize) + viewport.y(),
+ convertValueFromPercentageToUserUnits(width, viewportSize),
+ convertValueFromPercentageToUserUnits(height, viewportSize));
}
SVGLengthContext lengthContext(context);
- return FloatRect(x->value(lengthContext), y->value(lengthContext), width->value(lengthContext), height->value(lengthContext));
+ return FloatRect(x.value(lengthContext), y.value(lengthContext), width.value(lengthContext), height.value(lengthContext));
}
-FloatPoint SVGLengthContext::resolvePoint(const SVGElement* context, SVGUnitTypes::SVGUnitType type, PassRefPtrWillBeRawPtr<SVGLength> passX, PassRefPtrWillBeRawPtr<SVGLength> passY)
+FloatPoint SVGLengthContext::resolvePoint(const SVGElement* context, SVGUnitTypes::SVGUnitType type, const SVGLength& x, const SVGLength& y)
{
- RefPtrWillBeRawPtr<SVGLength> x = passX;
- RefPtrWillBeRawPtr<SVGLength> y = passY;
-
ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN);
if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) {
SVGLengthContext lengthContext(context);
- return FloatPoint(x->value(lengthContext), y->value(lengthContext));
+ return FloatPoint(x.value(lengthContext), y.value(lengthContext));
}
// FIXME: valueAsPercentage() won't be correct for eg. cm units. They need to be resolved in user space and then be considered in objectBoundingBox space.
- return FloatPoint(x->valueAsPercentage(), y->valueAsPercentage());
+ return FloatPoint(x.valueAsPercentage(), y.valueAsPercentage());
}
-float SVGLengthContext::resolveLength(const SVGElement* context, SVGUnitTypes::SVGUnitType type, PassRefPtrWillBeRawPtr<SVGLength> passX)
+float SVGLengthContext::resolveLength(const SVGElement* context, SVGUnitTypes::SVGUnitType type, const SVGLength& x)
{
- RefPtrWillBeRawPtr<SVGLength> x = passX;
-
ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN);
if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) {
SVGLengthContext lengthContext(context);
- return x->value(lengthContext);
+ return x.value(lengthContext);
}
// FIXME: valueAsPercentage() won't be correct for eg. cm units. They need to be resolved in user space and then be considered in objectBoundingBox space.
- return x->valueAsPercentage();
+ return x.valueAsPercentage();
}
float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const
diff --git a/third_party/WebKit/Source/core/svg/SVGLengthContext.h b/third_party/WebKit/Source/core/svg/SVGLengthContext.h
index a1be724..699367f 100644
--- a/third_party/WebKit/Source/core/svg/SVGLengthContext.h
+++ b/third_party/WebKit/Source/core/svg/SVGLengthContext.h
@@ -56,12 +56,12 @@
template<typename T>
static FloatRect resolveRectangle(const T* context, SVGUnitTypes::SVGUnitType type, const FloatRect& viewport)
{
- return resolveRectangle(context, type, viewport, context->x()->currentValue(), context->y()->currentValue(), context->width()->currentValue(), context->height()->currentValue());
+ return resolveRectangle(context, type, viewport, *context->x()->currentValue(), *context->y()->currentValue(), *context->width()->currentValue(), *context->height()->currentValue());
}
- static FloatRect resolveRectangle(const SVGElement*, SVGUnitTypes::SVGUnitType, const FloatRect& viewport, PassRefPtrWillBeRawPtr<SVGLength> x, PassRefPtrWillBeRawPtr<SVGLength> y, PassRefPtrWillBeRawPtr<SVGLength> width, PassRefPtrWillBeRawPtr<SVGLength> height);
- static FloatPoint resolvePoint(const SVGElement*, SVGUnitTypes::SVGUnitType, PassRefPtrWillBeRawPtr<SVGLength> x, PassRefPtrWillBeRawPtr<SVGLength> y);
- static float resolveLength(const SVGElement*, SVGUnitTypes::SVGUnitType, PassRefPtrWillBeRawPtr<SVGLength>);
+ static FloatRect resolveRectangle(const SVGElement*, SVGUnitTypes::SVGUnitType, const FloatRect& viewport, const SVGLength& x, const SVGLength& y, const SVGLength& width, const SVGLength& height);
+ static FloatPoint resolvePoint(const SVGElement*, SVGUnitTypes::SVGUnitType, const SVGLength& x, const SVGLength& y);
+ static float resolveLength(const SVGElement*, SVGUnitTypes::SVGUnitType, const SVGLength&);
float convertValueToUserUnits(float, SVGLengthMode, SVGLengthType fromUnit) const;
float convertValueFromUserUnits(float, SVGLengthMode, SVGLengthType toUnit) const;