Bug 501230 - TM: fast path for String.toString (r=gal).
This commit is contained in:
@@ -4733,6 +4733,48 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
|
||||
v = save = OBJECT_TO_JSVAL(obj);
|
||||
switch (hint) {
|
||||
case JSTYPE_STRING:
|
||||
/*
|
||||
* Optimize for String objects with standard toString methods. Support
|
||||
* new String(...) instances whether mutated to have their own scope or
|
||||
* not, as well as direct String.prototype references.
|
||||
*/
|
||||
if (OBJ_GET_CLASS(cx, obj) == &js_StringClass) {
|
||||
jsid toStringId = ATOM_TO_JSID(cx->runtime->atomState.toStringAtom);
|
||||
|
||||
JS_LOCK_OBJ(cx, obj);
|
||||
JSScope *scope = OBJ_SCOPE(obj);
|
||||
JSScopeProperty *sprop = scope->lookup(toStringId);
|
||||
|
||||
if (!sprop && scope->object == obj) {
|
||||
JSObject *proto = LOCKED_OBJ_GET_PROTO(obj);
|
||||
|
||||
if (proto && OBJ_GET_CLASS(cx, proto) == &js_StringClass) {
|
||||
JS_UNLOCK_SCOPE(cx, scope);
|
||||
JS_LOCK_OBJ(cx, proto);
|
||||
scope = OBJ_SCOPE(proto);
|
||||
sprop = scope->lookup(toStringId);
|
||||
}
|
||||
}
|
||||
|
||||
if (sprop &&
|
||||
SPROP_HAS_STUB_GETTER(sprop) &&
|
||||
SPROP_HAS_VALID_SLOT(sprop, scope)) {
|
||||
jsval fval = LOCKED_OBJ_GET_SLOT(scope->object, sprop->slot);
|
||||
|
||||
if (VALUE_IS_FUNCTION(cx, fval)) {
|
||||
JSObject *funobj = JSVAL_TO_OBJECT(fval);
|
||||
JSFunction *fun = GET_FUNCTION_PRIVATE(cx, funobj);
|
||||
|
||||
if (FUN_FAST_NATIVE(fun) == js_str_toString) {
|
||||
JS_UNLOCK_SCOPE(cx, scope);
|
||||
*vp = obj->fslots[JSSLOT_PRIVATE];
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
JS_UNLOCK_SCOPE(cx, scope);
|
||||
}
|
||||
|
||||
/*
|
||||
* Propagate the exception if js_TryMethod finds an appropriate
|
||||
* method, and calling that method returned failure.
|
||||
|
||||
Reference in New Issue
Block a user