Bug 1289457 - Take advantage of infallible new in XPCNativeSet::NewInstance{,Mutate} to skip checks. r=mrbkap

MozReview-Commit-ID: H4TEMzzT6iK
This commit is contained in:
Andrew McCreight 2016-07-29 16:08:06 -07:00
Родитель dbb581c9f8
Коммит 82ac383602
1 изменённых файлов: 30 добавлений и 40 удалений

Просмотреть файл

@ -680,8 +680,6 @@ XPCNativeSet*
XPCNativeSet::NewInstance(XPCNativeInterface** array, XPCNativeSet::NewInstance(XPCNativeInterface** array,
uint16_t count) uint16_t count)
{ {
XPCNativeSet* obj = nullptr;
if (!array || !count) if (!array || !count)
return nullptr; return nullptr;
@ -707,28 +705,25 @@ XPCNativeSet::NewInstance(XPCNativeInterface** array,
if (slots > 1) if (slots > 1)
size += (slots - 1) * sizeof(XPCNativeInterface*); size += (slots - 1) * sizeof(XPCNativeInterface*);
void* place = new char[size]; void* place = new char[size];
if (place) XPCNativeSet* obj = new(place) XPCNativeSet();
obj = new(place) XPCNativeSet();
if (obj) { // Stick the nsISupports in front and skip additional nsISupport(s)
// Stick the nsISupports in front and skip additional nsISupport(s) XPCNativeInterface** inp = array;
XPCNativeInterface** inp = array; XPCNativeInterface** outp = (XPCNativeInterface**) &obj->mInterfaces;
XPCNativeInterface** outp = (XPCNativeInterface**) &obj->mInterfaces; uint16_t memberCount = 1; // for the one member in nsISupports
uint16_t memberCount = 1; // for the one member in nsISupports
*(outp++) = isup; *(outp++) = isup;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
XPCNativeInterface* cur; XPCNativeInterface* cur;
if (isup == (cur = *(inp++))) if (isup == (cur = *(inp++)))
continue; continue;
*(outp++) = cur; *(outp++) = cur;
memberCount += cur->GetMemberCount(); memberCount += cur->GetMemberCount();
}
obj->mMemberCount = memberCount;
obj->mInterfaceCount = slots;
} }
obj->mMemberCount = memberCount;
obj->mInterfaceCount = slots;
return obj; return obj;
} }
@ -739,8 +734,6 @@ XPCNativeSet::NewInstanceMutate(XPCNativeSet* otherSet,
XPCNativeInterface* newInterface, XPCNativeInterface* newInterface,
uint16_t position) uint16_t position)
{ {
XPCNativeSet* obj = nullptr;
if (!newInterface) if (!newInterface)
return nullptr; return nullptr;
if (otherSet && position > otherSet->mInterfaceCount) if (otherSet && position > otherSet->mInterfaceCount)
@ -752,28 +745,25 @@ XPCNativeSet::NewInstanceMutate(XPCNativeSet* otherSet,
if (otherSet) if (otherSet)
size += otherSet->mInterfaceCount * sizeof(XPCNativeInterface*); size += otherSet->mInterfaceCount * sizeof(XPCNativeInterface*);
void* place = new char[size]; void* place = new char[size];
if (place) XPCNativeSet* obj = new(place) XPCNativeSet();
obj = new(place) XPCNativeSet();
if (obj) { if (otherSet) {
if (otherSet) { obj->mMemberCount = otherSet->GetMemberCount() +
obj->mMemberCount = otherSet->GetMemberCount() + newInterface->GetMemberCount();
newInterface->GetMemberCount(); obj->mInterfaceCount = otherSet->mInterfaceCount + 1;
obj->mInterfaceCount = otherSet->mInterfaceCount + 1;
XPCNativeInterface** src = otherSet->mInterfaces; XPCNativeInterface** src = otherSet->mInterfaces;
XPCNativeInterface** dest = obj->mInterfaces; XPCNativeInterface** dest = obj->mInterfaces;
for (uint16_t i = 0; i < obj->mInterfaceCount; i++) { for (uint16_t i = 0; i < obj->mInterfaceCount; i++) {
if (i == position) if (i == position)
*dest++ = newInterface; *dest++ = newInterface;
else else
*dest++ = *src++; *dest++ = *src++;
}
} else {
obj->mMemberCount = newInterface->GetMemberCount();
obj->mInterfaceCount = 1;
obj->mInterfaces[0] = newInterface;
} }
} else {
obj->mMemberCount = newInterface->GetMemberCount();
obj->mInterfaceCount = 1;
obj->mInterfaces[0] = newInterface;
} }
return obj; return obj;