Bug 1338086 - Remove useless else blocks in order to reduce complexity in xpcom/ r?froydnj draft
authorSylvestre Ledru <sledru@mozilla.com>
Thu, 09 Feb 2017 15:31:35 +0100
changeset 484421 11f027ebdc903f87ac9f0ca746111af21ccc8a91
parent 484420 b991eaa5b121d8dcd126c92ad36bf32ca127d222
child 484422 2d9c852ea9d35af340d32b784025fbe5d8939d27
push id45470
push userbmo:sledru@mozilla.com
push dateWed, 15 Feb 2017 08:57:47 +0000
reviewersfroydnj
bugs1338086
milestone54.0a1
Bug 1338086 - Remove useless else blocks in order to reduce complexity in xpcom/ r?froydnj MozReview-Commit-ID: JUJARn5Nspp
xpcom/build/FileLocation.cpp
xpcom/glue/nsStringAPI.cpp
xpcom/io/nsLocalFileUnix.cpp
xpcom/reflect/xptcall/md/unix/xptcstubs_x86_64_linux.cpp
--- a/xpcom/build/FileLocation.cpp
+++ b/xpcom/build/FileLocation.cpp
@@ -177,17 +177,17 @@ FileLocation::Data::GetSize(uint32_t* aR
 
     if (fileInfo.size > int64_t(UINT32_MAX)) {
       return NS_ERROR_FILE_TOO_BIG;
     }
 
     *aResult = fileInfo.size;
     return NS_OK;
   }
-  else if (mItem) {
+  if (mItem) {
     *aResult = mItem->RealSize();
     return NS_OK;
   }
   return NS_ERROR_NOT_INITIALIZED;
 }
 
 nsresult
 FileLocation::Data::Copy(char* aBuf, uint32_t aLen)
@@ -198,17 +198,17 @@ FileLocation::Data::Copy(char* aBuf, uin
                              XPCOM_MIN(aLen - totalRead, uint32_t(INT32_MAX)));
       if (read < 0) {
         return NS_ErrorAccordingToNSPR();
       }
       totalRead += read;
     }
     return NS_OK;
   }
-  else if (mItem) {
+  if (mItem) {
     nsZipCursor cursor(mItem, mZip, reinterpret_cast<uint8_t*>(aBuf),
                        aLen, true);
     uint32_t readLen;
     cursor.Copy(&readLen);
     if (readLen != aLen) {
       nsZipArchive::sFileCorruptedReason = "FileLocation::Data: insufficient data";
       return NS_ERROR_FILE_CORRUPTED;
     }
--- a/xpcom/glue/nsStringAPI.cpp
+++ b/xpcom/glue/nsStringAPI.cpp
@@ -214,17 +214,18 @@ nsAString::Compare(const char_type* aOth
   uint32_t selflen = NS_StringGetData(*this, &cself);
   uint32_t otherlen = NS_strlen(aOther);
   uint32_t comparelen = selflen <= otherlen ? selflen : otherlen;
 
   int32_t result = aComparator(cself, aOther, comparelen);
   if (result == 0) {
     if (selflen < otherlen) {
       return -1;
-    } else if (selflen > otherlen) {
+    }
+    if (selflen > otherlen) {
       return 1;
     }
   }
   return result;
 }
 
 int32_t
 nsAString::Compare(const self_type& aOther, ComparatorFunc aComparator) const
@@ -234,17 +235,18 @@ nsAString::Compare(const self_type& aOth
   uint32_t selflen = NS_StringGetData(*this, &cself);
   uint32_t otherlen = NS_StringGetData(aOther, &cother);
   uint32_t comparelen = selflen <= otherlen ? selflen : otherlen;
 
   int32_t result = aComparator(cself, cother, comparelen);
   if (result == 0) {
     if (selflen < otherlen) {
       return -1;
-    } else if (selflen > otherlen) {
+    }
+    if (selflen > otherlen) {
       return 1;
     }
   }
   return result;
 }
 
 bool
 nsAString::Equals(const char_type* aOther, ComparatorFunc aComparator) const
@@ -753,17 +755,18 @@ nsACString::Compare(const char_type* aOt
   uint32_t selflen = NS_CStringGetData(*this, &cself);
   uint32_t otherlen = strlen(aOther);
   uint32_t comparelen = selflen <= otherlen ? selflen : otherlen;
 
   int32_t result = aComparator(cself, aOther, comparelen);
   if (result == 0) {
     if (selflen < otherlen) {
       return -1;
-    } else if (selflen > otherlen) {
+    }
+    if (selflen > otherlen) {
       return 1;
     }
   }
   return result;
 }
 
 int32_t
 nsACString::Compare(const self_type& aOther, ComparatorFunc aComparator) const
@@ -773,17 +776,18 @@ nsACString::Compare(const self_type& aOt
   uint32_t selflen = NS_CStringGetData(*this, &cself);
   uint32_t otherlen = NS_CStringGetData(aOther, &cother);
   uint32_t comparelen = selflen <= otherlen ? selflen : otherlen;
 
   int32_t result = aComparator(cself, cother, comparelen);
   if (result == 0) {
     if (selflen < otherlen) {
       return -1;
-    } else if (selflen > otherlen) {
+    }
+    if (selflen > otherlen) {
       return 1;
     }
   }
   return result;
 }
 
 bool
 nsACString::Equals(const char_type* aOther, ComparatorFunc aComparator) const
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -956,23 +956,22 @@ nsLocalFile::CopyToNative(nsIFile* aNewP
 #endif
     }
 
     // Let us report the failure to write and read.
     // check for write/read error after cleaning up
     if (bytesRead < 0) {
       if (saved_write_error != NS_OK) {
         return saved_write_error;
-      } else if (saved_read_error != NS_OK) {
+      }
+      if (saved_read_error != NS_OK) {
         return saved_read_error;
       }
 #if DEBUG
-      else {              // sanity check. Die and debug.
-        MOZ_ASSERT(0);
-      }
+      MOZ_ASSERT(0);
 #endif
     }
 
     if (saved_write_close_error != NS_OK) {
       return saved_write_close_error;
     }
     if (saved_read_close_error != NS_OK) {
       return saved_read_close_error;
@@ -1960,30 +1959,30 @@ nsLocalFile::Reveal()
 
   bool isDirectory;
   if (NS_FAILED(IsDirectory(&isDirectory))) {
     return NS_ERROR_FAILURE;
   }
 
   if (isDirectory) {
     return giovfs->ShowURIForInput(mPath);
-  } else if (NS_SUCCEEDED(giovfs->OrgFreedesktopFileManager1ShowItems(mPath))) {
+  }
+  if (NS_SUCCEEDED(giovfs->OrgFreedesktopFileManager1ShowItems(mPath))) {
     return NS_OK;
-  } else {
-    nsCOMPtr<nsIFile> parentDir;
-    nsAutoCString dirPath;
-    if (NS_FAILED(GetParent(getter_AddRefs(parentDir)))) {
-      return NS_ERROR_FAILURE;
-    }
-    if (NS_FAILED(parentDir->GetNativePath(dirPath))) {
-      return NS_ERROR_FAILURE;
-    }
-
-    return giovfs->ShowURIForInput(dirPath);
+  }
+  nsCOMPtr<nsIFile> parentDir;
+  nsAutoCString dirPath;
+  if (NS_FAILED(GetParent(getter_AddRefs(parentDir)))) {
+    return NS_ERROR_FAILURE;
   }
+  if (NS_FAILED(parentDir->GetNativePath(dirPath))) {
+    return NS_ERROR_FAILURE;
+  }
+
+  return giovfs->ShowURIForInput(dirPath);
 #elif defined(MOZ_WIDGET_COCOA)
   CFURLRef url;
   if (NS_SUCCEEDED(GetCFURL(&url))) {
     nsresult rv = CocoaFileUtils::RevealFileInFinder(url);
     ::CFRelease(url);
     return rv;
   }
   return NS_ERROR_FAILURE;
--- a/xpcom/reflect/xptcall/md/unix/xptcstubs_x86_64_linux.cpp
+++ b/xpcom/reflect/xptcall/md/unix/xptcstubs_x86_64_linux.cpp
@@ -64,40 +64,38 @@ PrepareAndDispatch(nsXPTCStubBase * self
     uint32_t nr_gpr = 1;    // skip one GPR register for 'that'
     uint32_t nr_fpr = 0;
     uint64_t value;
 
     for (i = 0; i < paramCount; i++) {
         const nsXPTParamInfo& param = info->GetParam(i);
         const nsXPTType& type = param.GetType();
         nsXPTCMiniVariant* dp = &dispatchParams[i];
-	
+
         if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
             if (nr_fpr < FPR_COUNT)
                 dp->val.d = fpregs[nr_fpr++];
             else
-                dp->val.d = *(double*) ap++;
+                dp->val.d = *(double*)ap++;
             continue;
         }
-        else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
+        if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
             if (nr_fpr < FPR_COUNT)
                 // The value in %xmm register is already prepared to
                 // be retrieved as a float. Therefore, we pass the
                 // value verbatim, as a double without conversion.
                 dp->val.d = fpregs[nr_fpr++];
             else
-                dp->val.f = *(float*) ap++;
+                dp->val.f = *(float*)ap++;
             continue;
         }
-        else {
-            if (nr_gpr < GPR_COUNT)
-                value = gpregs[nr_gpr++];
-            else
-                value = *ap++;
-        }
+        if (nr_gpr < GPR_COUNT)
+            value = gpregs[nr_gpr++];
+        else
+            value = *ap++;
 
         if (param.IsOut() || !type.IsArithmetic()) {
             dp->val.p = (void*) value;
             continue;
         }
 
         switch (type) {
         case nsXPTType::T_I8:      dp->val.i8  = (int8_t)   value; break;