aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-09-08 12:47:52 +0200
committerLars Knoll <lars.knoll@theqtcompany.com>2015-09-25 08:38:40 +0000
commit3f12ee31a4dae822fd8e9d3a6791157d8503c653 (patch)
treedc3bdde5f4b10524412785069f2c6ab00c78d126 /src/qml/jsruntime
parent9848a5ed241fbbccae850e13764d3e96ab422b62 (diff)
Add method to convert identifiers back into QV4::String objects
Allocating a new String for the Identifier is wasting both memory and CPU. Let's rather extract it from the IdentifierTable. Change-Id: Ibb9b2ac9775fefce74602d6954586195cdd5814e Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4identifiertable.cpp16
-rw-r--r--src/qml/jsruntime/qv4identifiertable_p.h2
-rw-r--r--src/qml/jsruntime/qv4object.cpp3
3 files changed, 20 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4identifiertable.cpp b/src/qml/jsruntime/qv4identifiertable.cpp
index 138d76bf4a..a5336ee44f 100644
--- a/src/qml/jsruntime/qv4identifiertable.cpp
+++ b/src/qml/jsruntime/qv4identifiertable.cpp
@@ -149,6 +149,22 @@ Identifier *IdentifierTable::identifierImpl(const Heap::String *str)
return str->identifier;
}
+Heap::String *IdentifierTable::stringFromIdentifier(Identifier *i)
+{
+ if (!i)
+ return 0;
+
+ uint idx = i->hashValue % alloc;
+ while (1) {
+ Heap::String *e = entries[idx];
+ Q_ASSERT(e);
+ if (e->identifier == i)
+ return e;
+ ++idx;
+ idx %= alloc;
+ }
+}
+
Identifier *IdentifierTable::identifier(const QString &s)
{
return insertString(s)->identifier;
diff --git a/src/qml/jsruntime/qv4identifiertable_p.h b/src/qml/jsruntime/qv4identifiertable_p.h
index 58f808b4d5..d91ce623c1 100644
--- a/src/qml/jsruntime/qv4identifiertable_p.h
+++ b/src/qml/jsruntime/qv4identifiertable_p.h
@@ -74,6 +74,8 @@ public:
Identifier *identifierImpl(const Heap::String *str);
+ Heap::String *stringFromIdentifier(Identifier *i);
+
void mark(ExecutionEngine *e) {
for (int i = 0; i < alloc; ++i) {
Heap::String *entry = entries[i];
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp
index 42cc3c7df4..ee3539c176 100644
--- a/src/qml/jsruntime/qv4object.cpp
+++ b/src/qml/jsruntime/qv4object.cpp
@@ -44,6 +44,7 @@
#include "qv4objectiterator_p.h"
#include "qv4identifier_p.h"
#include "qv4string_p.h"
+#include "qv4identifiertable_p.h"
#include <stdint.h>
@@ -590,7 +591,7 @@ void Object::advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *
PropertyAttributes a = o->internalClass()->propertyData[it->memberIndex];
++it->memberIndex;
if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) {
- name->setM(o->engine()->newString(n->string));
+ name->setM(o->engine()->identifierTable->stringFromIdentifier(n));
*attrs = a;
pd->value = *o->propertyData(idx);
if (a.isAccessor())