Get rid of hasAccessorProperty in Heap::Base
authorLars Knoll <lars.knoll@theqtcompany.com>
Fri, 9 Jan 2015 12:13:04 +0000 (13:13 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 12 Jan 2015 10:04:19 +0000 (11:04 +0100)
This shouldn't affect performance as we can just as well
check for cases where we need to take the slow path
differently.

Change-Id: I4b9f69c39e9e64b437820ca3a6ea43e8877f2cf3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4argumentsobject.cpp
src/qml/jsruntime/qv4arraydata.cpp
src/qml/jsruntime/qv4arrayobject.cpp
src/qml/jsruntime/qv4functionobject.cpp
src/qml/jsruntime/qv4object.cpp
src/qml/jsruntime/qv4object_p.h
src/qml/jsruntime/qv4value_p.h

index f089808..33529db 100644 (file)
@@ -64,7 +64,6 @@ Heap::ArgumentsObject::ArgumentsObject(QV4::CallContext *context)
         args->arrayPut(0, context->d()->callData->args, context->d()->callData->argc);
         args->d()->fullyCreated = true;
     } else {
-        args->setHasAccessorProperty();
         Q_ASSERT(CalleePropertyIndex == args->internalClass()->find(context->d()->engine->id_callee));
         args->memberData()->data[CalleePropertyIndex] = context->d()->function->asReturnedValue();
     }
index f027743..a4f67c7 100644 (file)
@@ -35,6 +35,7 @@
 #include "qv4functionobject_p.h"
 #include "qv4mm_p.h"
 #include "qv4runtime_p.h"
+#include "qv4argumentsobject_p.h"
 
 using namespace QV4;
 
@@ -570,9 +571,13 @@ uint ArrayData::append(Object *obj, ArrayObject *otherObj, uint n)
 
     uint oldSize = obj->getLength();
 
-    if (other && other->isSparse()) {
+    if (!other || ArgumentsObject::isNonStrictArgumentsObject(otherObj)) {
+        ScopedValue v(scope);
+        for (uint i = 0; i < n; ++i)
+            obj->arraySet(oldSize + i, (v = otherObj->getIndexed(i)));
+    } else if (other && other->isSparse()) {
         Heap::SparseArrayData *os = static_cast<Heap::SparseArrayData *>(other->d());
-        if (otherObj->hasAccessorProperty() && other->hasAttributes()) {
+        if (other->hasAttributes()) {
             ScopedValue v(scope);
             for (const SparseArrayNode *it = os->sparse->begin();
                  it != os->sparse->end(); it = it->nextNode()) {
index 2d6955e..1186afb 100644 (file)
@@ -35,6 +35,7 @@
 #include "qv4sparsearray_p.h"
 #include "qv4objectproto_p.h"
 #include "qv4scopedvalue_p.h"
+#include "qv4argumentsobject_p.h"
 #include "qv4runtime_p.h"
 
 using namespace QV4;
@@ -605,7 +606,8 @@ ReturnedValue ArrayPrototype::method_indexOf(CallContext *ctx)
 
     ScopedValue value(scope);
 
-    if (instance->hasAccessorProperty() || (instance->arrayType() >= Heap::ArrayData::Sparse) || instance->protoHasArray()) {
+    if (ArgumentsObject::isNonStrictArgumentsObject(instance) ||
+        (instance->arrayType() >= Heap::ArrayData::Sparse) || instance->protoHasArray()) {
         // lets be safe and slow
         for (uint i = fromIndex; i < len; ++i) {
             bool exists;
index 200d955..3b0d723 100644 (file)
@@ -326,7 +326,7 @@ ReturnedValue FunctionPrototype::method_apply(CallContext *ctx)
     ScopedCallData callData(scope, len);
 
     if (len) {
-        if (arr->arrayType() != Heap::ArrayData::Simple || arr->protoHasArray() || arr->hasAccessorProperty()) {
+        if (arr->arrayType() != Heap::ArrayData::Simple || arr->protoHasArray()) {
             for (quint32 i = 0; i < len; ++i)
                 callData->args[i] = arr->getIndexed(i);
         } else {
index cc7171d..d30c113 100644 (file)
@@ -210,7 +210,6 @@ void Object::insertMember(String *s, const Property *p, PropertyAttributes attri
     ensureMemberIndex(internalClass()->size);
 
     if (attributes.isAccessor()) {
-        setHasAccessorProperty();
         Property *pp = propertyAt(idx);
         pp->value = p->value;
         pp->set = p->set;
@@ -882,8 +881,6 @@ bool Object::__defineOwnProperty__(ExecutionEngine *engine, String *name, const
             cattrs->setWritable(false);
         if (!succeeded)
             goto reject;
-        if (attrs.isAccessor())
-            setHasAccessorProperty();
         return true;
     }
 
@@ -1047,8 +1044,6 @@ bool Object::__defineOwnProperty__(ExecutionEngine *engine, uint index, String *
     } else {
         setArrayAttributes(index, cattrs);
     }
-    if (cattrs.isAccessor())
-        setHasAccessorProperty();
     return true;
   reject:
     if (engine->currentContext()->strictMode)
@@ -1070,7 +1065,8 @@ void Object::copyArrayData(Object *other)
     Q_ASSERT(isArrayObject());
     Scope scope(engine());
 
-    if (other->protoHasArray() || other->hasAccessorProperty()) {
+    if (other->protoHasArray() || ArgumentsObject::isNonStrictArgumentsObject(other) ||
+        (other->arrayType() == Heap::ArrayData::Sparse && other->arrayData()->attrs)) {
         uint len = other->getLength();
         Q_ASSERT(len);
 
@@ -1080,14 +1076,6 @@ void Object::copyArrayData(Object *other)
         }
     } else if (!other->arrayData()) {
         ;
-    } else if (other->hasAccessorProperty() && other->d()->arrayData->attrs && other->d()->arrayData->isSparse()){
-        // do it the slow way
-        ScopedValue v(scope);
-        Heap::ArrayData *osa = other->d()->arrayData;
-        for (const SparseArrayNode *it = osa->sparse->begin(); it != osa->sparse->end(); it = it->nextNode()) {
-            v = other->getValue(reinterpret_cast<Property *>(osa->arrayData + it->value), osa->attrs[it->value]);
-            arraySet(it->key(), v);
-        }
     } else {
         Q_ASSERT(!arrayData() && other->arrayData());
         ArrayData::realloc(this, other->d()->arrayData->type, other->d()->arrayData->alloc, false);
index c256b1f..a38750d 100644 (file)
@@ -140,9 +140,6 @@ struct Q_QML_EXPORT Object: Managed {
 
     inline ExecutionEngine *engine() const { return internalClass()->engine; }
 
-    inline bool hasAccessorProperty() const { return d()->hasAccessorProperty; }
-    inline void setHasAccessorProperty() { d()->hasAccessorProperty = true; }
-
     bool isExtensible() const { return d()->extensible; }
     void setExtensible(bool b) { d()->extensible = b; }
 
@@ -367,10 +364,7 @@ inline void Object::arraySet(uint index, const Property *p, PropertyAttributes a
 {
     // ### Clean up
     arrayCreate();
-    if (attributes.isAccessor()) {
-        setHasAccessorProperty();
-        initSparseArray();
-    } else if (index > 0x1000 && index > 2*d()->arrayData->alloc) {
+    if (attributes.isAccessor() || (index > 0x1000 && index > 2*d()->arrayData->alloc)) {
         initSparseArray();
     } else {
         arrayData()->vtable()->reallocate(this, index + 1, false);
index 1a5ccb8..f7855b0 100644 (file)
@@ -64,7 +64,7 @@ struct Q_QML_EXPORT Base {
         uchar _needsActivation : 1; // used by FunctionObject
         uchar _strictMode : 1; // used by FunctionObject
         uchar _bindingKeyFlag : 1;
-        uchar hasAccessorProperty : 1;
+        uchar _hasAccessorProperty : 1;
         uchar _unused : 1;
         mutable uchar subtype;
         uchar _unused2;