Bug 1179451 - Part 1: Rewrite some ternary operators as if/else. r=froydnj
authorAryeh Gregor <ayg@aryeh.name>
Thu, 13 Aug 2015 15:22:48 +0300
changeset 292141 1c0791d5bce7381fe18dae8428fca50d52774499
parent 292140 0c0847dc7dfbe73fe3775dab5ed599bb0dd4af3e
child 292142 1b6f0c5df0e4689df9557037ad70753785151e93
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1179451
milestone43.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 1179451 - Part 1: Rewrite some ternary operators as if/else. r=froydnj
accessible/base/AccIterator.cpp
accessible/html/HTMLFormControlAccessible.cpp
docshell/base/nsDocShell.cpp
dom/base/FileList.h
dom/base/nsGenericDOMDataNode.cpp
dom/base/nsMimeTypeArray.cpp
dom/base/nsPluginArray.cpp
dom/bluetooth/bluetooth2/BluetoothManager.cpp
dom/events/PaintRequest.h
dom/events/TextComposition.cpp
dom/media/MediaTrackList.cpp
dom/media/TextTrackCueList.cpp
dom/media/TextTrackList.cpp
dom/media/mediasource/SourceBufferList.cpp
layout/forms/nsRangeFrame.cpp
--- a/accessible/base/AccIterator.cpp
+++ b/accessible/base/AccIterator.cpp
@@ -391,17 +391,20 @@ ARIAOwnsIterator::Next()
 // SingleAccIterator
 ////////////////////////////////////////////////////////////////////////////////
 
 Accessible*
 SingleAccIterator::Next()
 {
   nsRefPtr<Accessible> nextAcc;
   mAcc.swap(nextAcc);
-  return (nextAcc && !nextAcc->IsDefunct()) ? nextAcc : nullptr;
+  if (!nextAcc || nextAcc->IsDefunct()) {
+    return nullptr;
+  }
+  return nextAcc;
 }
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // ItemIterator
 ////////////////////////////////////////////////////////////////////////////////
 
 Accessible*
--- a/accessible/html/HTMLFormControlAccessible.cpp
+++ b/accessible/html/HTMLFormControlAccessible.cpp
@@ -481,17 +481,20 @@ bool
 HTMLTextFieldAccessible::IsWidget() const
 {
   return true;
 }
 
 Accessible*
 HTMLTextFieldAccessible::ContainerWidget() const
 {
-  return mParent && mParent->Role() == roles::AUTOCOMPLETE ? mParent : nullptr;
+  if (!mParent || mParent->Role() != roles::AUTOCOMPLETE) {
+    return nullptr;
+  }
+  return mParent;
 }
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // HTMLFileInputAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
 HTMLFileInputAccessible::
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -4333,17 +4333,20 @@ nsDocShell::GetDocument()
 {
   NS_ENSURE_SUCCESS(EnsureContentViewer(), nullptr);
   return mContentViewer->GetDocument();
 }
 
 nsPIDOMWindow*
 nsDocShell::GetWindow()
 {
-  return NS_SUCCEEDED(EnsureScriptEnvironment()) ? mScriptGlobal : nullptr;
+  if (NS_FAILED(EnsureScriptEnvironment())) {
+    return nullptr;
+  }
+  return mScriptGlobal;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetDeviceSizeIsPageSize(bool aValue)
 {
   if (mDeviceSizeIsPageSize != aValue) {
     mDeviceSizeIsPageSize = aValue;
     nsRefPtr<nsPresContext> presContext;
--- a/dom/base/FileList.h
+++ b/dom/base/FileList.h
@@ -79,17 +79,20 @@ public:
   File* Item(uint32_t aIndex)
   {
     return mFiles.SafeElementAt(aIndex);
   }
 
   File* IndexedGetter(uint32_t aIndex, bool& aFound)
   {
     aFound = aIndex < mFiles.Length();
-    return aFound ? mFiles.ElementAt(aIndex) : nullptr;
+    if (!aFound) {
+      return nullptr;
+    }
+    return mFiles.ElementAt(aIndex);
   }
 
   uint32_t Length()
   {
     return mFiles.Length();
   }
 
 private:
--- a/dom/base/nsGenericDOMDataNode.cpp
+++ b/dom/base/nsGenericDOMDataNode.cpp
@@ -691,17 +691,20 @@ nsGenericDOMDataNode::GetShadowRoot() co
 {
   return nullptr;
 }
 
 ShadowRoot *
 nsGenericDOMDataNode::GetContainingShadow() const
 {
   nsDataSlots *slots = GetExistingDataSlots();
-  return slots ? slots->mContainingShadow : nullptr;
+  if (!slots) {
+    return nullptr;
+  }
+  return slots->mContainingShadow;
 }
 
 void
 nsGenericDOMDataNode::SetShadowRoot(ShadowRoot* aShadowRoot)
 {
 }
 
 nsTArray<nsIContent*>&
--- a/dom/base/nsMimeTypeArray.cpp
+++ b/dom/base/nsMimeTypeArray.cpp
@@ -259,18 +259,20 @@ void
 nsMimeType::GetDescription(nsString& aRetval) const
 {
   aRetval = mDescription;
 }
 
 nsPluginElement*
 nsMimeType::GetEnabledPlugin() const
 {
-  return (mPluginElement && mPluginElement->PluginTag()->IsEnabled()) ?
-    mPluginElement : nullptr;
+  if (!mPluginElement || !mPluginElement->PluginTag()->IsEnabled()) {
+    return nullptr;
+  }
+  return mPluginElement;
 }
 
 void
 nsMimeType::GetSuffixes(nsString& aRetval) const
 {
   aRetval = mExtension;
 }
 
--- a/dom/base/nsPluginArray.cpp
+++ b/dom/base/nsPluginArray.cpp
@@ -170,17 +170,21 @@ nsPluginArray::IndexedGetter(uint32_t aI
   if (!AllowPlugins()) {
     return nullptr;
   }
 
   EnsurePlugins();
 
   aFound = aIndex < mPlugins.Length();
 
-  return aFound ? mPlugins[aIndex] : nullptr;
+  if (!aFound) {
+    return nullptr;
+  }
+
+  return mPlugins[aIndex];
 }
 
 void
 nsPluginArray::Invalidate()
 {
   nsCOMPtr<nsIObserverService> obsService =
     mozilla::services::GetObserverService();
   if (obsService) {
@@ -386,17 +390,21 @@ nsPluginElement::NamedItem(const nsAStri
 
 nsMimeType*
 nsPluginElement::IndexedGetter(uint32_t aIndex, bool &aFound)
 {
   EnsurePluginMimeTypes();
 
   aFound = aIndex < mMimeTypes.Length();
 
-  return aFound ? mMimeTypes[aIndex] : nullptr;
+  if (!aFound) {
+    return nullptr;
+  }
+
+  return mMimeTypes[aIndex];
 }
 
 nsMimeType*
 nsPluginElement::NamedGetter(const nsAString& aName, bool &aFound)
 {
   EnsurePluginMimeTypes();
 
   aFound = false;
--- a/dom/bluetooth/bluetooth2/BluetoothManager.cpp
+++ b/dom/bluetooth/bluetooth2/BluetoothManager.cpp
@@ -132,17 +132,20 @@ BluetoothManager::DisconnectFromOwner()
 {
   DOMEventTargetHelper::DisconnectFromOwner();
   UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_MANAGER), this);
 }
 
 BluetoothAdapter*
 BluetoothManager::GetDefaultAdapter()
 {
-  return DefaultAdapterExists() ? mAdapters[mDefaultAdapterIndex] : nullptr;
+  if (!DefaultAdapterExists()) {
+    return nullptr;
+  }
+  return mAdapters[mDefaultAdapterIndex];
 }
 
 void
 BluetoothManager::AppendAdapter(const BluetoothValue& aValue)
 {
   MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
 
   // Create a new BluetoothAdapter and append it to adapters array
--- a/dom/events/PaintRequest.h
+++ b/dom/events/PaintRequest.h
@@ -84,17 +84,20 @@ public:
 
   PaintRequest* Item(uint32_t aIndex)
   {
     return mArray.SafeElementAt(aIndex);
   }
   PaintRequest* IndexedGetter(uint32_t aIndex, bool& aFound)
   {
     aFound = aIndex < mArray.Length();
-    return aFound ? mArray.ElementAt(aIndex) : nullptr;
+    if (!aFound) {
+      return nullptr;
+    }
+    return mArray.ElementAt(aIndex);
   }
 
 private:
   ~PaintRequestList() {}
 
   nsTArray< nsRefPtr<PaintRequest> > mArray;
   nsCOMPtr<nsIDOMEvent> mParent;
 };
--- a/dom/events/TextComposition.cpp
+++ b/dom/events/TextComposition.cpp
@@ -684,25 +684,31 @@ TextCompositionArray::IndexOf(nsPresCont
   nsINode* node = ElementAt(index)->GetEventTargetNode();
   return node == aNode ? index : NoIndex;
 }
 
 TextComposition*
 TextCompositionArray::GetCompositionFor(nsIWidget* aWidget)
 {
   index_type i = IndexOf(aWidget);
-  return i != NoIndex ? ElementAt(i) : nullptr;
+  if (i == NoIndex) {
+    return nullptr;
+  }
+  return ElementAt(i);
 }
 
 TextComposition*
 TextCompositionArray::GetCompositionFor(nsPresContext* aPresContext,
                                            nsINode* aNode)
 {
   index_type i = IndexOf(aPresContext, aNode);
-  return i != NoIndex ? ElementAt(i) : nullptr;
+  if (i == NoIndex) {
+    return nullptr;
+  }
+  return ElementAt(i);
 }
 
 TextComposition*
 TextCompositionArray::GetCompositionInContent(nsPresContext* aPresContext,
                                               nsIContent* aContent)
 {
   // There should be only one composition per content object.
   for (index_type i = Length(); i > 0; --i) {
--- a/dom/media/MediaTrackList.cpp
+++ b/dom/media/MediaTrackList.cpp
@@ -69,17 +69,20 @@ MediaTrackList::operator[](uint32_t aInd
 {
   return mTracks.ElementAt(aIndex);
 }
 
 MediaTrack*
 MediaTrackList::IndexedGetter(uint32_t aIndex, bool& aFound)
 {
   aFound = aIndex < mTracks.Length();
-  return aFound ? mTracks[aIndex] : nullptr;
+  if (!aFound) {
+    return nullptr;
+  }
+  return mTracks[aIndex];
 }
 
 MediaTrack*
 MediaTrackList::GetTrackById(const nsAString& aId)
 {
   for (uint32_t i = 0; i < mTracks.Length(); ++i) {
     if (aId.Equals(mTracks[i]->GetId())) {
       return mTracks[i];
--- a/dom/media/TextTrackCueList.cpp
+++ b/dom/media/TextTrackCueList.cpp
@@ -45,17 +45,20 @@ TextTrackCueList::WrapObject(JSContext* 
 {
   return TextTrackCueListBinding::Wrap(aCx, this, aGivenProto);
 }
 
 TextTrackCue*
 TextTrackCueList::IndexedGetter(uint32_t aIndex, bool& aFound)
 {
   aFound = aIndex < mList.Length();
-  return aFound ? mList[aIndex] : nullptr;
+  if (!aFound) {
+    return nullptr;
+  }
+  return mList[aIndex];
 }
 
 TextTrackCue*
 TextTrackCueList::operator[](uint32_t aIndex)
 {
   return mList.SafeElementAt(aIndex, nullptr);
 }
 
--- a/dom/media/TextTrackList.cpp
+++ b/dom/media/TextTrackList.cpp
@@ -64,17 +64,20 @@ TextTrackList::WrapObject(JSContext* aCx
 {
   return TextTrackListBinding::Wrap(aCx, this, aGivenProto);
 }
 
 TextTrack*
 TextTrackList::IndexedGetter(uint32_t aIndex, bool& aFound)
 {
   aFound = aIndex < mTextTracks.Length();
-  return aFound ? mTextTracks[aIndex] : nullptr;
+  if (!aFound) {
+    return nullptr;
+  }
+  return mTextTracks[aIndex];
 }
 
 TextTrack*
 TextTrackList::operator[](uint32_t aIndex)
 {
   return mTextTracks.SafeElementAt(aIndex, nullptr);
 }
 
--- a/dom/media/mediasource/SourceBufferList.cpp
+++ b/dom/media/mediasource/SourceBufferList.cpp
@@ -33,17 +33,21 @@ SourceBufferList::~SourceBufferList()
 {
 }
 
 SourceBuffer*
 SourceBufferList::IndexedGetter(uint32_t aIndex, bool& aFound)
 {
   MOZ_ASSERT(NS_IsMainThread());
   aFound = aIndex < mSourceBuffers.Length();
-  return aFound ? mSourceBuffers[aIndex] : nullptr;
+
+  if (!aFound) {
+    return nullptr;
+  }
+  return mSourceBuffers[aIndex];
 }
 
 uint32_t
 SourceBufferList::Length()
 {
   MOZ_ASSERT(NS_IsMainThread());
   return mSourceBuffers.Length();
 }
--- a/layout/forms/nsRangeFrame.cpp
+++ b/layout/forms/nsRangeFrame.cpp
@@ -868,17 +868,20 @@ nsRangeFrame::GetPseudoElement(nsCSSPseu
 }
 
 nsStyleContext*
 nsRangeFrame::GetAdditionalStyleContext(int32_t aIndex) const
 {
   // We only implement this so that SetAdditionalStyleContext will be
   // called if style changes that would change the -moz-focus-outer
   // pseudo-element have occurred.
-  return aIndex == 0 ? mOuterFocusStyle : nullptr;
+  if (aIndex != 0) {
+    return nullptr;
+  }
+  return mOuterFocusStyle;
 }
 
 void
 nsRangeFrame::SetAdditionalStyleContext(int32_t aIndex,
                                         nsStyleContext* aStyleContext)
 {
   MOZ_ASSERT(aIndex == 0,
              "GetAdditionalStyleContext is handling other indexes?");