Bug 1217307 - Remove some unnecessary null checks in dom/base/. r=njn
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Thu, 19 Nov 2015 09:13:49 +0200
changeset 309215 66eba1425dbe624d2cbac75affe07a8ffef284a5
parent 309214 699556d95575cdc247a501c5a5a86107b52263ab
child 309216 f05d1adcc902007e5cee15fbda55bfe7fd027276
push id1040
push userraliiev@mozilla.com
push dateMon, 29 Feb 2016 17:11:22 +0000
treeherdermozilla-release@8c3167321162 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1217307
milestone45.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 1217307 - Remove some unnecessary null checks in dom/base/. r=njn
dom/base/FragmentOrElement.cpp
dom/base/nsAttrValue.cpp
dom/base/nsCCUncollectableMarker.cpp
dom/base/nsContentPermissionHelper.cpp
dom/base/nsContentPolicy.cpp
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMWindowUtils.cpp
dom/base/nsDocument.cpp
dom/base/nsDocumentEncoder.cpp
dom/base/nsFocusManager.cpp
dom/base/nsGenConImageContent.cpp
dom/base/nsGenericDOMDataNode.cpp
dom/base/nsGlobalWindowCommands.cpp
dom/base/nsImageLoadingContent.cpp
dom/base/nsNameSpaceManager.cpp
dom/base/nsObjectLoadingContent.cpp
dom/base/nsScriptNameSpaceManager.cpp
dom/base/nsTextFragment.cpp
dom/base/nsTextNode.cpp
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -504,17 +504,16 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsNodeSu
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNodeSupportsWeakRefTearoff)
 
 NS_IMETHODIMP
 nsNodeSupportsWeakRefTearoff::GetWeakReference(nsIWeakReference** aInstancePtr)
 {
   nsINode::nsSlots* slots = mNode->Slots();
   if (!slots->mWeakReference) {
     slots->mWeakReference = new nsNodeWeakReference(mNode);
-    NS_ENSURE_TRUE(slots->mWeakReference, NS_ERROR_OUT_OF_MEMORY);
   }
 
   NS_ADDREF(*aInstancePtr = slots->mWeakReference);
 
   return NS_OK;
 }
 
 //----------------------------------------------------------------------
--- a/dom/base/nsAttrValue.cpp
+++ b/dom/base/nsAttrValue.cpp
@@ -162,20 +162,17 @@ nsAttrValue::~nsAttrValue()
   ResetIfSet();
 }
 
 /* static */
 nsresult
 nsAttrValue::Init()
 {
   NS_ASSERTION(!sEnumTableArray, "nsAttrValue already initialized");
-
   sEnumTableArray = new nsTArray<const EnumTable*>;
-  NS_ENSURE_TRUE(sEnumTableArray, NS_ERROR_OUT_OF_MEMORY);
-  
   return NS_OK;
 }
 
 /* static */
 void
 nsAttrValue::Shutdown()
 {
   delete sEnumTableArray;
@@ -1845,24 +1842,18 @@ bool
 nsAttrValue::EnsureEmptyAtomArray()
 {
   if (Type() == eAtomArray) {
     ResetMiscAtomOrString();
     GetAtomArrayValue()->Clear();
     return true;
   }
 
-  AtomArray* array = new AtomArray;
-  if (!array) {
-    Reset();
-    return false;
-  }
-
   MiscContainer* cont = EnsureEmptyMiscContainer();
-  cont->mValue.mAtomArray = array;
+  cont->mValue.mAtomArray = new AtomArray;
   cont->mType = eAtomArray;
 
   return true;
 }
 
 already_AddRefed<nsStringBuffer>
 nsAttrValue::GetStringBuffer(const nsAString& aValue) const
 {
--- a/dom/base/nsCCUncollectableMarker.cpp
+++ b/dom/base/nsCCUncollectableMarker.cpp
@@ -51,17 +51,16 @@ NS_IMPL_ISUPPORTS(nsCCUncollectableMarke
 nsresult
 nsCCUncollectableMarker::Init()
 {
   if (sInited) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIObserver> marker = new nsCCUncollectableMarker;
-  NS_ENSURE_TRUE(marker, NS_ERROR_OUT_OF_MEMORY);
 
   nsCOMPtr<nsIObserverService> obs =
     mozilla::services::GetObserverService();
   if (!obs)
     return NS_ERROR_FAILURE;
 
   nsresult rv;
 
--- a/dom/base/nsContentPermissionHelper.cpp
+++ b/dom/base/nsContentPermissionHelper.cpp
@@ -146,17 +146,16 @@ ContentPermissionRequestParent::~Content
 {
   MOZ_COUNT_DTOR(ContentPermissionRequestParent);
 }
 
 bool
 ContentPermissionRequestParent::Recvprompt()
 {
   mProxy = new nsContentPermissionRequestProxy();
-  NS_ASSERTION(mProxy, "Alloc of request proxy failed");
   if (NS_FAILED(mProxy->Init(mRequests, this))) {
     mProxy->Cancel();
   }
   return true;
 }
 
 bool
 ContentPermissionRequestParent::RecvNotifyVisibility(const bool& aIsVisible)
--- a/dom/base/nsContentPolicy.cpp
+++ b/dom/base/nsContentPolicy.cpp
@@ -31,18 +31,16 @@ using mozilla::LogLevel;
 NS_IMPL_ISUPPORTS(nsContentPolicy, nsIContentPolicy)
 
 static PRLogModuleInfo* gConPolLog;
 
 nsresult
 NS_NewContentPolicy(nsIContentPolicy **aResult)
 {
   *aResult = new nsContentPolicy;
-  if (!*aResult)
-      return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(*aResult);
   return NS_OK;
 }
 
 nsContentPolicy::nsContentPolicy()
     : mPolicies(NS_CONTENTPOLICY_CATEGORY)
     , mSimplePolicies(NS_SIMPLECONTENTPOLICY_CATEGORY)
 {
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -1406,17 +1406,16 @@ nsDOMConstructor::Create(const char16_t*
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
   bool constructable = aNameStruct ?
                          IsConstructable(aNameStruct) :
                          IsConstructable(aData);
 
   *aResult = new nsDOMConstructor(aName, constructable, currentInner);
-  NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aResult);
   return NS_OK;
 }
 
 NS_IMPL_ADDREF(nsDOMConstructor)
 NS_IMPL_RELEASE(nsDOMConstructor)
 NS_INTERFACE_MAP_BEGIN(nsDOMConstructor)
   NS_INTERFACE_MAP_ENTRY(nsIDOMDOMConstructor)
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -1893,17 +1893,16 @@ nsDOMWindowUtils::SendQueryContentEvent(
       break;
   }
 
   nsEventStatus status;
   nsresult rv = targetWidget->DispatchEvent(&queryEvent, status);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsQueryContentEventResult* result = new nsQueryContentEventResult();
-  NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
   result->SetEventResult(widget, queryEvent);
   NS_ADDREF(*aResult = result);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::SendSelectionSetEvent(uint32_t aOffset,
                                         uint32_t aLength,
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -309,18 +309,16 @@ nsIdentifierMapEntry::AppendAllIdContent
 }
 
 void
 nsIdentifierMapEntry::AddContentChangeCallback(nsIDocument::IDTargetObserver aCallback,
                                                void* aData, bool aForImage)
 {
   if (!mChangeCallbacks) {
     mChangeCallbacks = new nsTHashtable<ChangeCallbackEntry>;
-    if (!mChangeCallbacks)
-      return;
   }
 
   ChangeCallback cc = { aCallback, aData, aForImage };
   mChangeCallbacks->PutEntry(cc);
 }
 
 void
 nsIdentifierMapEntry::RemoveContentChangeCallback(nsIDocument::IDTargetObserver aCallback,
@@ -1242,19 +1240,16 @@ IMPL_SHIM(nsIApplicationCacheContainer)
 #define TRY_SHIM(_i)                                                       \
   PR_BEGIN_MACRO                                                           \
     if (IID_IS(_i)) {                                                      \
       nsCOMPtr<_i> real = do_GetInterface(mCallbacks);                     \
       if (!real) {                                                         \
         return NS_NOINTERFACE;                                             \
       }                                                                    \
       nsCOMPtr<_i> shim = new _i##Shim(this, real);                        \
-      if (!shim) {                                                         \
-        return NS_ERROR_OUT_OF_MEMORY;                                     \
-      }                                                                    \
       shim.forget(aSink);                                                  \
       return NS_OK;                                                        \
     }                                                                      \
   PR_END_MACRO
 
 NS_IMETHODIMP
 nsExternalResourceMap::LoadgroupCallbacks::GetInterface(const nsIID & aIID,
                                                         void **aSink)
@@ -10029,18 +10024,16 @@ nsDocument::SetChangeScrollPosWhenScroll
   mChangeScrollPosWhenScrollingToRef = aValue;
 }
 
 void
 nsIDocument::RegisterActivityObserver(nsISupports* aSupports)
 {
   if (!mActivityObservers) {
     mActivityObservers = new nsTHashtable<nsPtrHashKey<nsISupports> >();
-    if (!mActivityObservers)
-      return;
   }
   mActivityObservers->PutEntry(aSupports);
 }
 
 bool
 nsIDocument::UnregisterActivityObserver(nsISupports* aSupports)
 {
   if (!mActivityObservers) {
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -1302,18 +1302,16 @@ nsDocumentEncoder::SetNodeFixup(nsIDocum
 
 
 nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult); // make mac compiler happy
 
 nsresult
 NS_NewTextEncoder(nsIDocumentEncoder** aResult)
 {
   *aResult = new nsDocumentEncoder;
-  if (!*aResult)
-    return NS_ERROR_OUT_OF_MEMORY;
  NS_ADDREF(*aResult);
  return NS_OK;
 }
 
 class nsHTMLCopyEncoder : public nsDocumentEncoder
 {
 public:
 
@@ -2049,18 +2047,16 @@ nsHTMLCopyEncoder::IsEmptyTextContent(ns
 }
 
 nsresult NS_NewHTMLCopyTextEncoder(nsIDocumentEncoder** aResult); // make mac compiler happy
 
 nsresult
 NS_NewHTMLCopyTextEncoder(nsIDocumentEncoder** aResult)
 {
   *aResult = new nsHTMLCopyEncoder;
-  if (!*aResult)
-    return NS_ERROR_OUT_OF_MEMORY;
  NS_ADDREF(*aResult);
  return NS_OK;
 }
 
 int32_t
 nsHTMLCopyEncoder::GetImmediateContextCount(const nsTArray<nsINode*>& aAncestorArray)
 {
   int32_t i = aAncestorArray.Length(), j = 0;
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -185,17 +185,16 @@ nsFocusManager::~nsFocusManager()
   }
 }
 
 // static
 nsresult
 nsFocusManager::Init()
 {
   nsFocusManager* fm = new nsFocusManager();
-  NS_ENSURE_TRUE(fm, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(fm);
   sInstance = fm;
 
   gFocusLog = PR_NewLogModule("Focus");
   gFocusNavigationLog = PR_NewLogModule("FocusNavigation");
 
   nsIContent::sTabFocusModelAppliesToXUL =
     Preferences::GetBool("accessibility.tabfocus_applies_to_xul",
--- a/dom/base/nsGenConImageContent.cpp
+++ b/dom/base/nsGenConImageContent.cpp
@@ -71,18 +71,16 @@ NS_IMPL_ISUPPORTS_INHERITED(nsGenConImag
                             imgIOnloadBlocker)
 
 nsresult
 NS_NewGenConImageContent(nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
                          imgRequestProxy* aImageRequest)
 {
   NS_PRECONDITION(aImageRequest, "Must have request!");
   nsGenConImageContent *it = new nsGenConImageContent(aNodeInfo);
-  if (!it)
-    return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(*aResult = it);
   nsresult rv = it->Init(aImageRequest);
   if (NS_FAILED(rv))
     NS_RELEASE(*aResult);
   return rv;
 }
 
 nsGenConImageContent::~nsGenConImageContent()
--- a/dom/base/nsGenericDOMDataNode.cpp
+++ b/dom/base/nsGenericDOMDataNode.cpp
@@ -338,17 +338,16 @@ nsGenericDOMDataNode::SetTextInternal(ui
     NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
   }
   else {
     // Merging old and new
 
     // Allocate new buffer
     int32_t newLength = textLength - aCount + aLength;
     char16_t* to = new char16_t[newLength];
-    NS_ENSURE_TRUE(to, NS_ERROR_OUT_OF_MEMORY);
 
     // Copy over appropriate data
     if (aOffset) {
       mText.CopyTo(to, 0, aOffset);
     }
     if (aLength) {
       memcpy(to + aOffset, aBuffer, aLength * sizeof(char16_t));
     }
--- a/dom/base/nsGlobalWindowCommands.cpp
+++ b/dom/base/nsGlobalWindowCommands.cpp
@@ -983,25 +983,23 @@ nsClipboardDragDropHookCommand::GetComma
 
   RegisterWindowCommands
 
 ----------------------------------------------------------------------------*/
 
 #define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName)                \
   {                                                                 \
     _cmdClass* theCmd = new _cmdClass();                            \
-    if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                     \
     rv = inCommandTable->RegisterCommand(_cmdName,                  \
                    static_cast<nsIControllerCommand *>(theCmd));    \
   }
 
 #define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName)              \
   {                                                                 \
     _cmdClass* theCmd = new _cmdClass();                            \
-    if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                     \
     rv = inCommandTable->RegisterCommand(_cmdName,                  \
                    static_cast<nsIControllerCommand *>(theCmd));
 
 #define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName)               \
     rv = inCommandTable->RegisterCommand(_cmdName,                  \
                    static_cast<nsIControllerCommand *>(theCmd));
 
 #define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName)               \
--- a/dom/base/nsImageLoadingContent.cpp
+++ b/dom/base/nsImageLoadingContent.cpp
@@ -380,20 +380,16 @@ nsImageLoadingContent::AddObserver(imgIN
   // otherwise we have to create a new entry
 
   ImageObserver* observer = &mObserverList;
   while (observer->mNext) {
     observer = observer->mNext;
   }
 
   observer->mNext = new ImageObserver(aObserver);
-  if (! observer->mNext) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
   ReplayImageStatus(mCurrentRequest, aObserver);
   ReplayImageStatus(mPendingRequest, aObserver);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsImageLoadingContent::RemoveObserver(imgINotificationObserver* aObserver)
--- a/dom/base/nsNameSpaceManager.cpp
+++ b/dom/base/nsNameSpaceManager.cpp
@@ -184,17 +184,17 @@ nsresult nsNameSpaceManager::AddNameSpac
     // We've wrapped...  Can't do anything else here; just bail.
     return NS_ERROR_OUT_OF_MEMORY;
   }
   
   NS_ASSERTION(aNameSpaceID - 1 == (int32_t) mURIArray.Length(),
                "BAD! AddNameSpace not called in right order!");
 
   nsString* uri = new nsString(aURI);
-  if (!uri || !mURIArray.AppendElement(uri)) {
+  if (!mURIArray.AppendElement(uri)) {
     delete uri;
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   mURIToIDTable.Put(uri, aNameSpaceID);
 
   return NS_OK;
 }
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -2931,19 +2931,16 @@ nsObjectLoadingContent::AsyncStartPlugin
   nsCOMPtr<nsIContent> thisContent =
     do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
   nsIDocument* doc = thisContent->OwnerDoc();
   if (doc->IsStaticDocument() || doc->IsBeingUsedAsImage()) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIRunnable> event = new nsAsyncInstantiateEvent(this);
-  if (!event) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
   nsresult rv = NS_DispatchToCurrentThread(event);
   if (NS_SUCCEEDED(rv)) {
     // Track pending events
     mPendingInstantiateEvent = event;
   }
 
   return rv;
 }
--- a/dom/base/nsScriptNameSpaceManager.cpp
+++ b/dom/base/nsScriptNameSpaceManager.cpp
@@ -475,18 +475,16 @@ nsScriptNameSpaceManager::RegisterDOMCID
 
   // XXX Should we bail out here?
   NS_ASSERTION(s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
                s->mType == nsGlobalNameStruct::eTypeNewDOMBinding ||
                s->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator,
                "Someone tries to register classinfo data for a class that isn't new or external!");
 
   s->mData = new nsExternalDOMClassInfoData;
-  NS_ENSURE_TRUE(s->mData, NS_ERROR_OUT_OF_MEMORY);
-
   s->mType = nsGlobalNameStruct::eTypeExternalClassInfo;
   s->mData->mName = aName;
   s->mData->mNameUTF16 = className;
   if (aConstructorFptr)
     s->mData->u.mExternalConstructorFptr = aConstructorFptr;
   else
     // null constructor will cause us to use nsDOMGenericSH::doCreate
     s->mData->u.mExternalConstructorFptr = nullptr;
--- a/dom/base/nsTextFragment.cpp
+++ b/dom/base/nsTextFragment.cpp
@@ -37,18 +37,16 @@ using mozilla::CheckedUint32;
 nsresult
 nsTextFragment::Init()
 {
   // Create whitespace strings
   uint32_t i;
   for (i = 0; i <= TEXTFRAG_MAX_NEWLINES; ++i) {
     sSpaceSharedString[i] = new char[1 + i + TEXTFRAG_WHITE_AFTER_NEWLINE];
     sTabSharedString[i] = new char[1 + i + TEXTFRAG_WHITE_AFTER_NEWLINE];
-    NS_ENSURE_TRUE(sSpaceSharedString[i] && sTabSharedString[i],
-                   NS_ERROR_OUT_OF_MEMORY);
     sSpaceSharedString[i][0] = ' ';
     sTabSharedString[i][0] = ' ';
     uint32_t j;
     for (j = 1; j < 1 + i; ++j) {
       sSpaceSharedString[i][j] = '\n';
       sTabSharedString[i][j] = '\n';
     }
     for (; j < (1 + i + TEXTFRAG_WHITE_AFTER_NEWLINE); ++j) {
--- a/dom/base/nsTextNode.cpp
+++ b/dom/base/nsTextNode.cpp
@@ -209,20 +209,16 @@ NS_NewAttributeContent(nsNodeInfoManager
   
   *aResult = nullptr;
 
   already_AddRefed<mozilla::dom::NodeInfo> ni = aNodeInfoManager->GetTextNodeInfo();
 
   nsAttributeTextNode* textNode = new nsAttributeTextNode(ni,
                                                           aNameSpaceID,
                                                           aAttrName);
-  if (!textNode) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
   NS_ADDREF(*aResult = textNode);
 
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS_INHERITED(nsAttributeTextNode, nsTextNode,
                             nsIMutationObserver)