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>
This commit is contained in:
parent
bc88b706e2
commit
721f2156a6
|
@ -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)
|
||||
|
|
|
@ -140,6 +140,8 @@ struct ExecutionEngine
|
|||
QVector<ExceptionHandler> unwindStack;
|
||||
Value exception;
|
||||
|
||||
struct StringPool *stringPool;
|
||||
|
||||
ExecutionEngine(EvalISelFactory *iselFactory);
|
||||
|
||||
ExecutionContext *newContext();
|
||||
|
|
Loading…
Reference in New Issue