From 8097fa53b5e0e6228bd5737de6de8cd77c04dddf Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 30 Oct 2009 13:23:28 +0100 Subject: 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 --- examples/script/customclass/bytearrayclass.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'examples/script') 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())) -- cgit v1.2.3