Bug 785017 - Use NS_GetStaticAtom in svg content where appropriate. r=dholbert
authorRobert Longson <longsonr@gmail.com>
Fri, 24 Aug 2012 08:29:09 +0100
changeset 103266 8e3e0ae18274c9576e694d335f23591233d6658c
parent 103265 008a58e4a33889b6d5aef891d91a2220585a1ef9
child 103267 950379788e3365fb8bfdb06e4db3da42b3c8c625
push id13907
push userlongsonr@gmail.com
push dateFri, 24 Aug 2012 07:29:22 +0000
treeherdermozilla-inbound@8e3e0ae18274 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs785017
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 785017 - Use NS_GetStaticAtom in svg content where appropriate. r=dholbert
content/svg/content/src/SVGLength.cpp
content/svg/content/src/nsSVGAngle.cpp
content/svg/content/src/nsSVGElement.cpp
content/svg/content/src/nsSVGEnum.cpp
content/svg/content/src/nsSVGLength2.cpp
--- a/content/svg/content/src/SVGLength.cpp
+++ b/content/svg/content/src/SVGLength.cpp
@@ -14,17 +14,17 @@
 #include "prdtoa.h"
 #include "nsMathUtils.h"
 #include <limits>
 
 namespace mozilla {
 
 // Declare some helpers defined below:
 static void GetUnitString(nsAString& unit, uint16_t unitType);
-static uint16_t GetUnitTypeForString(const char* unitStr);
+static uint16_t GetUnitTypeForString(const nsAString& unitStr);
 
 void
 SVGLength::GetValueAsString(nsAString &aValue) const
 {
   PRUnichar buf[24];
   nsTextFormatter::snprintf(buf, sizeof(buf)/sizeof(PRUnichar),
                             NS_LITERAL_STRING("%g").get(),
                             (double)mValue);
@@ -46,28 +46,24 @@ SVGLength::SetValueFromString(const nsAS
 
   while (*str != '\0' && IsSVGWhitespace(*str)) {
     ++str;
   }
   char *unit;
   tmpValue = float(PR_strtod(str, &unit));
   if (unit != str && NS_finite(tmpValue)) {
     char *theRest = unit;
-    if (*unit != '\0' && !IsSVGWhitespace(*unit)) {
-      while (*theRest != '\0' && !IsSVGWhitespace(*theRest)) {
-        ++theRest;
-      }
-      nsCAutoString unitStr(unit, theRest - unit);
-      tmpUnit = GetUnitTypeForString(unitStr.get());
-      if (tmpUnit == nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN) {
-        // nsSVGUtils::ReportToConsole
-        return false;
-      }
-    } else {
-      tmpUnit = nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER;
+    while (*theRest != '\0' && !IsSVGWhitespace(*theRest)) {
+      ++theRest;
+    }
+    tmpUnit = GetUnitTypeForString(
+                Substring(aValue, unit - str, theRest - unit));
+    if (tmpUnit == nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN) {
+      // nsSVGUtils::ReportToConsole
+      return false;
     }
     while (*theRest && IsSVGWhitespace(*theRest)) {
       ++theRest;
     }
     if (!*theRest) {
       mValue = tmpValue;
       mUnit = tmpUnit;
       return true;
@@ -230,24 +226,26 @@ GetUnitString(nsAString& unit, uint16_t 
     }
     return;
   }
   NS_NOTREACHED("Unknown unit type"); // Someone's using an SVGLength with an invalid unit?
   return;
 }
 
 static uint16_t
-GetUnitTypeForString(const char* unitStr)
+GetUnitTypeForString(const nsAString& unitStr)
 {
-  if (!unitStr || *unitStr == '\0')
+  if (unitStr.IsEmpty())
     return nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER;
 
-  nsCOMPtr<nsIAtom> unitAtom = do_GetAtom(unitStr);
+  nsIAtom* unitAtom = NS_GetStaticAtom(unitStr);
 
-  for (uint32_t i = 1 ; i < ArrayLength(unitMap) ; i++) {
-    if (unitMap[i] && *unitMap[i] == unitAtom) {
-      return i;
+  if (unitAtom) {
+    for (uint32_t i = 1 ; i < ArrayLength(unitMap) ; i++) {
+      if (unitMap[i] && *unitMap[i] == unitAtom) {
+        return i;
+      }
     }
   }
   return nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN;
 }
 
 } // namespace mozilla
--- a/content/svg/content/src/nsSVGAngle.cpp
+++ b/content/svg/content/src/nsSVGAngle.cpp
@@ -149,26 +149,28 @@ GetUnitString(nsAString& unit, uint16_t 
     return;
   }
 
   NS_NOTREACHED("Unknown unit type");
   return;
 }
 
 static uint16_t
-GetUnitTypeForString(const char* unitStr)
+GetUnitTypeForString(const nsAString& unitStr)
 {
-  if (!unitStr || *unitStr == '\0') 
+  if (unitStr.IsEmpty()) 
     return nsIDOMSVGAngle::SVG_ANGLETYPE_UNSPECIFIED;
                    
-  nsCOMPtr<nsIAtom> unitAtom = do_GetAtom(unitStr);
+  nsIAtom *unitAtom = NS_GetStaticAtom(unitStr);
 
-  for (uint32_t i = 0 ; i < ArrayLength(unitMap) ; i++) {
-    if (unitMap[i] && *unitMap[i] == unitAtom) {
-      return i;
+  if (unitAtom) {
+    for (uint32_t i = 0 ; i < ArrayLength(unitMap) ; i++) {
+      if (unitMap[i] && *unitMap[i] == unitAtom) {
+        return i;
+      }
     }
   }
 
   return nsIDOMSVGAngle::SVG_ANGLETYPE_UNKNOWN;
 }
 
 static void
 GetValueString(nsAString &aValueAsString, float aValue, uint16_t aUnitType)
@@ -193,17 +195,18 @@ GetValueFromString(const nsAString &aVal
   const char *str = value.get();
 
   if (NS_IsAsciiWhitespace(*str))
     return NS_ERROR_DOM_SYNTAX_ERR;
   
   char *rest;
   *aValue = float(PR_strtod(str, &rest));
   if (rest != str && NS_finite(*aValue)) {
-    *aUnitType = GetUnitTypeForString(rest);
+    *aUnitType = GetUnitTypeForString(
+      Substring(aValueAsString, rest - str));
     if (IsValidUnitType(*aUnitType)) {
       return NS_OK;
     }
   }
   
   return NS_ERROR_DOM_SYNTAX_ERR;
 }
 
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -450,18 +450,19 @@ nsSVGElement::ParseAttribute(int32_t aNa
       }
     }
 
     if (!foundMatch) {
       // Check for nsSVGBoolean attribute
       BooleanAttributesInfo booleanInfo = GetBooleanInfo();
       for (i = 0; i < booleanInfo.mBooleanCount; i++) {
         if (aAttribute == *booleanInfo.mBooleanInfo[i].mName) {
-          nsCOMPtr<nsIAtom> valAtom = do_GetAtom(aValue);
-          rv = booleanInfo.mBooleans[i].SetBaseValueAtom(valAtom, this);
+          nsIAtom *valAtom = NS_GetStaticAtom(aValue);
+          rv = valAtom ? booleanInfo.mBooleans[i].SetBaseValueAtom(valAtom, this) :
+                 NS_ERROR_DOM_SYNTAX_ERR;
           if (NS_FAILED(rv)) {
             booleanInfo.Reset(i);
           } else {
             aResult.SetTo(valAtom);
             didSetResult = true;
           }
           foundMatch = true;
           break;
--- a/content/svg/content/src/nsSVGEnum.cpp
+++ b/content/svg/content/src/nsSVGEnum.cpp
@@ -137,28 +137,30 @@ nsSVGEnum::ToSMILAttr(nsSVGElement *aSVG
 }
 
 nsresult
 nsSVGEnum::SMILEnum::ValueFromString(const nsAString& aStr,
                                      const nsISMILAnimationElement* /*aSrcElement*/,
                                      nsSMILValue& aValue,
                                      bool& aPreventCachingOfSandwich) const
 {
-  nsCOMPtr<nsIAtom> valAtom = do_GetAtom(aStr);
-  nsSVGEnumMapping *mapping = mVal->GetMapping(mSVGElement);
+  nsIAtom *valAtom = NS_GetStaticAtom(aStr);
+  if (valAtom) {
+    nsSVGEnumMapping *mapping = mVal->GetMapping(mSVGElement);
 
-  while (mapping && mapping->mKey) {
-    if (valAtom == *(mapping->mKey)) {
-      nsSMILValue val(&SMILEnumType::sSingleton);
-      val.mU.mUint = mapping->mVal;
-      aValue = val;
-      aPreventCachingOfSandwich = false;
-      return NS_OK;
+    while (mapping && mapping->mKey) {
+      if (valAtom == *(mapping->mKey)) {
+        nsSMILValue val(&SMILEnumType::sSingleton);
+        val.mU.mUint = mapping->mVal;
+        aValue = val;
+        aPreventCachingOfSandwich = false;
+        return NS_OK;
+      }
+      mapping++;
     }
-    mapping++;
   }
   
   // only a warning since authors may mistype attribute values
   NS_WARNING("unknown enumeration key");
   return NS_ERROR_FAILURE;
 }
 
 nsSMILValue
--- a/content/svg/content/src/nsSVGLength2.cpp
+++ b/content/svg/content/src/nsSVGLength2.cpp
@@ -97,26 +97,27 @@ GetUnitString(nsAString& unit, uint16_t 
     return;
   }
 
   NS_NOTREACHED("Unknown unit type");
   return;
 }
 
 static uint16_t
-GetUnitTypeForString(const char* unitStr)
+GetUnitTypeForString(const nsAString& unitStr)
 {
-  if (!unitStr || *unitStr == '\0') 
+  if (unitStr.IsEmpty()) 
     return nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER;
                    
-  nsCOMPtr<nsIAtom> unitAtom = do_GetAtom(unitStr);
-
-  for (uint32_t i = 0 ; i < ArrayLength(unitMap) ; i++) {
-    if (unitMap[i] && *unitMap[i] == unitAtom) {
-      return i;
+  nsIAtom *unitAtom = NS_GetStaticAtom(unitStr);
+  if (unitAtom) {
+    for (uint32_t i = 0 ; i < ArrayLength(unitMap) ; i++) {
+      if (unitMap[i] && *unitMap[i] == unitAtom) {
+        return i;
+      }
     }
   }
 
   return nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN;
 }
 
 static void
 GetValueString(nsAString &aValueAsString, float aValue, uint16_t aUnitType)
@@ -141,17 +142,18 @@ GetValueFromString(const nsAString &aVal
   const char *str = value.get();
 
   if (NS_IsAsciiWhitespace(*str))
     return NS_ERROR_DOM_SYNTAX_ERR;
   
   char *rest;
   *aValue = float(PR_strtod(str, &rest));
   if (rest != str && NS_finite(*aValue)) {
-    *aUnitType = GetUnitTypeForString(rest);
+    *aUnitType = GetUnitTypeForString(
+      Substring(aValueAsString, rest - str));
     if (IsValidUnitType(*aUnitType)) {
       return NS_OK;
     }
   }
   
   return NS_ERROR_DOM_SYNTAX_ERR;
 }