aboutsummaryrefslogtreecommitdiffstats
path: root/qmljs_engine.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2012-11-28 13:39:14 +0100
committerLars Knoll <lars.knoll@digia.com>2012-11-28 14:06:06 +0100
commit721f2156a6c1ba77dd2c12bf06b7a3dcb0ea0b2c (patch)
treee0751c940c73433e91ea405f7842951006685f9b /qmljs_engine.cpp
parentbc88b706e2b894b4b5ae0977e3477a85b6762bc1 (diff)
Introduce a simple string pool to speed up lookups.
This change uniques string pointers, so the String::isEqualTo will more often succeed in the pointer-equality case. Change-Id: I1d4f1a70147c48bc75359642a56a0446b5fbf199 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'qmljs_engine.cpp')
-rw-r--r--qmljs_engine.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/qmljs_engine.cpp b/qmljs_engine.cpp
index 6ac7250aef..7d12df5ace 100644
--- a/qmljs_engine.cpp
+++ b/qmljs_engine.cpp
@@ -45,9 +45,26 @@
namespace QQmlJS {
namespace VM {
+struct StringPool
+{
+ QHash<QString, String*> strings;
+
+ String *newString(const QString &s)
+ {
+ QHash<QString, String*>::const_iterator it = strings.find(s);
+ if (it != strings.end())
+ return it.value();
+ String *str = new String(s);
+ strings.insert(s, str);
+ return str;
+ }
+};
+
ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
: iselFactory(factory)
{
+ stringPool = new StringPool;
+
rootContext = newContext();
rootContext->init(this);
@@ -213,7 +230,7 @@ FunctionObject *ExecutionEngine::newObjectCtor(ExecutionContext *ctx)
String *ExecutionEngine::newString(const QString &s)
{
- return new String(s);
+ return stringPool->newString(s);
}
Object *ExecutionEngine::newStringObject(const Value &value)