Bug 1449883 - Use `const nsStaticAtom* const` instead of `nsStaticAtom**` in some SVG .cpp files. r=jwatt
The patch also removes some conditional tests involving unitMap[i] that are
now redundant due to preceding null tests against unitAtom.
MozReview-Commit-ID: CJpktlS4k15
--- a/dom/svg/SVGLength.cpp
+++ b/dom/svg/SVGLength.cpp
@@ -181,54 +181,54 @@ SVGLength::GetUserUnitsPerPercent(const
}
}
return std::numeric_limits<float>::quiet_NaN();
}
// Helpers:
// These items must be at the same index as the SVGLength constants!
-static nsStaticAtom** const unitMap[] =
+static const nsStaticAtom* const unitMap[] =
{
nullptr, /* SVG_LENGTHTYPE_UNKNOWN */
nullptr, /* SVG_LENGTHTYPE_NUMBER */
- &nsGkAtoms::percentage,
- &nsGkAtoms::em,
- &nsGkAtoms::ex,
- &nsGkAtoms::px,
- &nsGkAtoms::cm,
- &nsGkAtoms::mm,
- &nsGkAtoms::in,
- &nsGkAtoms::pt,
- &nsGkAtoms::pc
+ nsGkAtoms::percentage,
+ nsGkAtoms::em,
+ nsGkAtoms::ex,
+ nsGkAtoms::px,
+ nsGkAtoms::cm,
+ nsGkAtoms::mm,
+ nsGkAtoms::in,
+ nsGkAtoms::pt,
+ nsGkAtoms::pc
};
static void
GetUnitString(nsAString& unit, uint16_t unitType)
{
if (SVGLength::IsValidUnitType(unitType)) {
if (unitMap[unitType]) {
- (*unitMap[unitType])->ToString(unit);
+ unitMap[unitType]->ToString(unit);
}
return;
}
NS_NOTREACHED("Unknown unit type"); // Someone's using an SVGLength with an invalid unit?
}
static uint16_t
GetUnitTypeForString(const nsAString& unitStr)
{
if (unitStr.IsEmpty())
return SVGLengthBinding::SVG_LENGTHTYPE_NUMBER;
nsAtom* unitAtom = NS_GetStaticAtom(unitStr);
if (unitAtom) {
for (uint32_t i = 1 ; i < ArrayLength(unitMap) ; i++) {
- if (unitMap[i] && *unitMap[i] == unitAtom) {
+ if (unitMap[i] == unitAtom) {
return i;
}
}
}
return SVGLengthBinding::SVG_LENGTHTYPE_UNKNOWN;
}
} // namespace mozilla
--- a/dom/svg/nsSVGAngle.cpp
+++ b/dom/svg/nsSVGAngle.cpp
@@ -17,23 +17,23 @@
#include "SVGAnimatedAngle.h"
#include "SVGOrientSMILType.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::dom::SVGAngleBinding;
using namespace mozilla::dom::SVGMarkerElementBinding;
-static nsStaticAtom** const unitMap[] =
+static const nsStaticAtom* const unitMap[] =
{
nullptr, /* SVG_ANGLETYPE_UNKNOWN */
nullptr, /* SVG_ANGLETYPE_UNSPECIFIED */
- &nsGkAtoms::deg,
- &nsGkAtoms::rad,
- &nsGkAtoms::grad
+ nsGkAtoms::deg,
+ nsGkAtoms::rad,
+ nsGkAtoms::grad
};
static nsSVGAttrTearoffTable<nsSVGAngle, SVGAnimatedAngle>
sSVGAnimatedAngleTearoffTable;
static nsSVGAttrTearoffTable<nsSVGAngle, SVGAngle>
sBaseSVGAngleTearoffTable;
static nsSVGAttrTearoffTable<nsSVGAngle, SVGAngle>
sAnimSVGAngleTearoffTable;
@@ -50,17 +50,17 @@ IsValidUnitType(uint16_t unit)
return false;
}
static void
GetUnitString(nsAString& unit, uint16_t unitType)
{
if (IsValidUnitType(unitType)) {
if (unitMap[unitType]) {
- (*unitMap[unitType])->ToString(unit);
+ unitMap[unitType]->ToString(unit);
}
return;
}
NS_NOTREACHED("Unknown unit type");
}
static uint16_t
@@ -68,17 +68,17 @@ GetUnitTypeForString(const nsAString& un
{
if (unitStr.IsEmpty())
return SVG_ANGLETYPE_UNSPECIFIED;
nsStaticAtom* unitAtom = NS_GetStaticAtom(unitStr);
if (unitAtom) {
for (uint32_t i = 0 ; i < ArrayLength(unitMap) ; i++) {
- if (unitMap[i] && *unitMap[i] == unitAtom) {
+ if (unitMap[i] == unitAtom) {
return i;
}
}
}
return SVG_ANGLETYPE_UNKNOWN;
}
--- a/dom/svg/nsSVGLength2.cpp
+++ b/dom/svg/nsSVGLength2.cpp
@@ -17,29 +17,29 @@
#include "nsSVGIntegrationUtils.h"
#include "nsTextFormatter.h"
#include "DOMSVGLength.h"
#include "LayoutLogging.h"
using namespace mozilla;
using namespace mozilla::dom;
-static nsStaticAtom** const unitMap[] =
+static const nsStaticAtom* const unitMap[] =
{
nullptr, /* SVG_LENGTHTYPE_UNKNOWN */
nullptr, /* SVG_LENGTHTYPE_NUMBER */
- &nsGkAtoms::percentage,
- &nsGkAtoms::em,
- &nsGkAtoms::ex,
- &nsGkAtoms::px,
- &nsGkAtoms::cm,
- &nsGkAtoms::mm,
- &nsGkAtoms::in,
- &nsGkAtoms::pt,
- &nsGkAtoms::pc
+ nsGkAtoms::percentage,
+ nsGkAtoms::em,
+ nsGkAtoms::ex,
+ nsGkAtoms::px,
+ nsGkAtoms::cm,
+ nsGkAtoms::mm,
+ nsGkAtoms::in,
+ nsGkAtoms::pt,
+ nsGkAtoms::pc
};
static nsSVGAttrTearoffTable<nsSVGLength2, SVGAnimatedLength>
sSVGAnimatedLengthTearoffTable;
/* Helper functions */
static bool
@@ -52,34 +52,34 @@ IsValidUnitType(uint16_t unit)
return false;
}
static void
GetUnitString(nsAString& unit, uint16_t unitType)
{
if (IsValidUnitType(unitType)) {
if (unitMap[unitType]) {
- (*unitMap[unitType])->ToString(unit);
+ unitMap[unitType]->ToString(unit);
}
return;
}
NS_NOTREACHED("Unknown unit type");
}
static uint16_t
GetUnitTypeForString(const nsAString& unitStr)
{
if (unitStr.IsEmpty())
return SVGLengthBinding::SVG_LENGTHTYPE_NUMBER;
nsAtom *unitAtom = NS_GetStaticAtom(unitStr);
if (unitAtom) {
for (uint32_t i = 0 ; i < ArrayLength(unitMap) ; i++) {
- if (unitMap[i] && *unitMap[i] == unitAtom) {
+ if (unitMap[i] == unitAtom) {
return i;
}
}
}
return SVGLengthBinding::SVG_LENGTHTYPE_UNKNOWN;
}