Bug 950281 - micro-optimize NS_TableDrivenQI by ensuring the table has at least 1 non-null entry; r=bsmedberg

This commit is contained in:
Nathan Froyd 2013-12-13 19:17:18 -05:00
parent 02c94cf332
commit cef4749188
2 changed files with 9 additions and 2 deletions

View File

@ -8,7 +8,7 @@ nsresult NS_FASTCALL
NS_TableDrivenQI(void* aThis, const QITableEntry* entries,
REFNSIID aIID, void **aInstancePtr)
{
while (entries->iid) {
do {
if (aIID.Equals(*entries->iid)) {
nsISupports* r =
reinterpret_cast<nsISupports*>
@ -19,7 +19,7 @@ NS_TableDrivenQI(void* aThis, const QITableEntry* entries,
}
++entries;
}
} while (entries->iid);
*aInstancePtr = nullptr;
return NS_ERROR_NO_INTERFACE;

View File

@ -609,8 +609,15 @@ NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
reinterpret_cast<char*>((_class*) 0x1000)) \
},
/*
* XXX: we want to use mozilla::ArrayLength (or equivalent,
* MOZ_ARRAY_LENGTH) in this condition, but some versions of GCC don't
* see that the static_assert condition is actually constant in those
* cases, even with constexpr support (?).
*/
#define NS_INTERFACE_TABLE_END_WITH_PTR(_ptr) \
{ nullptr, 0 } }; \
static_assert((sizeof(table)/sizeof(table[0])) > 1, "need at least 1 interface"); \
rv = NS_TableDrivenQI(static_cast<void*>(_ptr), \
table, aIID, aInstancePtr);