From c903f0e3285b3e0d6bf26f5e7c80a5b4116f5458 Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Wed, 14 May 2003 14:51:00 +0000 Subject: [PATCH] In getByGetter/setBySetter with slot.delegateTo avoid potentially expensive checks for start type if this == start. git-svn-id: svn://10.0.0.236/trunk@142438 18797224-902f-48f8-a5cc-f745e15eee43 --- .../mozilla/javascript/ScriptableObject.java | 51 ++++++++++++------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/ScriptableObject.java b/mozilla/js/rhino/src/org/mozilla/javascript/ScriptableObject.java index e1f8dc00c20..21525f854b6 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/ScriptableObject.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/ScriptableObject.java @@ -179,30 +179,38 @@ public abstract class ScriptableObject implements Scriptable, Serializable, } private Object getByGetter(GetterSlot slot, Scriptable start) { - try { - if (slot.delegateTo == null) { + Object getterThis; + Object[] args; + if (slot.delegateTo == null) { + if (start != this) { // Walk the prototype chain to find an appropriate // object to invoke the getter on. Class clazz = slot.getter.getDeclaringClass(); while (!clazz.isInstance(start)) { start = start.getPrototype(); + if (start == this) { + break; + } if (start == null) { start = this; break; } } - return slot.getter.invoke(start, ScriptRuntime.emptyArgs); } - Object[] args = { this }; - return slot.getter.invoke(slot.delegateTo, args); - } - catch (InvocationTargetException e) { - throw WrappedException.wrapException(e); - } - catch (IllegalAccessException e) { - throw WrappedException.wrapException(e); + getterThis = start; + args = ScriptRuntime.emptyArgs; + } else { + getterThis = slot.delegateTo; + args = new Object[] { this }; } + try { + return slot.getter.invoke(getterThis, args); + } catch (InvocationTargetException e) { + throw WrappedException.wrapException(e); + } catch (IllegalAccessException e) { + throw WrappedException.wrapException(e); + } } /** @@ -273,14 +281,19 @@ public abstract class ScriptableObject implements Scriptable, Serializable, Object actualArg = FunctionObject.convertArg(cx, start, value, desired); if (slot.delegateTo == null) { - // Walk the prototype chain to find an appropriate - // object to invoke the setter on. - Class clazz = slot.setter.getDeclaringClass(); - while (!clazz.isInstance(start)) { - start = start.getPrototype(); - if (start == null) { - start = this; - break; + if (start != this) { + // Walk the prototype chain to find an appropriate + // object to invoke the setter on. + Class clazz = slot.setter.getDeclaringClass(); + while (!clazz.isInstance(start)) { + start = start.getPrototype(); + if (start == this) { + break; + } + if (start == null) { + start = this; + break; + } } } setterThis = start;