From f0eaaef4aeb6fa8951cca1e1e90def3411896e9f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 15 Oct 2013 22:27:10 +0200 Subject: [PATCH] Some minor optimizations Change-Id: Ib2e08e7c89ca59a48f8fd52b30981e5d7e60803b Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4mm.cpp | 16 ++++-------- src/qml/jsruntime/qv4mm_p.h | 4 +-- src/qml/jsruntime/qv4object.cpp | 58 ++++++++++++++++++++++------------------- src/qml/jsruntime/qv4object_p.h | 2 -- 4 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/qml/jsruntime/qv4mm.cpp b/src/qml/jsruntime/qv4mm.cpp index 6fe49cd..a03f286 100644 --- a/src/qml/jsruntime/qv4mm.cpp +++ b/src/qml/jsruntime/qv4mm.cpp @@ -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(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::iterator i = m_d->heapChunks.begin(), ei = m_d->heapChunks.end(); i != ei; ++i) - freedCount += sweep(reinterpret_cast(i->memory.base()), i->memory.size(), i->chunkSize, &deletable); + sweep(reinterpret_cast(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 diff --git a/src/qml/jsruntime/qv4mm_p.h b/src/qml/jsruntime/qv4mm_p.h index abbc0a7..95f4954 100644 --- a/src/qml/jsruntime/qv4mm_p.h +++ b/src/qml/jsruntime/qv4mm_p.h @@ -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 m_d; diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 795362e..b04c651 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -241,19 +241,39 @@ void Object::markObjects(Managed *that) { Object *o = static_cast(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) diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 8807f60..097d40d 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -255,8 +255,6 @@ public: return arrayData + index; } - void markArrayObjects() const; - void push_back(const ValueRef v); SparseArrayNode *sparseArrayBegin() { return sparseArray ? sparseArray->begin() : 0; } -- 2.7.4