gecko-dev/xpcom/glue/nsISupportsImpl.cpp
Nathan Froyd fb3a3066d1 Bug 950882 - micro-optimize NS_TableDrivenQI calling sequence by reordering argument list; r=bsmedberg
For register-rich ABIs (e.g. x86-64 and ARM), QueryInterface's incoming
registers are going to look like:

arg register 1: |this|
arg register 2: the IID of interest
arg register 3: the outparam instance pointer

Most of our QI implementations call NS_TableDrivenQI, which expects
arguments like so:

arg register 1: |this|
arg register 2: the QITableEntry table
arg register 3: the IID of interest
arg register 4: the outparam instance pointer

So we're going to have to do a register shuffle of the IID and the
outparam to be able to load the QITableEntry pointer before calling into
NS_TableDrivenQI.

This patch reorders the argument list of NS_TableDrivenQI so that the
first three arguments match the order that QueryInterface receives them
in.  Then your typical QueryInterface implementation becomes:

- load local |table|
- tail-call NS_TableDrivenQI

Eliminating the register shuffling reduces text size by 12K on an
Android ARM build.
2013-12-13 19:50:02 -05:00

27 lines
729 B
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupportsImpl.h"
nsresult NS_FASTCALL
NS_TableDrivenQI(void* aThis, REFNSIID aIID, void **aInstancePtr,
const QITableEntry* entries)
{
do {
if (aIID.Equals(*entries->iid)) {
nsISupports* r =
reinterpret_cast<nsISupports*>
(reinterpret_cast<char*>(aThis) + entries->offset);
NS_ADDREF(r);
*aInstancePtr = r;
return NS_OK;
}
++entries;
} while (entries->iid);
*aInstancePtr = nullptr;
return NS_ERROR_NO_INTERFACE;
}