Fixing bug 408792. Remove some expensive QI calls from frequently called code. r=jonas@sicking.cc, sr=bzbarsky@mit.edu

This commit is contained in:
jst@mozilla.org 2007-12-21 05:44:58 -08:00
Родитель d8a0bcdea5
Коммит 7a800e1698
5 изменённых файлов: 23 добавлений и 8 удалений

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

@ -1126,7 +1126,7 @@ nsDocument::Init()
// subclasses currently do, other don't). This is because the code in
// nsNodeUtils always notifies the first observer first, expecting the
// first observer to be the document.
NS_ENSURE_TRUE(slots->mMutationObservers.PrependElementUnlessExists(this),
NS_ENSURE_TRUE(slots->mMutationObservers.PrependElementUnlessExists(static_cast<nsIMutationObserver*>(this)),
NS_ERROR_OUT_OF_MEMORY);
@ -2585,6 +2585,11 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
mLayoutHistoryState = nsnull;
mScopeObject = do_GetWeakReference(aScriptGlobalObject);
}
// Remember the pointer to our window (or lack there of), to avoid
// having to QI every time it's asked for.
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mScriptGlobalObject);
mWindow = window;
}
nsIScriptGlobalObject*
@ -2625,6 +2630,10 @@ nsDocument::SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject)
nsPIDOMWindow *
nsDocument::GetWindow()
{
if (mWindow) {
return mWindow->GetOuterWindow();
}
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(GetScriptGlobalObject()));
if (!win) {

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

@ -747,6 +747,9 @@ protected:
// document can get its script context and scope. This is the
// *inner* window object.
nsCOMPtr<nsIScriptGlobalObject> mScriptGlobalObject;
// Weak reference to mScriptGlobalObject QI:d to nsPIDOMWindow,
// updated on every set of mSecriptGlobalObject.
nsPIDOMWindow *mWindow;
// If document is created for example using
// document.implementation.createDocument(...), mScriptObject points to

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

@ -3399,7 +3399,7 @@ nsHTMLDocument::ResolveName(const nsAString& aName,
IdAndNameMapEntry *entry =
static_cast<IdAndNameMapEntry *>
(PL_DHashTableOperate(&mIdAndNameHashTable, name,
PL_DHASH_ADD));
PL_DHASH_ADD));
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
if (entry->mNameContentList == NAME_NOT_VALID) {
@ -3419,7 +3419,7 @@ nsHTMLDocument::ResolveName(const nsAString& aName,
// If we already have an entry->mNameContentList, we need to flush out
// notifications too, so that it will get updated properly.
FlushPendingNotifications(entry->mNameContentList ?
Flush_ContentAndNotify : Flush_Content);
Flush_ContentAndNotify : Flush_Content);
if (generation != mIdAndNameHashTable.generation) {
// Table changed, so the entry pointer is no longer valid; look up the
@ -3428,7 +3428,7 @@ nsHTMLDocument::ResolveName(const nsAString& aName,
entry =
static_cast<IdAndNameMapEntry *>
(PL_DHashTableOperate(&mIdAndNameHashTable, name,
PL_DHASH_ADD));
PL_DHASH_ADD));
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
}

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

@ -129,6 +129,8 @@ LOCAL_INCLUDES = \
-I$(topsrcdir)/content/xul/document/src \
-I$(topsrcdir)/content/events/src \
-I$(topsrcdir)/content/base/src \
-I$(topsrcdir)/content/html/document/src \
-I$(topsrcdir)/layout/style \
$(NULL)
DEFINES += -D_IMPL_NS_LAYOUT

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

@ -132,7 +132,7 @@
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMNSHTMLFormControlList.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIHTMLDocument.h"
#include "nsHTMLDocument.h"
// HTMLSelectElement helper includes
#include "nsIDOMHTMLSelectElement.h"
@ -7667,8 +7667,9 @@ nsHTMLDocumentSH::ResolveImpl(JSContext *cx,
nsIXPConnectWrappedNative *wrapper, jsval id,
nsISupports **result)
{
nsCOMPtr<nsIHTMLDocument> doc(do_QueryWrappedNative(wrapper));
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
nsHTMLDocument *doc =
static_cast<nsHTMLDocument*>(static_cast<nsINode*>
(wrapper->Native()));
// 'id' is not always a string, it can be a number since document.1
// should map to <input name="1">. Thus we can't use
@ -8252,7 +8253,7 @@ nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
if (id == sAll_id && !sDisableDocumentAllSupport &&
!ObjectIsNativeWrapper(cx, obj)) {
nsCOMPtr<nsIDocument> doc(do_QueryWrappedNative(wrapper));
nsIDocument *doc = static_cast<nsIDocument*>(wrapper->Native());
if (doc->GetCompatibilityMode() == eCompatibility_NavQuirks) {
JSObject *helper =