diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-01-03 22:17:46 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2013-01-04 06:58:22 +0100 |
commit | 8260deef953115e098ed63eadaaac65234f0ec28 (patch) | |
tree | 6b58085a87e678e06a74f80d8a0f6863b02bd9a0 /qmljs_objects.cpp | |
parent | 8746fcc8b81a57d42d11504806556910fd4ab94d (diff) |
Add fast conversion of a string to an array index
This will be required later on when Array gets fixed
properly.
Change-Id: I37eccf94b202c9a003aab30b078ee24c422359a1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'qmljs_objects.cpp')
-rw-r--r-- | qmljs_objects.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index 1840e059ca..9070128543 100644 --- a/qmljs_objects.cpp +++ b/qmljs_objects.cpp @@ -60,6 +60,24 @@ using namespace QQmlJS::VM; + +uint String::asArrayIndex() const +{ + uint u = 0; + const QChar *ch = _text.constData(); + const QChar *end = ch + _text.length(); + while (ch < end) { + if (ch->unicode() < '0' && ch->unicode() > '9') + return InvalidArrayIndex; + uint n = u*10 + ch->unicode() - '0'; + if (n < u) + // overflow + return InvalidArrayIndex; + u = n; + } + return u; +} + // // Object // |