Bug 705584 - Improve/increase use of nsCharSeparatedTokenizerTemplate in nsSMILParserUtils. r=dholbert
authorRobert Longson <longsonr@gmail.com>
Thu, 05 Sep 2013 13:08:47 +0100
changeset 158634 809ec333407e4a7cf71cbf08252bf89703a67a1c
parent 158633 ba28223861b15de428639cd7f74d77500d8e504c
child 158635 89d4dc9f19d8d4ebe6a8bc7d5210fb71ee40498b
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs705584
milestone26.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 705584 - Improve/increase use of nsCharSeparatedTokenizerTemplate in nsSMILParserUtils. r=dholbert
content/smil/nsSMILParserUtils.cpp
--- a/content/smil/nsSMILParserUtils.cpp
+++ b/content/smil/nsSMILParserUtils.cpp
@@ -469,56 +469,45 @@ nsSMILParserUtils::ParseKeySplines(const
   return rv;
 }
 
 nsresult
 nsSMILParserUtils::ParseSemicolonDelimitedProgressList(const nsAString& aSpec,
                                                        bool aNonDecreasing,
                                                        nsTArray<double>& aArray)
 {
-  nsresult rv = NS_OK;
-
-  NS_ConvertUTF16toUTF8 spec(aSpec);
-  const char* start = spec.BeginReading();
-  const char* end = spec.EndReading();
-
-  SkipBeginWsp(start, end);
+  nsCharSeparatedTokenizerTemplate<IsSpace> tokenizer(aSpec, ';');
 
   double previousValue = -1.0;
 
-  while (start != end) {
-    double value = GetFloat(start, end, &rv);
-    if (NS_FAILED(rv))
-      break;
+  while (tokenizer.hasMoreTokens()) {
+    NS_ConvertUTF16toUTF8 utf8Token(tokenizer.nextToken());
+    const char *token = utf8Token.get();
+    if (*token == '\0') {
+      return NS_ERROR_FAILURE; // empty string (e.g. two ';' in a row)
+    }
+
+    char *end;
+    double value = PR_strtod(token, &end);
+    if (*end != '\0') {
+      return NS_ERROR_FAILURE;
+    }
 
     if (value > 1.0 || value < 0.0 ||
         (aNonDecreasing && value < previousValue)) {
-      rv = NS_ERROR_FAILURE;
-      break;
+      return NS_ERROR_FAILURE;
     }
 
     if (!aArray.AppendElement(value)) {
-      rv = NS_ERROR_OUT_OF_MEMORY;
-      break;
+      return NS_ERROR_OUT_OF_MEMORY;
     }
     previousValue = value;
-
-    SkipBeginWsp(start, end);
-    if (start == end)
-      break;
-
-    if (*start++ != ';') {
-      rv = NS_ERROR_FAILURE;
-      break;
-    }
-
-    SkipBeginWsp(start, end);
   }
 
-  return rv;
+  return NS_OK;
 }
 
 // Helper class for ParseValues
 class SMILValueParser : public nsSMILParserUtils::GenericValueParser
 {
 public:
   SMILValueParser(const SVGAnimationElement* aSrcElement,
                   const nsISMILAttr* aSMILAttr,
@@ -566,17 +555,17 @@ nsSMILParserUtils::ParseValues(const nsA
                               &aValuesArray, &aPreventCachingOfSandwich);
   return ParseValuesGeneric(aSpec, valueParser);
 }
 
 nsresult
 nsSMILParserUtils::ParseValuesGeneric(const nsAString& aSpec,
                                       GenericValueParser& aParser)
 {
-  nsCharSeparatedTokenizer tokenizer(aSpec, ';');
+  nsCharSeparatedTokenizerTemplate<IsSpace> tokenizer(aSpec, ';');
   if (!tokenizer.hasMoreTokens()) { // Empty list
     return NS_ERROR_FAILURE;
   }
 
   while (tokenizer.hasMoreTokens()) {
     nsresult rv = aParser.Parse(tokenizer.nextToken());
     if (NS_FAILED(rv)) {
       return NS_ERROR_FAILURE;