Some minor optimizations
authorLars Knoll <lars.knoll@digia.com>
Tue, 15 Oct 2013 20:27:10 +0000 (22:27 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sat, 19 Oct 2013 12:59:02 +0000 (14:59 +0200)
Change-Id: Ib2e08e7c89ca59a48f8fd52b30981e5d7e60803b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4mm.cpp
src/qml/jsruntime/qv4mm_p.h
src/qml/jsruntime/qv4object.cpp
src/qml/jsruntime/qv4object_p.h

index 6fe49cd..a03f286 100644 (file)
@@ -286,7 +286,9 @@ Managed *MemoryManager::alloc(std::size_t size)
         std::sort(m_d->heapChunks.begin(), m_d->heapChunks.end());
         char *chunk = (char *)allocation.memory.base();
         char *end = chunk + allocation.memory.size() - size;
+#ifndef QT_NO_DEBUG
         memset(chunk, 0, allocation.memory.size());
+#endif
         Managed **last = &m_d->smallItems[pos];
         while (chunk <= end) {
             Managed *o = reinterpret_cast<Managed *>(chunk);
@@ -396,7 +398,7 @@ void MemoryManager::mark()
     }
 }
 
-std::size_t MemoryManager::sweep(bool lastSweep)
+void MemoryManager::sweep(bool lastSweep)
 {
     PersistentValuePrivate *weak = m_weakValues;
     while (weak) {
@@ -428,12 +430,11 @@ std::size_t MemoryManager::sweep(bool lastSweep)
         }
     }
 
-    std::size_t freedCount = 0;
     GCDeletable *deletable = 0;
     GCDeletable **firstDeletable = &deletable;
 
     for (QVector<Data::Chunk>::iterator i = m_d->heapChunks.begin(), ei = m_d->heapChunks.end(); i != ei; ++i)
-        freedCount += sweep(reinterpret_cast<char*>(i->memory.base()), i->memory.size(), i->chunkSize, &deletable);
+        sweep(reinterpret_cast<char*>(i->memory.base()), i->memory.size(), i->chunkSize, &deletable);
 
     ExecutionContext *ctx = m_contextList;
     ExecutionContext **n = &m_contextList;
@@ -456,15 +457,11 @@ std::size_t MemoryManager::sweep(bool lastSweep)
         delete deletable;
         deletable = next;
     }
-
-    return freedCount;
 }
 
-std::size_t MemoryManager::sweep(char *chunkStart, std::size_t chunkSize, size_t size, GCDeletable **deletable)
+void MemoryManager::sweep(char *chunkStart, std::size_t chunkSize, size_t size, GCDeletable **deletable)
 {
 //    qDebug("chunkStart @ %p, size=%x, pos=%x (%x)", chunkStart, size, size>>4, m_d->smallItems[size >> 4]);
-    std::size_t freedCount = 0;
-
     Managed **f = &m_d->smallItems[size >> 4];
 
 #ifdef V4_USE_VALGRIND
@@ -496,15 +493,12 @@ std::size_t MemoryManager::sweep(char *chunkStart, std::size_t chunkSize, size_t
 #endif
                 *f = m;
                 SCRIBBLE(m, 0x99, size);
-                ++freedCount;
             }
         }
     }
 #ifdef V4_USE_VALGRIND
     VALGRIND_ENABLE_ERROR_REPORTING;
 #endif
-
-    return freedCount;
 }
 
 bool MemoryManager::isGCBlocked() const
index abbc0a7..95f4954 100644 (file)
@@ -132,8 +132,8 @@ private:
     void collectFromStack() const;
     void collectFromJSStack() const;
     void mark();
-    std::size_t sweep(bool lastSweep = false);
-    std::size_t sweep(char *chunkStart, std::size_t chunkSize, size_t size, GCDeletable **deletable);
+    void sweep(bool lastSweep = false);
+    void sweep(char *chunkStart, std::size_t chunkSize, size_t size, GCDeletable **deletable);
 
 protected:
     QScopedPointer<Data> m_d;
index 795362e..b04c651 100644 (file)
@@ -241,19 +241,39 @@ void Object::markObjects(Managed *that)
 {
     Object *o = static_cast<Object *>(that);
 
-    for (int i = 0; i < o->internalClass->size; ++i) {
-        const Property &pd = o->memberData[i];
-        if (o->internalClass->propertyData[i].isData()) {
-            if (Managed *m = pd.value.asManaged())
-                m->mark();
-         } else {
-            if (pd.getter())
-                pd.getter()->mark();
-            if (pd.setter())
-                pd.setter()->mark();
+    if (!o->hasAccessorProperty) {
+        for (int i = 0; i < o->internalClass->size; ++i)
+            o->memberData[i].value.mark();
+    } else {
+        for (int i = 0; i < o->internalClass->size; ++i) {
+            const Property &pd = o->memberData[i];
+            if (o->internalClass->propertyData[i].isAccessor()) {
+                if (pd.getter())
+                    pd.getter()->mark();
+                if (pd.setter())
+                    pd.setter()->mark();
+            } else {
+                pd.value.mark();
+            }
+        }
+    }
+    if (o->flags & SimpleArray) {
+        for (uint i = 0; i < o->arrayDataLen; ++i)
+            o->arrayData[i].value.mark();
+        return;
+    } else {
+        for (uint i = 0; i < o->arrayDataLen; ++i) {
+            const Property &pd = o->arrayData[i];
+            if (o->arrayAttributes && o->arrayAttributes[i].isAccessor()) {
+                if (pd.getter())
+                    pd.getter()->mark();
+                if (pd.setter())
+                    pd.setter()->mark();
+            } else {
+                pd.value.mark();
+            }
         }
     }
-    o->markArrayObjects();
 }
 
 void Object::ensureMemberIndex(uint idx)
@@ -1374,22 +1394,6 @@ bool Object::setArrayLength(uint newLen) {
     return ok;
 }
 
-void Object::markArrayObjects() const
-{
-    for (uint i = 0; i < arrayDataLen; ++i) {
-        const Property &pd = arrayData[i];
-        if (!arrayAttributes || arrayAttributes[i].isData()) {
-            if (Managed *m = pd.value.asManaged())
-                m->mark();
-         } else if (arrayAttributes[i].isAccessor()) {
-            if (pd.getter())
-                pd.getter()->mark();
-            if (pd.setter())
-                pd.setter()->mark();
-        }
-    }
-}
-
 DEFINE_MANAGED_VTABLE(ArrayObject);
 
 ArrayObject::ArrayObject(ExecutionEngine *engine, const QStringList &list)
index 8807f60..097d40d 100644 (file)
@@ -255,8 +255,6 @@ public:
         return arrayData + index;
     }
 
-    void markArrayObjects() const;
-
     void push_back(const ValueRef v);
 
     SparseArrayNode *sparseArrayBegin() { return sparseArray ? sparseArray->begin() : 0; }