From 57a8f89c7442336b0354baf66e3c34f61207eb36 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.org" Date: Tue, 4 Dec 2007 03:53:00 +0000 Subject: [PATCH] Fixing bug 406671. Speed up nsWindowSH::GetProperty(). r+sr=peterv@propagandism.org, a=jonas@sicking.cc --- dom/src/base/nsDOMClassInfo.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index edb826f9eb2..de9eb14f141 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -4466,19 +4466,31 @@ nsWindowSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, // child frame in nsWindowSH::NewResolve() (*vp will tell us if // that's the case). If *vp is a window object (i.e. a child // frame), return without doing a security check. + // + // Calling GetWrappedNativeOfJSObject() is not all that cheap, so + // only do that if the JSClass name is one that is likely to be a + // window object. - nsCOMPtr vpwrapper; - sXPConnect->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(*vp), - getter_AddRefs(vpwrapper)); + const char *name = JS_GET_CLASS(cx, JSVAL_TO_OBJECT(*vp))->name; - if (vpwrapper) { - nsCOMPtr window(do_QueryWrappedNative(vpwrapper)); + // The list of Window class names here need to be kept in sync + // with the actual class names! + if ((*name == 'W' && strcmp(name, "Window") == 0) || + (*name == 'C' && strcmp(name, "ChromeWindow") == 0) || + (*name == 'M' && strcmp(name, "ModalContentWindow") == 0)) { + nsCOMPtr vpwrapper; + sXPConnect->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(*vp), + getter_AddRefs(vpwrapper)); - if (window) { - // Yup, *vp is a window object, return early (*vp is already - // the window, so no need to wrap it again). + if (vpwrapper) { + nsCOMPtr window(do_QueryWrappedNative(vpwrapper)); - return NS_SUCCESS_I_DID_SOMETHING; + if (window) { + // Yup, *vp is a window object, return early (*vp is already + // the window, so no need to wrap it again). + + return NS_SUCCESS_I_DID_SOMETHING; + } } } }