From c10527b7c36a0c1ad49faaec5e4ea3dbb4f78b6c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 9 Jan 2015 13:56:47 +0100 Subject: [PATCH] Remove the StringType_UInt subtype It's not really used, and doesn't optimise anything really. Additionally get rid of some code duplication. Change-Id: I6502512e6df58db2c0264ea43d91a23c7585427c Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4string.cpp | 57 ++++++++++------------------------------- src/qml/jsruntime/qv4string_p.h | 7 ++--- 2 files changed, 17 insertions(+), 47 deletions(-) diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index 5275673..795a6df 100644 --- a/src/qml/jsruntime/qv4string.cpp +++ b/src/qml/jsruntime/qv4string.cpp @@ -43,9 +43,8 @@ using namespace QV4; -static uint toArrayIndex(const QChar *ch, const QChar *end, bool *ok) +static uint toArrayIndex(const QChar *ch, const QChar *end) { - *ok = false; uint i = ch->unicode() - '0'; if (i > 9) return UINT_MAX; @@ -65,15 +64,13 @@ static uint toArrayIndex(const QChar *ch, const QChar *end, bool *ok) i = n; ++ch; } - *ok = true; return i; } #ifndef V4_BOOTSTRAP -static uint toArrayIndex(const char *ch, const char *end, bool *ok) +static uint toArrayIndex(const char *ch, const char *end) { - *ok = false; uint i = *ch - '0'; if (i > 9) return UINT_MAX; @@ -93,7 +90,6 @@ static uint toArrayIndex(const char *ch, const char *end, bool *ok) i = n; ++ch; } - *ok = true; return i; } @@ -225,16 +221,7 @@ bool String::isEqualTo(Managed *t, Managed *o) if (!o->internalClass()->vtable->isString) return false; - String *that = static_cast(t); - String *other = static_cast(o); - if (that->hashValue() != other->hashValue()) - return false; - if (that->identifier() && that->identifier() == other->identifier()) - return true; - if (that->subtype() >= Heap::String::StringType_UInt && that->subtype() == other->subtype()) - return true; - - return that->toQString() == other->toQString(); + return static_cast(t)->isEqualTo(static_cast(o)); } @@ -278,10 +265,10 @@ uint String::toUInt(bool *ok) const if (subtype() == Heap::String::StringType_Unknown) d()->createHashValue(); - if (subtype() >= Heap::String::StringType_UInt) + if (subtype() == Heap::String::StringType_ArrayIndex) return d()->stringHash; - // ### this conversion shouldn't be required + // required for UINT_MAX or numbers starting with a leading 0 double d = RuntimeHelpers::stringToNumber(toQString()); uint l = (uint)d; if (d == l) @@ -290,20 +277,6 @@ uint String::toUInt(bool *ok) const return UINT_MAX; } -bool String::equals(String *other) const -{ - if (this == other) - return true; - if (hashValue() != other->hashValue()) - return false; - if (identifier() && identifier() == other->identifier()) - return true; - if (subtype() >= Heap::String::StringType_UInt && subtype() == other->subtype()) - return true; - - return toQString() == other->toQString(); -} - void String::makeIdentifierImpl() const { if (d()->largestSubLength) @@ -335,10 +308,9 @@ void Heap::String::createHashValue() const 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; + stringHash = ::toArrayIndex(ch, end); + if (stringHash != UINT_MAX) { + subtype = Heap::String::StringType_ArrayIndex; return; } @@ -380,9 +352,8 @@ uint String::createHashValue(const QChar *ch, int length) const QChar *end = ch + length; // array indices get their number as hash value - bool ok; - uint stringHash = ::toArrayIndex(ch, end, &ok); - if (ok) + uint stringHash = ::toArrayIndex(ch, end); + if (stringHash != UINT_MAX) return stringHash; uint h = 0xffffffff; @@ -399,9 +370,8 @@ uint String::createHashValue(const char *ch, int length) const char *end = ch + length; // array indices get their number as hash value - bool ok; - uint stringHash = ::toArrayIndex(ch, end, &ok); - if (ok) + uint stringHash = ::toArrayIndex(ch, end); + if (stringHash != UINT_MAX) return stringHash; uint h = 0xffffffff; @@ -424,7 +394,6 @@ uint String::getLength(const Managed *m) uint String::toArrayIndex(const QString &str) { - bool ok; - return ::toArrayIndex(str.constData(), str.constData() + str.length(), &ok); + return ::toArrayIndex(str.constData(), str.constData() + str.length()); } diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h index 86b8f2b..8c3030b 100644 --- a/src/qml/jsruntime/qv4string_p.h +++ b/src/qml/jsruntime/qv4string_p.h @@ -50,7 +50,6 @@ struct Q_QML_PRIVATE_EXPORT String : Base { enum StringType { StringType_Unknown, StringType_Regular, - StringType_UInt, StringType_ArrayIndex }; @@ -90,7 +89,7 @@ struct Q_QML_PRIVATE_EXPORT String : Base { Q_ASSERT(!largestSubLength); if (identifier && identifier == other->identifier) return true; - if (subtype >= Heap::String::StringType_UInt && subtype == other->subtype) + if (subtype == Heap::String::StringType_ArrayIndex && other->subtype == Heap::String::StringType_ArrayIndex) return true; return toQString() == other->toQString(); @@ -124,7 +123,9 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { IsString = true }; - bool equals(String *other) const; + bool equals(String *other) const { + return d()->isEqualTo(other->d()); + } inline bool isEqualTo(const String *other) const { return d()->isEqualTo(other->d()); } -- 2.7.4