aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4string_p.h
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2014-11-11 15:08:30 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2014-11-12 20:44:13 +0100
commitafbf1f74af678af0eda76035133406aa8883408a (patch)
tree2bc7b93256cad8691baa0079e60ba4cf2d52fa93 /src/qml/jsruntime/qv4string_p.h
parentfaf13a3aa0c97b7386e44d02f323a9156a733c9f (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_p.h')
-rw-r--r--src/qml/jsruntime/qv4string_p.h56
1 files changed, 33 insertions, 23 deletions
diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h
index 69c9a0f892..989398883e 100644
--- a/src/qml/jsruntime/qv4string_p.h
+++ b/src/qml/jsruntime/qv4string_p.h
@@ -67,6 +67,35 @@ struct Q_QML_PRIVATE_EXPORT String : Base {
len == (uint)text->size);
return len;
}
+ void createHashValue() const;
+ inline unsigned hashValue() const {
+ if (subtype == StringType_Unknown)
+ createHashValue();
+ Q_ASSERT(!largestSubLength);
+
+ return stringHash;
+ }
+ inline QString toQString() const {
+ if (largestSubLength)
+ simplifyString();
+ QStringDataPtr ptr = { text };
+ text->ref.ref();
+ return QString(ptr);
+ }
+ inline bool isEqualTo(const String *other) const {
+ if (this == other)
+ return true;
+ if (hashValue() != other->hashValue())
+ return false;
+ Q_ASSERT(!largestSubLength);
+ if (identifier && identifier == other->identifier)
+ return true;
+ if (subtype >= Heap::String::StringType_UInt && subtype == other->subtype)
+ return true;
+
+ return toQString() == other->toQString();
+ }
+
union {
mutable QStringData *text;
mutable String *left;
@@ -96,17 +125,7 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed {
bool equals(String *other) const;
inline bool isEqualTo(const String *other) const {
- if (this == other)
- return true;
- if (hashValue() != other->hashValue())
- return false;
- Q_ASSERT(!d()->largestSubLength);
- if (d()->identifier && d()->identifier == other->d()->identifier)
- return true;
- if (subtype() >= Heap::String::StringType_UInt && subtype() == other->subtype())
- return true;
-
- return toQString() == other->toQString();
+ return d()->isEqualTo(other->d());
}
inline bool compare(const String *other) {
@@ -114,23 +133,15 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed {
}
inline QString toQString() const {
- if (d()->largestSubLength)
- d()->simplifyString();
- QStringDataPtr ptr = { d()->text };
- d()->text->ref.ref();
- return QString(ptr);
+ return d()->toQString();
}
inline unsigned hashValue() const {
- if (subtype() == Heap::String::StringType_Unknown)
- createHashValue();
- Q_ASSERT(!d()->largestSubLength);
-
- return d()->stringHash;
+ return d()->hashValue();
}
uint asArrayIndex() const {
if (subtype() == Heap::String::StringType_Unknown)
- createHashValue();
+ d()->createHashValue();
Q_ASSERT(!d()->largestSubLength);
if (subtype() == Heap::String::StringType_ArrayIndex)
return d()->stringHash;
@@ -146,7 +157,6 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed {
void makeIdentifierImpl() const;
- void createHashValue() const;
static uint createHashValue(const QChar *ch, int length);
static uint createHashValue(const char *ch, int length);