Inline some code only used from one place
authorLars Knoll <lars.knoll@digia.com>
Tue, 5 Feb 2013 21:13:27 +0000 (22:13 +0100)
committerErik Verbruggen <erik.verbruggen@digia.com>
Wed, 6 Feb 2013 15:02:21 +0000 (16:02 +0100)
Cleans up the qv4object class definition.

Change-Id: Ifca7f89afb3affce5d940b1b4f7dcfe71779012c
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
src/v4/qv4arrayobject.cpp
src/v4/qv4object.cpp
src/v4/qv4object.h

index bec7c22..3079c52 100644 (file)
@@ -322,7 +322,19 @@ Value ArrayPrototype::method_shift(ExecutionContext *ctx)
         return Value::undefinedValue();
     }
 
-    Value result = instance->getValueChecked(ctx, instance->front());
+    PropertyDescriptor *front = 0;
+    if (!instance->sparseArray) {
+        if (instance->arrayDataLen)
+            front = instance->arrayData;
+    } else {
+        SparseArrayNode *n = instance->sparseArray->findNode(0);
+        if (n)
+            front = instance->arrayDecriptor(n->value);
+    }
+    if (front && front->type == PropertyDescriptor::Generic)
+        front = 0;
+
+    Value result = instance->getValueChecked(ctx, front);
 
     bool protoHasArray = false;
     Object *p = instance;
index dda340b..d8231b5 100644 (file)
@@ -551,8 +551,29 @@ bool Object::__delete__(ExecutionContext *ctx, String *name)
 
 bool Object::__delete__(ExecutionContext *ctx, uint index)
 {
-    if (deleteArrayIndex(index))
+    PropertyDescriptor *pd = 0;
+    if (!sparseArray) {
+        if (index >= arrayDataLen)
+            return true;
+        pd = arrayAt(index);
+    } else {
+        SparseArrayNode *n = sparseArray->findNode(index);
+        if (n)
+            pd = arrayDecriptor(n->value);
+    }
+    if (!pd || pd->type == PropertyDescriptor::Generic)
         return true;
+
+    if (pd->isConfigurable()) {
+        pd->type = PropertyDescriptor::Generic;
+        pd->value = Value::undefinedValue();
+        if (sparseArray) {
+            pd->value.int_32 = arrayFreeList;
+            arrayFreeList = pd - arrayData;
+        }
+        return true;
+    }
+
     if (ctx->strictMode)
         __qmljs_throw_type_error(ctx);
     return false;
index c9a4337..7f99668 100644 (file)
@@ -259,30 +259,6 @@ public:
         fillDescriptor(pd, value);
     }
 
-    bool deleteArrayIndex(uint index) {
-        PropertyDescriptor *pd = 0;
-        if (!sparseArray) {
-            if (index >= arrayDataLen)
-                return true;
-            pd = arrayAt(index);
-        } else {
-            SparseArrayNode *n = sparseArray->findNode(index);
-            if (n)
-                pd = arrayDecriptor(n->value);
-        }
-        if (!pd || pd->type == PropertyDescriptor::Generic)
-            return true;
-        if (!pd->isConfigurable())
-            return false;
-        pd->type = PropertyDescriptor::Generic;
-        pd->value = Value::undefinedValue();
-        if (sparseArray) {
-            pd->value.int_32 = arrayFreeList;
-            arrayFreeList = pd - arrayData;
-        }
-        return true;
-    }
-
     PropertyDescriptor *arrayAt(uint index) const {
         if (!sparseArray) {
             if (index >= arrayDataLen)
@@ -306,20 +282,6 @@ public:
 
     void markArrayObjects() const;
 
-    PropertyDescriptor *front() {
-        PropertyDescriptor *pd = 0;
-        if (!sparseArray) {
-            if (arrayDataLen)
-                pd = arrayData;
-        } else {
-            SparseArrayNode *n = sparseArray->findNode(0);
-            if (n)
-                pd = arrayDecriptor(n->value);
-        }
-        if (pd && pd->type == PropertyDescriptor::Generic)
-            return 0;
-        return pd;
-    }
     void push_back(Value v) {
         uint idx = arrayLength();
         if (!sparseArray) {