diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-01-09 13:56:47 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2015-01-12 11:04:24 +0100 |
commit | c10527b7c36a0c1ad49faaec5e4ea3dbb4f78b6c (patch) | |
tree | 8fe38a4f63953c1ace1c46b1d591ff45347ee974 /src/qml/jsruntime/qv4string.cpp | |
parent | 455d967025c0485c1dc0d817008de70cdbcd60dd (diff) |
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 <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4string.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4string.cpp | 57 |
1 files changed, 13 insertions, 44 deletions
diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index 52756734c5..795a6dfdc4 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<String *>(t); - String *other = static_cast<String *>(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<String *>(t)->isEqualTo(static_cast<String *>(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()); } |