Fix for bug 814821 (Dromaeo dom-traverse regression from bug 812333) - part 2: make WrapNewBindingObject a little faster. r=bz.

--HG--
extra : rebase_source : ea52aea5d91436b516c8aa439f4af741cdea824c
This commit is contained in:
Peter Van der Beken 2012-11-27 10:20:04 +01:00
Родитель 7a757eb82e
Коммит a40774deb2
2 изменённых файлов: 33 добавлений и 16 удалений

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

@ -2311,11 +2311,7 @@ nsINode::QuerySelectorAll(const nsAString& aSelector, ErrorResult& aResult)
JSObject*
nsINode::WrapObject(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
{
// Not all nodes have been converted
if (!IsDOMBinding()) {
*aTriedToWrap = false;
return nullptr;
}
MOZ_ASSERT(IsDOMBinding());
// Make sure one of these is true
// (1) our owner document has a script handling object,

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

@ -497,9 +497,23 @@ CheckWrapperCacheCast<T, true>
};
#endif
// Create a JSObject wrapping "value", for cases when "value" is a
// non-wrapper-cached object using WebIDL bindings. "value" must implement a
// WrapObject() method taking a JSContext and a scope.
MOZ_ALWAYS_INLINE bool
CouldBeDOMBinding(void*)
{
return true;
}
MOZ_ALWAYS_INLINE bool
CouldBeDOMBinding(nsWrapperCache* aCache)
{
return aCache->IsDOMBinding();
}
// Create a JSObject wrapping "value", if there isn't one already, and store it
// in *vp. "value" must be a concrete class that implements a
// GetWrapperPreserveColor() which can return its existing wrapper, if any, and
// a WrapObject() which will try to create a wrapper. Typically, this is done by
// having "value" inherit from nsWrapperCache.
template <class T>
MOZ_ALWAYS_INLINE bool
WrapNewBindingObject(JSContext* cx, JSObject* scope, T* value, JS::Value* vp)
@ -511,9 +525,12 @@ WrapNewBindingObject(JSContext* cx, JSObject* scope, T* value, JS::Value* vp)
*vp = JS::ObjectValue(*obj);
return true;
}
}
} else {
// Inline this here while we have non-dom objects in wrapper caches.
if (!CouldBeDOMBinding(value)) {
return false;
}
if (!obj) {
bool triedToWrap;
obj = value->WrapObject(cx, scope, &triedToWrap);
if (!obj) {
@ -553,11 +570,9 @@ WrapNewBindingObject(JSContext* cx, JSObject* scope, T* value, JS::Value* vp)
return JS_WrapValue(cx, vp);
}
// Create a JSObject wrapping "value", if there isn't one already, and store it
// in *vp. "value" must be a concrete class that implements a GetWrapper()
// which can return its existing wrapper, if any, and a WrapObject() which will
// try to create a wrapper. Typically, this is done by having "value" inherit
// from nsWrapperCache.
// Create a JSObject wrapping "value", for cases when "value" is a
// non-wrapper-cached object using WebIDL bindings. "value" must implement a
// WrapObject() method taking a JSContext and a scope.
template <class T>
inline bool
WrapNewBindingNonWrapperCachedObject(JSContext* cx, JSObject* scope, T* value,
@ -948,7 +963,13 @@ struct WrapNativeParentHelper
}
bool triedToWrap;
obj = parent->WrapObject(cx, scope, &triedToWrap);
// Inline this here while we have non-dom objects in wrapper caches.
if (!CouldBeDOMBinding(parent)) {
triedToWrap = false;
} else {
obj = parent->WrapObject(cx, scope, &triedToWrap);
}
if (!triedToWrap) {
obj = WrapNativeParentFallback<T>::Wrap(cx, scope, parent, cache);
}