Bug 1496598 - Port bug 1493226: remove needless QueryInterface calls in JS delegation. r=jorgk
This changes the DELEGATE_JS helper macro, replacing QueryInterface usage with raw pointers (or implicit casts to descendent types) in cases where the object type is known at compile time. In fact, the remaining QueryInterface uses could also be removed - in all cases, we _know_ that the mCppBase is an instance of the "Super" helper class, which is always castable to the interfaces we're opening to delegation. But at the moment, mCppBase is always stored as a nsCOMPtr<> to one of the interfaces, and we can't get to the others without using a runtime QueryInterface().
This commit is contained in:
Родитель
59aaab00c9
Коммит
162bfadde0
|
@ -36,18 +36,17 @@ protected:
|
|||
|
||||
/*
|
||||
* This macro is used in forwarding functions.
|
||||
* _interface: the interface being forwarded.
|
||||
* _jsdelegate: the name of the JS pointer that implements a particular
|
||||
* interface.
|
||||
* _jsmethods: the DelegateList object
|
||||
* _cppbase: the C++ base instance (used when call not delegated to js)
|
||||
*
|
||||
* You must follow the naming convention:
|
||||
* 1) use mCppBase as the name of the C++ base class instance.
|
||||
* 2) use mMethod as the name of the DelegateList object.
|
||||
**/
|
||||
|
||||
#define DELEGATE_JS(_interface, _jsdelegate) (\
|
||||
_jsdelegate && mMethods && \
|
||||
mMethods->Contains(nsLiteralCString(__FUNCTION__)) ? \
|
||||
_jsdelegate : nsCOMPtr<_interface>(do_QueryInterface(mCppBase)))
|
||||
#define DELEGATE_JS(_jsdelegate, _jsmethods, _cppbase) (\
|
||||
_jsdelegate && _jsmethods && \
|
||||
_jsmethods->Contains(nsLiteralCString(__FUNCTION__)) ? \
|
||||
_jsdelegate : (_cppbase))
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -45,10 +45,12 @@ public:
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_MSGIOVERRIDE
|
||||
|
||||
NS_FORWARD_NSIABDIRECTORY(DELEGATE_JS(nsIAbDirectory, mJsIAbDirectory)->)
|
||||
NS_FORWARD_NSIABCOLLECTION(DELEGATE_JS(nsIAbCollection, mJsIAbCollection)->)
|
||||
NS_FORWARD_NSIABITEM(DELEGATE_JS(nsIAbItem, mJsIAbItem)->)
|
||||
NS_FORWARD_NSIINTERFACEREQUESTOR(DELEGATE_JS(nsIInterfaceRequestor, mJsIInterfaceRequestor)->)
|
||||
// use mCppBase as a raw pointer where possible
|
||||
NS_FORWARD_NSIABDIRECTORY(DELEGATE_JS(mJsIAbDirectory, mMethods, mCppBase)->)
|
||||
NS_FORWARD_NSIABCOLLECTION(DELEGATE_JS(mJsIAbCollection, mMethods, (mCppBase.get()))->)
|
||||
NS_FORWARD_NSIABITEM(DELEGATE_JS(mJsIAbItem, mMethods, (mCppBase.get()))->)
|
||||
NS_FORWARD_NSIINTERFACEREQUESTOR(DELEGATE_JS(mJsIInterfaceRequestor, mMethods,
|
||||
(nsCOMPtr<nsIInterfaceRequestor>(do_QueryInterface(mCppBase))))->)
|
||||
|
||||
JaCppAbDirectoryDelegator();
|
||||
|
||||
|
@ -56,6 +58,7 @@ private:
|
|||
virtual ~JaCppAbDirectoryDelegator() {
|
||||
}
|
||||
|
||||
// nsIAbDirectory inherits from nsIAbCollection which inherits from nsIAbItem.
|
||||
class Super : public nsIAbDirectory,
|
||||
public nsIInterfaceRequestor
|
||||
{
|
||||
|
|
|
@ -46,9 +46,11 @@ public:
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_MSGIOVERRIDE
|
||||
|
||||
NS_FORWARD_NSIMSGCOMPOSE(DELEGATE_JS(nsIMsgCompose, mJsIMsgCompose)->)
|
||||
NS_FORWARD_NSIMSGSENDLISTENER(DELEGATE_JS(nsIMsgSendListener, mJsIMsgSendListener)->)
|
||||
NS_FORWARD_NSIINTERFACEREQUESTOR(DELEGATE_JS(nsIInterfaceRequestor, mJsIInterfaceRequestor)->)
|
||||
NS_FORWARD_NSIMSGCOMPOSE(DELEGATE_JS(mJsIMsgCompose, mMethods, mCppBase)->)
|
||||
NS_FORWARD_NSIMSGSENDLISTENER(DELEGATE_JS(mJsIMsgSendListener, mMethods, mCppBase.get())->)
|
||||
NS_FORWARD_NSIINTERFACEREQUESTOR(
|
||||
DELEGATE_JS(mJsIInterfaceRequestor, mMethods,
|
||||
(nsCOMPtr<nsIInterfaceRequestor>(do_QueryInterface(mCppBase))))->)
|
||||
|
||||
JaCppComposeDelegator();
|
||||
|
||||
|
|
|
@ -50,8 +50,10 @@ public:
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_MSGIOVERRIDE
|
||||
|
||||
NS_FORWARD_NSIMSGINCOMINGSERVER(DELEGATE_JS(nsIMsgIncomingServer, mJsIMsgIncomingServer)->)
|
||||
NS_FORWARD_NSIINTERFACEREQUESTOR(DELEGATE_JS(nsIInterfaceRequestor, mJsIInterfaceRequestor)->)
|
||||
// use mCppBase as a raw pointer where possible
|
||||
NS_FORWARD_NSIMSGINCOMINGSERVER(DELEGATE_JS(mJsIMsgIncomingServer, mMethods, mCppBase)->)
|
||||
NS_FORWARD_NSIINTERFACEREQUESTOR(DELEGATE_JS(mJsIInterfaceRequestor, mMethods,
|
||||
(nsCOMPtr<nsIInterfaceRequestor>(do_QueryInterface(mCppBase))))->)
|
||||
|
||||
JaCppIncomingServerDelegator();
|
||||
|
||||
|
|
|
@ -64,18 +64,23 @@ public:
|
|||
// Note that we do not support override of RDF methods.
|
||||
NS_FORWARD_NSIRDFRESOURCE(JaBaseCppMsgFolder::)
|
||||
NS_FORWARD_NSIRDFNODE(JaBaseCppMsgFolder::)
|
||||
NS_FORWARD_NSIMSGFOLDER(DELEGATE_JS(nsIMsgFolder, mJsIMsgFolder)->)
|
||||
NS_FORWARD_NSIMSGFOLDER(
|
||||
DELEGATE_JS(mJsIMsgFolder, mMethods, mCppBase)->)
|
||||
NS_FORWARD_NSIDBCHANGELISTENER(
|
||||
DELEGATE_JS(nsIDBChangeListener, mJsIDBChangeListener)->)
|
||||
NS_FORWARD_NSIURLLISTENER(DELEGATE_JS(nsIUrlListener, mJsIUrlListener)->)
|
||||
DELEGATE_JS(mJsIDBChangeListener, mMethods,
|
||||
(nsCOMPtr<nsIDBChangeListener>(do_QueryInterface(mCppBase))))->)
|
||||
NS_FORWARD_NSIURLLISTENER(
|
||||
DELEGATE_JS(mJsIUrlListener, mMethods,
|
||||
(nsCOMPtr<nsIUrlListener>(do_QueryInterface(mCppBase))))->)
|
||||
NS_FORWARD_NSIJUNKMAILCLASSIFICATIONLISTENER(
|
||||
DELEGATE_JS(nsIJunkMailClassificationListener,
|
||||
mJsIJunkMailClassificationListener)->)
|
||||
DELEGATE_JS(mJsIJunkMailClassificationListener, mMethods,
|
||||
(nsCOMPtr<nsIJunkMailClassificationListener>(do_QueryInterface(mCppBase))))->)
|
||||
NS_FORWARD_NSIMSGTRAITCLASSIFICATIONLISTENER(
|
||||
DELEGATE_JS(nsIMsgTraitClassificationListener,
|
||||
mJsIMsgTraitClassificationListener)->)
|
||||
DELEGATE_JS(mJsIMsgTraitClassificationListener, mMethods,
|
||||
(nsCOMPtr<nsIMsgTraitClassificationListener>(do_QueryInterface(mCppBase))))->)
|
||||
NS_FORWARD_NSIINTERFACEREQUESTOR(
|
||||
DELEGATE_JS(nsIInterfaceRequestor, mJsIInterfaceRequestor)->)
|
||||
DELEGATE_JS(mJsIInterfaceRequestor, mMethods,
|
||||
(nsCOMPtr<nsIInterfaceRequestor>(do_QueryInterface(mCppBase))))->)
|
||||
|
||||
JaCppMsgFolderDelegator();
|
||||
|
||||
|
|
|
@ -47,11 +47,13 @@ public:
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_MSGIOVERRIDE
|
||||
|
||||
NS_FORWARD_NSIMSGSEND(DELEGATE_JS(nsIMsgSend, mJsIMsgSend)->)
|
||||
NS_FORWARD_NSIMSGSEND(DELEGATE_JS(mJsIMsgSend, mMethods, mCppBase)->)
|
||||
NS_FORWARD_NSIMSGOPERATIONLISTENER(
|
||||
DELEGATE_JS(nsIMsgOperationListener, mJsIMsgOperationListener)->)
|
||||
DELEGATE_JS(mJsIMsgOperationListener, mMethods,
|
||||
(nsCOMPtr<nsIMsgOperationListener>(do_QueryInterface(mCppBase))))->)
|
||||
NS_FORWARD_NSIINTERFACEREQUESTOR(
|
||||
DELEGATE_JS(nsIInterfaceRequestor, mJsIInterfaceRequestor)->)
|
||||
DELEGATE_JS(mJsIInterfaceRequestor, mMethods,
|
||||
(nsCOMPtr<nsIInterfaceRequestor>(do_QueryInterface(mCppBase))))->)
|
||||
|
||||
JaCppSendDelegator();
|
||||
|
||||
|
|
|
@ -76,8 +76,10 @@ public:
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_MSGIOVERRIDE
|
||||
|
||||
NS_FORWARD_NSIMSGMESSAGEURL(DELEGATE_JS(nsIMsgMessageUrl, mJsIMsgMessageUrl)->)
|
||||
NS_FORWARD_NSIINTERFACEREQUESTOR(DELEGATE_JS(nsIInterfaceRequestor, mJsIInterfaceRequestor)->)
|
||||
NS_FORWARD_NSIMSGMESSAGEURL(DELEGATE_JS(mJsIMsgMessageUrl, mMethods,
|
||||
(nsCOMPtr<nsIMsgMessageUrl>(do_QueryInterface(mCppBase))))->)
|
||||
NS_FORWARD_NSIINTERFACEREQUESTOR(DELEGATE_JS(mJsIInterfaceRequestor, mMethods,
|
||||
(nsCOMPtr<nsIInterfaceRequestor>(do_QueryInterface(mCppBase))))->)
|
||||
|
||||
JaCppUrlDelegator();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче