Inline some code for property lookups
authorLars Knoll <lars.knoll@digia.com>
Wed, 30 Jan 2013 14:43:22 +0000 (15:43 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Wed, 30 Jan 2013 16:33:29 +0000 (17:33 +0100)
Speeds up fact.2.js and crypto.js by ~5-10%

Change-Id: I121b6c3dbbd89060f323a422286adf946d4f924a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/v4/qv4object.cpp

index e9e3d78..6f5fb60 100644 (file)
@@ -276,10 +276,16 @@ Value Object::__get__(ExecutionContext *ctx, String *name, bool *hasProperty)
         return Value::fromObject(prototype);
     }
 
-    if (PropertyDescriptor *p = __getPropertyDescriptor__(ctx, name)) {
-        if (hasProperty)
-            *hasProperty = true;
-        return getValue(ctx, p);
+    Object *o = this;
+    while (o) {
+        if (o->members) {
+            if (PropertyDescriptor *p = o->members->find(name)) {
+                if (hasProperty)
+                    *hasProperty = true;
+                return getValue(ctx, p);
+            }
+        }
+        o = o->prototype;
     }
 
     if (hasProperty)
@@ -289,11 +295,28 @@ Value Object::__get__(ExecutionContext *ctx, String *name, bool *hasProperty)
 
 Value Object::__get__(ExecutionContext *ctx, uint index, bool *hasProperty)
 {
-    const PropertyDescriptor *p = __getPropertyDescriptor__(ctx, index);
-    if (p && p->type != PropertyDescriptor::Generic) {
+    PropertyDescriptor *pd = 0;
+    Object *o = this;
+    while (o) {
+        PropertyDescriptor *p = o->array.at(index);
+        if (p && p->type != PropertyDescriptor::Generic) {
+            pd = p;
+            break;
+        }
+        if (o->isStringObject()) {
+            p = static_cast<StringObject *>(o)->getIndex(ctx, index);
+            if (p) {
+                pd = p;
+                break;
+            }
+        }
+        o = o->prototype;
+    }
+
+    if (pd) {
         if (hasProperty)
             *hasProperty = true;
-        return getValue(ctx, p);
+        return getValue(ctx, pd);
     }
 
     if (hasProperty)