Bug 1289457 - Take advantage of infallible new in XPCNativeSet::NewInstance{,Mutate} to skip checks. r=mrbkap
authorAndrew McCreight <continuation@gmail.com>
Fri, 29 Jul 2016 16:08:06 -0700
changeset 347405 5f0c9095c0ff59de08caa34270c6139deef86f3b
parent 347404 6b2d6afdd59b9cfba22e49d09cf3a892835db9d0
child 347406 fcc56a97afb3beb1786a205d4634e377efbf4ebe
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1289457
milestone50.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 1289457 - Take advantage of infallible new in XPCNativeSet::NewInstance{,Mutate} to skip checks. r=mrbkap MozReview-Commit-ID: H4TEMzzT6iK
js/xpconnect/src/XPCWrappedNativeInfo.cpp
--- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp
@@ -675,18 +675,16 @@ XPCNativeSet::GetNewOrUsed(XPCNativeSet*
     return currentSet;
 }
 
 // static
 XPCNativeSet*
 XPCNativeSet::NewInstance(XPCNativeInterface** array,
                           uint16_t count)
 {
-    XPCNativeSet* obj = nullptr;
-
     if (!array || !count)
         return nullptr;
 
     // We impose the invariant:
     // "All sets have exactly one nsISupports interface and it comes first."
     // This is the place where we impose that rule - even if given inputs
     // that don't exactly follow the rule.
 
@@ -702,83 +700,75 @@ XPCNativeSet::NewInstance(XPCNativeInter
     }
 
     // Use placement new to create an object with the right amount of space
     // to hold the members array
     int size = sizeof(XPCNativeSet);
     if (slots > 1)
         size += (slots - 1) * sizeof(XPCNativeInterface*);
     void* place = new char[size];
-    if (place)
-        obj = new(place) XPCNativeSet();
+    XPCNativeSet* obj = new(place) XPCNativeSet();
 
-    if (obj) {
-        // Stick the nsISupports in front and skip additional nsISupport(s)
-        XPCNativeInterface** inp = array;
-        XPCNativeInterface** outp = (XPCNativeInterface**) &obj->mInterfaces;
-        uint16_t memberCount = 1;   // for the one member in nsISupports
+    // Stick the nsISupports in front and skip additional nsISupport(s)
+    XPCNativeInterface** inp = array;
+    XPCNativeInterface** outp = (XPCNativeInterface**) &obj->mInterfaces;
+    uint16_t memberCount = 1;   // for the one member in nsISupports
 
-        *(outp++) = isup;
+    *(outp++) = isup;
 
-        for (i = 0; i < count; i++) {
-            XPCNativeInterface* cur;
+    for (i = 0; i < count; i++) {
+        XPCNativeInterface* cur;
 
-            if (isup == (cur = *(inp++)))
-                continue;
-            *(outp++) = cur;
-            memberCount += cur->GetMemberCount();
-        }
-        obj->mMemberCount = memberCount;
-        obj->mInterfaceCount = slots;
+        if (isup == (cur = *(inp++)))
+            continue;
+        *(outp++) = cur;
+        memberCount += cur->GetMemberCount();
     }
+    obj->mMemberCount = memberCount;
+    obj->mInterfaceCount = slots;
 
     return obj;
 }
 
 // static
 XPCNativeSet*
 XPCNativeSet::NewInstanceMutate(XPCNativeSet*       otherSet,
                                 XPCNativeInterface* newInterface,
                                 uint16_t            position)
 {
-    XPCNativeSet* obj = nullptr;
-
     if (!newInterface)
         return nullptr;
     if (otherSet && position > otherSet->mInterfaceCount)
         return nullptr;
 
     // Use placement new to create an object with the right amount of space
     // to hold the members array
     int size = sizeof(XPCNativeSet);
     if (otherSet)
         size += otherSet->mInterfaceCount * sizeof(XPCNativeInterface*);
     void* place = new char[size];
-    if (place)
-        obj = new(place) XPCNativeSet();
+    XPCNativeSet* obj = new(place) XPCNativeSet();
 
-    if (obj) {
-        if (otherSet) {
-            obj->mMemberCount = otherSet->GetMemberCount() +
-                                newInterface->GetMemberCount();
-            obj->mInterfaceCount = otherSet->mInterfaceCount + 1;
+    if (otherSet) {
+        obj->mMemberCount = otherSet->GetMemberCount() +
+            newInterface->GetMemberCount();
+        obj->mInterfaceCount = otherSet->mInterfaceCount + 1;
 
-            XPCNativeInterface** src = otherSet->mInterfaces;
-            XPCNativeInterface** dest = obj->mInterfaces;
-            for (uint16_t i = 0; i < obj->mInterfaceCount; i++) {
-                if (i == position)
-                    *dest++ = newInterface;
-                else
-                    *dest++ = *src++;
-            }
-        } else {
-            obj->mMemberCount = newInterface->GetMemberCount();
-            obj->mInterfaceCount = 1;
-            obj->mInterfaces[0] = newInterface;
+        XPCNativeInterface** src = otherSet->mInterfaces;
+        XPCNativeInterface** dest = obj->mInterfaces;
+        for (uint16_t i = 0; i < obj->mInterfaceCount; i++) {
+            if (i == position)
+                *dest++ = newInterface;
+            else
+                *dest++ = *src++;
         }
+    } else {
+        obj->mMemberCount = newInterface->GetMemberCount();
+        obj->mInterfaceCount = 1;
+        obj->mInterfaces[0] = newInterface;
     }
 
     return obj;
 }
 
 // static
 void
 XPCNativeSet::DestroyInstance(XPCNativeSet* inst)