aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4stringobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-01-03 15:37:32 +0100
committerLars Knoll <lars.knoll@qt.io>2018-01-19 10:13:54 +0000
commit1fe206712755b0d99f91bc7897f0a705ec583f2d (patch)
treeb5fee1288c60f8d9b60e7b5147ab7ebe4c6b1a2c /src/qml/jsruntime/qv4stringobject.cpp
parent959ad9f998c340257a4027db4bed3a5639a8f48f (diff)
Introduce a SubString String type
Use it in regexp matching. There's probably other places where we should use this as well. Change-Id: Ie2774acff0a5ec7b1c26c564fa40e65fecea29d4 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4stringobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4stringobject.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp
index b4c50170cf..4cc4a5c0cb 100644
--- a/src/qml/jsruntime/qv4stringobject.cpp
+++ b/src/qml/jsruntime/qv4stringobject.cpp
@@ -200,6 +200,15 @@ void StringPrototype::init(ExecutionEngine *engine, Object *ctor)
defineDefaultProperty(QStringLiteral("trim"), method_trim);
}
+static Heap::String *thisAsString(ExecutionEngine *v4, const Value *thisObject)
+{
+ if (String *s = thisObject->stringValue())
+ return s->d();
+ if (const StringObject *thisString = thisObject->as<StringObject>())
+ return thisString->d()->string;
+ return thisObject->toString(v4);
+}
+
static QString getThisString(ExecutionEngine *v4, const Value *thisObject)
{
if (String *s = thisObject->stringValue())
@@ -649,11 +658,12 @@ ReturnedValue StringPrototype::method_search(const FunctionObject *b, const Valu
ReturnedValue StringPrototype::method_slice(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
{
ExecutionEngine *v4 = b->engine();
- const QString text = getThisString(v4, thisObject);
+ Heap::String *s = thisAsString(v4, thisObject);
if (v4->hasException)
return QV4::Encode::undefined();
+ Q_ASSERT(s);
- const double length = text.length();
+ const double length = s->length();
double start = argc ? argv[0].toInteger() : 0;
double end = (argc < 2 || argv[1].isUndefined())
@@ -673,7 +683,7 @@ ReturnedValue StringPrototype::method_slice(const FunctionObject *b, const Value
const int intEnd = int(end);
int count = qMax(0, intEnd - intStart);
- return Encode(v4->newString(text.mid(intStart, count)));
+ return Encode(v4->memoryManager->alloc<ComplexString>(s, intStart, count));
}
ReturnedValue StringPrototype::method_split(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)