aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4regexpobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-09-02 14:25:15 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-02 17:27:36 +0200
commitea0ea907edbe7dd0c65f10752d7df1de6f0fd63b (patch)
treec9e0641d43cd19dfc3ad022c34e196592e22a6cb /src/qml/jsruntime/qv4regexpobject.cpp
parent6359ab63cd9c730a168e8b8da4c275e2d03d25d5 (diff)
Optimize String.replace and RegExp.exec
This speeds up the v8 regexp benchmark by a factor 2.5 :) Change-Id: Ibd6b18ee28181aa712429cbec4598984e0c69820 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4regexpobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4regexpobject.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp
index cd104c0a71..c213c78aeb 100644
--- a/src/qml/jsruntime/qv4regexpobject.cpp
+++ b/src/qml/jsruntime/qv4regexpobject.cpp
@@ -177,7 +177,7 @@ void RegExpObject::markObjects(Managed *that)
Property *RegExpObject::lastIndexProperty(ExecutionContext *ctx)
{
- assert(0 == internalClass->find(ctx->engine->newIdentifier(QStringLiteral("lastIndex"))));
+ Q_ASSERT(0 == internalClass->find(ctx->engine->newIdentifier(QStringLiteral("lastIndex"))));
return &memberData[0];
}
@@ -317,18 +317,19 @@ Value RegExpPrototype::method_exec(SimpleCallContext *ctx)
}
// fill in result data
- ArrayObject *array = ctx->engine->newArrayObject();
- for (int i = 0; i < r->value->captureCount(); ++i) {
+ ArrayObject *array = ctx->engine->newArrayObject(ctx->engine->regExpExecArrayClass);
+ int len = r->value->captureCount();
+ array->arrayReserve(len);
+ for (int i = 0; i < len; ++i) {
int start = matchOffsets[i * 2];
int end = matchOffsets[i * 2 + 1];
- Value entry = Value::undefinedValue();
- if (start != -1 && end != -1)
- entry = Value::fromString(ctx, s.mid(start, end - start));
- array->push_back(entry);
+ array->arrayData[i].value = (start != -1 && end != -1) ? Value::fromString(ctx, s.mid(start, end - start)) : Value::undefinedValue();
}
+ array->arrayDataLen = len;
+ array->setArrayLengthUnchecked(len);
- array->put(ctx, QLatin1String("index"), Value::fromInt32(result));
- array->put(ctx, QLatin1String("input"), arg);
+ array->memberData[Index_ArrayIndex].value = Value::fromInt32(result);
+ array->memberData[Index_ArrayInput].value = arg;
if (r->global)
r->lastIndexProperty(ctx)->value = Value::fromInt32(matchOffsets[1]);