diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2014-11-11 15:08:30 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-11-12 20:44:13 +0100 |
commit | afbf1f74af678af0eda76035133406aa8883408a (patch) | |
tree | 2bc7b93256cad8691baa0079e60ba4cf2d52fa93 /src/qml/jsruntime/qv4string.cpp | |
parent | faf13a3aa0c97b7386e44d02f323a9156a733c9f (diff) |
Ported ExecutionEngine::newString and newIdentifier to Heap::String
Avoid the use of Returned<String> for newString and changed the identifier
table to use Heap::String. This required moving some code back into
Heap::String, but that's code that doesn't call back into the GC, so
allocations and therefore future object moves aren't possible.
Change-Id: I1dca3e9c12a9c56f09419af8cc8cba39fe04f720
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4string.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4string.cpp | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index 945a117364..a06a36d7fd 100644 --- a/src/qml/jsruntime/qv4string.cpp +++ b/src/qml/jsruntime/qv4string.cpp @@ -282,7 +282,7 @@ uint String::toUInt(bool *ok) const *ok = true; if (subtype() == Heap::String::StringType_Unknown) - createHashValue(); + d()->createHashValue(); if (subtype() >= Heap::String::StringType_UInt) return d()->stringHash; @@ -331,6 +331,32 @@ void Heap::String::simplifyString() const largestSubLength = 0; } +void Heap::String::createHashValue() const +{ + if (largestSubLength) + simplifyString(); + Q_ASSERT(!largestSubLength); + const QChar *ch = reinterpret_cast<const QChar *>(text->data()); + const QChar *end = ch + text->size; + + // array indices get their number as hash value + bool ok; + stringHash = ::toArrayIndex(ch, end, &ok); + if (ok) { + subtype = (stringHash == UINT_MAX) ? Heap::String::StringType_UInt : Heap::String::StringType_ArrayIndex; + return; + } + + uint h = 0xffffffff; + while (ch < end) { + h = 31 * h + ch->unicode(); + ++ch; + } + + stringHash = h; + subtype = Heap::String::StringType_Regular; +} + void Heap::String::append(const String *data, QChar *ch) { std::vector<const String *> worklist; @@ -352,31 +378,7 @@ void Heap::String::append(const String *data, QChar *ch) } -void String::createHashValue() const -{ - if (d()->largestSubLength) - d()->simplifyString(); - Q_ASSERT(!d()->largestSubLength); - const QChar *ch = reinterpret_cast<const QChar *>(d()->text->data()); - const QChar *end = ch + d()->text->size; - // array indices get their number as hash value - bool ok; - d()->stringHash = ::toArrayIndex(ch, end, &ok); - if (ok) { - setSubtype((d()->stringHash == UINT_MAX) ? Heap::String::StringType_UInt : Heap::String::StringType_ArrayIndex); - return; - } - - uint h = 0xffffffff; - while (ch < end) { - h = 31 * h + ch->unicode(); - ++ch; - } - - d()->stringHash = h; - setSubtype(Heap::String::StringType_Regular); -} uint String::createHashValue(const QChar *ch, int length) { |