Bug 1449883 - Use `const nsStaticAtom* const` instead of `nsStaticAtom**` in some SVG .cpp files. r=jwatt draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 03 Apr 2018 17:29:37 +1000
changeset 776498 abe717038847e73db56ab4db06ff7613a95f6959
parent 776497 72ba90cf84bba6f272324dc947693eef0ea6eeca
push id104891
push usernnethercote@mozilla.com
push dateTue, 03 Apr 2018 07:30:23 +0000
reviewersjwatt
bugs1449883
milestone61.0a1
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
dom/svg/SVGLength.cpp
dom/svg/nsSVGAngle.cpp
dom/svg/nsSVGLength2.cpp
--- 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;
 }