aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4string.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsruntime/qv4string.cpp')
-rw-r--r--src/qml/jsruntime/qv4string.cpp133
1 files changed, 16 insertions, 117 deletions
diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp
index abef885249..3365ffe637 100644
--- a/src/qml/jsruntime/qv4string.cpp
+++ b/src/qml/jsruntime/qv4string.cpp
@@ -49,57 +49,8 @@
using namespace QV4;
-static uint toArrayIndex(const QChar *ch, const QChar *end)
-{
- uint i = ch->unicode() - '0';
- if (i > 9)
- return UINT_MAX;
- ++ch;
- // reject "01", "001", ...
- if (i == 0 && ch != end)
- return UINT_MAX;
-
- while (ch < end) {
- uint x = ch->unicode() - '0';
- if (x > 9)
- return UINT_MAX;
- uint n = i*10 + x;
- if (n < i)
- // overflow
- return UINT_MAX;
- i = n;
- ++ch;
- }
- return i;
-}
-
#ifndef V4_BOOTSTRAP
-static uint toArrayIndex(const char *ch, const char *end)
-{
- uint i = *ch - '0';
- if (i > 9)
- return UINT_MAX;
- ++ch;
- // reject "01", "001", ...
- if (i == 0 && ch != end)
- return UINT_MAX;
-
- while (ch < end) {
- uint x = *ch - '0';
- if (x > 9)
- return UINT_MAX;
- uint n = i*10 + x;
- if (n < i)
- // overflow
- return UINT_MAX;
- i = n;
- ++ch;
- }
- return i;
-}
-
-
DEFINE_MANAGED_VTABLE(String);
void String::markObjects(Heap::Base *that, ExecutionEngine *e)
@@ -123,9 +74,11 @@ bool String::isEqualTo(Managed *t, Managed *o)
}
-Heap::String::String(MemoryManager *mm, const QString &t)
- : mm(mm)
+void Heap::String::init(MemoryManager *mm, const QString &t)
{
+ Base::init();
+ this->mm = mm;
+
subtype = String::StringType_Unknown;
text = const_cast<QString &>(t).data_ptr();
@@ -136,9 +89,11 @@ Heap::String::String(MemoryManager *mm, const QString &t)
len = text->size;
}
-Heap::String::String(MemoryManager *mm, String *l, String *r)
- : mm(mm)
+void Heap::String::init(MemoryManager *mm, String *l, String *r)
{
+ Base::init();
+ this->mm = mm;
+
subtype = String::StringType_Unknown;
left = l;
@@ -198,31 +153,6 @@ void Heap::String::simplifyString() const
mm->growUnmanagedHeapSizeUsage(size_t(text->size) * sizeof(QChar));
}
-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
- stringHash = ::toArrayIndex(ch, end);
- if (stringHash != UINT_MAX) {
- subtype = 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;
@@ -243,45 +173,14 @@ void Heap::String::append(const String *data, QChar *ch)
}
}
-
-
-
-uint String::createHashValue(const QChar *ch, int length)
-{
- const QChar *end = ch + length;
-
- // array indices get their number as hash value
- uint stringHash = ::toArrayIndex(ch, end);
- if (stringHash != UINT_MAX)
- return stringHash;
-
- uint h = 0xffffffff;
- while (ch < end) {
- h = 31 * h + ch->unicode();
- ++ch;
- }
-
- return h;
-}
-
-uint String::createHashValue(const char *ch, int length)
+void Heap::String::createHashValue() const
{
- const char *end = ch + length;
-
- // array indices get their number as hash value
- uint stringHash = ::toArrayIndex(ch, end);
- if (stringHash != UINT_MAX)
- return stringHash;
-
- uint h = 0xffffffff;
- while (ch < end) {
- if ((uchar)(*ch) >= 0x80)
- return UINT_MAX;
- h = 31 * h + *ch;
- ++ch;
- }
-
- return h;
+ if (largestSubLength)
+ simplifyString();
+ Q_ASSERT(!largestSubLength);
+ const QChar *ch = reinterpret_cast<const QChar *>(text->data());
+ const QChar *end = ch + text->size;
+ stringHash = QV4::String::calculateHashValue(ch, end, &subtype);
}
uint String::getLength(const Managed *m)
@@ -293,6 +192,6 @@ uint String::getLength(const Managed *m)
uint String::toArrayIndex(const QString &str)
{
- return ::toArrayIndex(str.constData(), str.constData() + str.length());
+ return QV4::String::toArrayIndex(str.constData(), str.constData() + str.length());
}