diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-01-03 15:37:32 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-01-19 10:13:54 +0000 |
commit | 1fe206712755b0d99f91bc7897f0a705ec583f2d (patch) | |
tree | b5fee1288c60f8d9b60e7b5147ab7ebe4c6b1a2c /src/qml/jsruntime/qv4string.cpp | |
parent | 959ad9f998c340257a4027db4bed3a5639a8f48f (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/qv4string.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4string.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index bdfb8af3f6..932ccf13ef 100644 --- a/src/qml/jsruntime/qv4string.cpp +++ b/src/qml/jsruntime/qv4string.cpp @@ -59,8 +59,13 @@ void Heap::String::markObjects(Heap::Base *that, MarkStack *markStack) return; ComplexString *cs = static_cast<ComplexString *>(s); - cs->left->mark(markStack); - cs->right->mark(markStack); + if (cs->subtype == StringType_AddedString) { + cs->left->mark(markStack); + cs->right->mark(markStack); + } else { + Q_ASSERT(cs->subtype == StringType_SubString); + cs->left->mark(markStack); + } } DEFINE_MANAGED_VTABLE(String); @@ -111,6 +116,18 @@ void Heap::ComplexString::init(String *l, String *r) simplifyString(); } +void Heap::ComplexString::init(Heap::String *ref, int from, int len) +{ + Q_ASSERT(ref->length() >= from + len); + Base::init(); + + subtype = String::StringType_SubString; + + left = ref; + this->from = from; + this->len = len; +} + void Heap::String::destroy() { if (text) { internalClass->engine->memoryManager->changeUnmanagedHeapSizeUsage(qptrdiff(-text->size) * (int)sizeof(QChar)); @@ -124,7 +141,7 @@ uint String::toUInt(bool *ok) const { *ok = true; - if (subtype() == Heap::String::StringType_Unknown) + if (subtype() >= Heap::String::StringType_Unknown) d()->createHashValue(); if (subtype() == Heap::String::StringType_ArrayIndex) return d()->stringHash; @@ -156,7 +173,10 @@ void Heap::String::simplifyString() const append(this, ch); text = result.data_ptr(); text->ref.ref(); + const ComplexString *cs = static_cast<const ComplexString *>(this); identifier = 0; + cs->left = cs->right = nullptr; + internalClass->engine->memoryManager->changeUnmanagedHeapSizeUsage(qptrdiff(text->size) * (qptrdiff)sizeof(QChar)); subtype = StringType_Unknown; } @@ -171,10 +191,14 @@ void Heap::String::append(const String *data, QChar *ch) const String *item = worklist.back(); worklist.pop_back(); - if (item->subtype >= StringType_Complex) { + if (item->subtype == StringType_AddedString) { const ComplexString *cs = static_cast<const ComplexString *>(item); worklist.push_back(cs->right); worklist.push_back(cs->left); + } else if (item->subtype == StringType_SubString) { + const ComplexString *cs = static_cast<const ComplexString *>(item); + memcpy(ch, cs->left->toQString().constData() + cs->from, cs->len*sizeof(QChar)); + ch += cs->len; } else { memcpy(ch, item->text->data(), item->text->size * sizeof(QChar)); ch += item->text->size; |