aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4string.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2016-06-29 15:06:08 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2016-07-13 08:16:39 +0000
commit9109d15398f8c869e401aa9aacc578c96200e217 (patch)
treea304ea0c5aabb46f3f306e7a5f444d224c918b59 /src/qml/jsruntime/qv4string.cpp
parentb55485bd4ad6d9084e15e982e457a835aeda831d (diff)
V4: allow for String::createHashValue to be inlined
Notably into QHashedString(Ref)::computeHash. Change-Id: Icf8487ed3da0f117cb0911f20c9b88498f61510a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4string.cpp')
-rw-r--r--src/qml/jsruntime/qv4string.cpp65
1 files changed, 2 insertions, 63 deletions
diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp
index 7c965ce441..3901514326 100644
--- a/src/qml/jsruntime/qv4string.cpp
+++ b/src/qml/jsruntime/qv4string.cpp
@@ -46,59 +46,10 @@
#include "qv4stringobject_p.h"
#endif
#include <QtCore/QHash>
-#include <QtCore/private/qnumeric_p.h>
using namespace QV4;
-static inline uint toUInt(const QChar *ch) { return ch->unicode(); }
#ifndef V4_BOOTSTRAP
-static inline uint toUInt(const char *ch) { return *ch; }
-#endif
-
-template <typename T>
-static inline uint toArrayIndex(const T *ch, const T *end)
-{
- uint i = toUInt(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 = toUInt(ch) - '0';
- if (x > 9)
- return UINT_MAX;
- if (mul_overflow(i, uint(10), &i) || add_overflow(i, x, &i))
- return UINT_MAX;
- ++ch;
- }
- return i;
-}
-
-#ifndef V4_BOOTSTRAP
-
-template <typename T>
-static inline uint calculateHashValue(const T *ch, const T* end, uint *subtype)
-{
- // array indices get their number as hash value
- uint h = ::toArrayIndex(ch, end);
- if (h != UINT_MAX) {
- if (subtype)
- *subtype = Heap::String::StringType_ArrayIndex;
- return h;
- }
-
- while (ch < end) {
- h = 31 * h + toUInt(ch);
- ++ch;
- }
-
- if (subtype)
- *subtype = Heap::String::StringType_Regular;
- return h;
-}
DEFINE_MANAGED_VTABLE(String);
@@ -225,19 +176,7 @@ void Heap::String::createHashValue() const
Q_ASSERT(!largestSubLength);
const QChar *ch = reinterpret_cast<const QChar *>(text->data());
const QChar *end = ch + text->size;
- stringHash = calculateHashValue(ch, end, &subtype);
-}
-
-uint String::createHashValue(const QChar *ch, int length, uint *subtype)
-{
- const QChar *end = ch + length;
- return calculateHashValue(ch, end, subtype);
-}
-
-uint String::createHashValue(const char *ch, int length, uint *subtype)
-{
- const char *end = ch + length;
- return calculateHashValue(ch, end, subtype);
+ stringHash = QV4::String::calculateHashValue(ch, end, &subtype);
}
uint String::getLength(const Managed *m)
@@ -249,6 +188,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());
}