Bug 567283 patch 1 - Convert if enclosing most of function into early return. r?xidorn draft
authorL. David Baron <dbaron@dbaron.org>
Sun, 08 May 2016 09:56:14 -0700
changeset 364683 262380dfb6f8ceb35225bc9a81d59c7408fe3b03
parent 364682 bae525a694e2dc0aa433885be8751330d4995a49
child 364684 a9743d4e625c3c0d7fb9637efff35f37ddc1e24f
push id17539
push userdbaron@mozilla.com
push dateSun, 08 May 2016 16:56:29 +0000
reviewersxidorn
bugs567283
milestone49.0a1
Bug 567283 patch 1 - Convert if enclosing most of function into early return. r?xidorn This conversion just reindents most of the function, but it then avoids having indentation changes in patch 2. MozReview-Commit-ID: A5unK4grJ47
gfx/src/nsColor.cpp
--- a/gfx/src/nsColor.cpp
+++ b/gfx/src/nsColor.cpp
@@ -75,52 +75,52 @@ static int ComponentValue(const char16_t
   return component;
 }
 
 bool NS_HexToRGB(const nsAString& aColorSpec, nscolor* aResult)
 {
   const char16_t* buffer = aColorSpec.BeginReading();
 
   int nameLen = aColorSpec.Length();
-  if ((nameLen == 3) || (nameLen == 6)) {
-    // Make sure the digits are legal
-    for (int i = 0; i < nameLen; i++) {
-      char16_t ch = buffer[i];
-      if (((ch >= '0') && (ch <= '9')) ||
-          ((ch >= 'a') && (ch <= 'f')) ||
-          ((ch >= 'A') && (ch <= 'F'))) {
-        // Legal character
-        continue;
-      }
-      // Whoops. Illegal character.
-      return false;
-    }
+  if (nameLen != 3 && nameLen != 6) {
+    // Improperly formatted color value
+    return false;
+  }
 
-    // Convert the ascii to binary
-    int dpc = ((3 == nameLen) ? 1 : 2);
-    // Translate components from hex to binary
-    int r = ComponentValue(buffer, nameLen, 0, dpc);
-    int g = ComponentValue(buffer, nameLen, 1, dpc);
-    int b = ComponentValue(buffer, nameLen, 2, dpc);
-    if (dpc == 1) {
-      // Scale single digit component to an 8 bit value. Replicate the
-      // single digit to compute the new value.
-      r = (r << 4) | r;
-      g = (g << 4) | g;
-      b = (b << 4) | b;
+  // Make sure the digits are legal
+  for (int i = 0; i < nameLen; i++) {
+    char16_t ch = buffer[i];
+    if (((ch >= '0') && (ch <= '9')) ||
+        ((ch >= 'a') && (ch <= 'f')) ||
+        ((ch >= 'A') && (ch <= 'F'))) {
+      // Legal character
+      continue;
     }
-    NS_ASSERTION((r >= 0) && (r <= 255), "bad r");
-    NS_ASSERTION((g >= 0) && (g <= 255), "bad g");
-    NS_ASSERTION((b >= 0) && (b <= 255), "bad b");
-    *aResult = NS_RGB(r, g, b);
-    return true;
+    // Whoops. Illegal character.
+    return false;
   }
 
-  // Improperly formatted color value
-  return false;
+  // Convert the ascii to binary
+  int dpc = ((3 == nameLen) ? 1 : 2);
+  // Translate components from hex to binary
+  int r = ComponentValue(buffer, nameLen, 0, dpc);
+  int g = ComponentValue(buffer, nameLen, 1, dpc);
+  int b = ComponentValue(buffer, nameLen, 2, dpc);
+  if (dpc == 1) {
+    // Scale single digit component to an 8 bit value. Replicate the
+    // single digit to compute the new value.
+    r = (r << 4) | r;
+    g = (g << 4) | g;
+    b = (b << 4) | b;
+  }
+  NS_ASSERTION((r >= 0) && (r <= 255), "bad r");
+  NS_ASSERTION((g >= 0) && (g <= 255), "bad g");
+  NS_ASSERTION((b >= 0) && (b <= 255), "bad b");
+  *aResult = NS_RGB(r, g, b);
+  return true;
 }
 
 // This implements part of the algorithm for legacy behavior described in
 // http://www.whatwg.org/specs/web-apps/current-work/complete/common-microsyntaxes.html#rules-for-parsing-a-legacy-color-value
 bool NS_LooseHexToRGB(const nsString& aColorSpec, nscolor* aResult)
 {
   if (aColorSpec.EqualsLiteral("transparent")) {
     return false;