Bug 1424120 - Part 8: clang-format ToInteger. r=njn
authorEric Rahm <erahm@mozilla.com>
Fri, 08 Dec 2017 11:43:15 -0800
changeset 448700 dcd1da3793f1315e1c55c1123253992dfd957587
parent 448699 293bc5e35a4fa69c6a68f9542d3e6daa624a5926
child 448701 c28dfb7efe2f38b0e0ae4743e4d50a732a2ec698
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1424120
milestone59.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 1424120 - Part 8: clang-format ToInteger. r=njn
xpcom/string/nsTStringObsolete.cpp
--- a/xpcom/string/nsTStringObsolete.cpp
+++ b/xpcom/string/nsTStringObsolete.cpp
@@ -107,119 +107,117 @@ nsTString<T>::RFindCharInSet(const char_
   else
     ++aOffset;
 
   return ::RFindCharInSet(this->mData, aOffset, aSet);
 }
 
 
 // Common logic for nsTString<T>::ToIntger and nsTString<T>::ToInteger64.
-template <typename T, typename int_type>
+template<typename T, typename int_type>
 int_type
-ToIntegerCommon(const nsTString<T>& aSrc,
-                nsresult* aErrorCode, uint32_t aRadix)
+ToIntegerCommon(const nsTString<T>& aSrc, nsresult* aErrorCode, uint32_t aRadix)
 {
   MOZ_ASSERT(aRadix == 10 || aRadix == 16);
 
   using char_type = typename nsTString<T>::char_type;
 
   auto cp = aSrc.BeginReading();
   mozilla::CheckedInt<int_type> result;
   bool negate = false;
   char_type theChar = 0;
 
-  //initial value, override if we find an integer
-  *aErrorCode=NS_ERROR_ILLEGAL_VALUE;
+  // initial value, override if we find an integer
+  *aErrorCode = NS_ERROR_ILLEGAL_VALUE;
 
-  //begin by skipping over leading chars that shouldn't be part of the number...
+  // begin by skipping over leading chars that shouldn't be part of the
+  // number...
 
-  auto endcp=aSrc.EndReading();
-  bool done=false;
+  auto endcp = aSrc.EndReading();
+  bool done = false;
 
   // NB: For backwards compatibility I'm not going to change this logic but
   //     it seems really odd. Previously there was logic to auto-detect the
   //     radix if kAutoDetect was passed in. In practice this value was never
   //     used, so it pretended to auto detect and skipped some preceding
   //     letters (excluding valid hex digits) but never used the result.
   //
   //     For example if you pass in "Get the number: 10", aRadix = 10 we'd
   //     skip the 'G', and then fail to parse "et the number: 10". If aRadix =
   //     16 we'd skip the 'G', and parse just 'e' returning 14.
-  while((cp<endcp) && (!done)){
-    switch(*cp++) {
+  while ((cp < endcp) && (!done)) {
+    switch (*cp++) {
+      // clang-format off
       case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
       case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
       case '0': case '1': case '2': case '3': case '4':
       case '5': case '6': case '7': case '8': case '9':
-        done=true;
+        done = true;
         break;
+      // clang-format on
       case '-':
-        negate=true; //fall through...
+        negate = true; // fall through...
         break;
       default:
         break;
-    } //switch
+    } // switch
   }
 
   if (!done) {
     // No base 16 or base 10 digits were found.
     return 0;
   }
 
   // Step back.
   cp--;
 
-  //integer found
+  // integer found
   *aErrorCode = NS_OK;
 
-  //now iterate the numeric chars and build our result
-  while(cp<endcp){
-    theChar=*cp++;
-    if(('0'<=theChar) && (theChar<='9')){
-      result = (aRadix * result) + (theChar-'0');
-    }
-    else if((theChar>='A') && (theChar<='F')) {
-      if(10==aRadix) {
-        *aErrorCode=NS_ERROR_ILLEGAL_VALUE;
-        result=0;
+  // now iterate the numeric chars and build our result
+  while (cp < endcp) {
+    theChar = *cp++;
+    if (('0' <= theChar) && (theChar <= '9')) {
+      result = (aRadix * result) + (theChar - '0');
+    } else if ((theChar >= 'A') && (theChar <= 'F')) {
+      if (10 == aRadix) {
+        *aErrorCode = NS_ERROR_ILLEGAL_VALUE;
+        result = 0;
         break;
+      } else {
+        result = (aRadix * result) + ((theChar - 'A') + 10);
       }
-      else {
-        result = (aRadix * result) + ((theChar-'A')+10);
+    } else if ((theChar >= 'a') && (theChar <= 'f')) {
+      if (10 == aRadix) {
+        *aErrorCode = NS_ERROR_ILLEGAL_VALUE;
+        result = 0;
+        break;
+      } else {
+        result = (aRadix * result) + ((theChar - 'a') + 10);
       }
-    }
-    else if((theChar>='a') && (theChar<='f')) {
-      if(10==aRadix) {
-        *aErrorCode=NS_ERROR_ILLEGAL_VALUE;
-        result=0;
-        break;
-      }
-      else {
-        result = (aRadix * result) + ((theChar-'a')+10);
-      }
-    }
-    else if((('X'==theChar) || ('x'==theChar)) && result == 0) {
+    } else if ((('X' == theChar) || ('x' == theChar)) && result == 0) {
       // For some reason we support a leading 'x' regardless of radix. For
       // example: "000000x500", aRadix = 10 would be parsed as 500 rather
       // than 0.
       continue;
-    }
-    else {
-      //we've encountered a char that's not a legal number or sign
+    } else {
+      // we've encountered a char that's not a legal number or sign
       break;
     }
 
     if (!result.isValid()) {
       // overflow!
       *aErrorCode = NS_ERROR_ILLEGAL_VALUE;
       return 0;
     }
-  } //while
-  if(negate)
-    result=-result;
+  } // while
+
+  if (negate) {
+    result = -result;
+  }
 
   return result.value();
 }
 
 
 template <typename T>
 int32_t
 nsTString<T>::ToInteger(nsresult* aErrorCode, uint32_t aRadix) const