summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-10-30 13:23:28 +0100
committerKent Hansen <khansen@trolltech.com>2009-10-30 14:33:20 +0100
commit8097fa53b5e0e6228bd5737de6de8cd77c04dddf (patch)
tree095b65b7b80dc8d82207d4c757f5433fc01659e9 /examples
parent96799bf4da265835b5e574593bc5106712352ffc (diff)
Add QScriptString::toArrayIndex() function
Avoid hacking a custom toArrayIndex() in the example; instead provide an ECMA-compliant conversion that's as fast as possible (having to convert the QScriptString to a QString and then convert the result to a number is considerably slower than calling JSC's Identifier::toArrayIndex() function directly). Reviewed-by: Olivier Goffart
Diffstat (limited to 'examples')
-rw-r--r--examples/script/customclass/bytearrayclass.cpp17
1 files changed, 3 insertions, 14 deletions
diff --git a/examples/script/customclass/bytearrayclass.cpp b/examples/script/customclass/bytearrayclass.cpp
index 7291b9769b..bce69e4da7 100644
--- a/examples/script/customclass/bytearrayclass.cpp
+++ b/examples/script/customclass/bytearrayclass.cpp
@@ -72,18 +72,6 @@ private:
int m_last;
};
-static qint32 toArrayIndex(const QString &str)
-{
- QByteArray bytes = str.toUtf8();
- char *eptr;
- quint32 pos = strtoul(bytes.constData(), &eptr, 10);
- if ((eptr == bytes.constData() + bytes.size())
- && (QByteArray::number(pos) == bytes)) {
- return pos;
- }
- return -1;
-}
-
//! [0]
ByteArrayClass::ByteArrayClass(QScriptEngine *engine)
: QObject(engine), QScriptClass(engine)
@@ -120,8 +108,9 @@ QScriptClass::QueryFlags ByteArrayClass::queryProperty(const QScriptValue &objec
if (name == length) {
return flags;
} else {
- qint32 pos = toArrayIndex(name);
- if (pos == -1)
+ bool isArrayIndex;
+ qint32 pos = name.toArrayIndex(&isArrayIndex);
+ if (!isArrayIndex)
return 0;
*id = pos;
if ((flags & HandlesReadAccess) && (pos >= ba->size()))