summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-10-22 15:09:04 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-10-23 10:18:24 (GMT)
commit7bfa219ebd050523ecd0d72ad7154e1ce3b83ae9 (patch)
tree5fd85e56516ddebca9b9c15e3baaa8540cd76773
parent7e7b34fe5acab632c10814b591c80b0a9d613220 (diff)
downloadQt-7bfa219ebd050523ecd0d72ad7154e1ce3b83ae9.zip
Qt-7bfa219ebd050523ecd0d72ad7154e1ce3b83ae9.tar.gz
Qt-7bfa219ebd050523ecd0d72ad7154e1ce3b83ae9.tar.bz2
Use an inline helper function to check if a QScriptString is valid
Makes QScriptValue::property() ~10% faster. Reviewed-by: Olivier Goffart
-rw-r--r--src/script/api/qscriptstring.cpp3
-rw-r--r--src/script/api/qscriptstring_p.h7
-rw-r--r--src/script/api/qscriptvalue.cpp6
3 files changed, 11 insertions, 5 deletions
diff --git a/src/script/api/qscriptstring.cpp b/src/script/api/qscriptstring.cpp
index 2fb157f..1ede51c 100644
--- a/src/script/api/qscriptstring.cpp
+++ b/src/script/api/qscriptstring.cpp
@@ -139,8 +139,7 @@ QScriptString &QScriptString::operator=(const QScriptString &other)
*/
bool QScriptString::isValid() const
{
- Q_D(const QScriptString);
- return (d && d->engine);
+ return QScriptStringPrivate::isValid(*this);
}
/*!
diff --git a/src/script/api/qscriptstring_p.h b/src/script/api/qscriptstring_p.h
index d3bb47d..8e344e8 100644
--- a/src/script/api/qscriptstring_p.h
+++ b/src/script/api/qscriptstring_p.h
@@ -77,6 +77,8 @@ public:
inline void detachFromEngine();
+ static inline bool isValid(const QScriptString &q);
+
QBasicAtomicInt ref;
QScriptEnginePrivate *engine;
JSC::Identifier identifier;
@@ -114,6 +116,11 @@ inline void QScriptStringPrivate::detachFromEngine()
identifier = JSC::Identifier();
}
+inline bool QScriptStringPrivate::isValid(const QScriptString &q)
+{
+ return (q.d_ptr && q.d_ptr->engine);
+}
+
QT_END_NAMESPACE
#endif
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp
index 26cd314..21673d1 100644
--- a/src/script/api/qscriptvalue.cpp
+++ b/src/script/api/qscriptvalue.cpp
@@ -1775,7 +1775,7 @@ QScriptValue QScriptValue::property(const QScriptString &name,
const ResolveFlags &mode) const
{
Q_D(const QScriptValue);
- if (!d || !d->isObject() || !name.isValid())
+ if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name))
return QScriptValue();
return d->property(name.d_ptr->identifier, mode);
}
@@ -1798,7 +1798,7 @@ void QScriptValue::setProperty(const QScriptString &name,
const PropertyFlags &flags)
{
Q_D(QScriptValue);
- if (!d || !d->isObject() || !name.isValid())
+ if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name))
return;
d->setProperty(name.d_ptr->identifier, value, flags);
}
@@ -1832,7 +1832,7 @@ QScriptValue::PropertyFlags QScriptValue::propertyFlags(const QScriptString &nam
const ResolveFlags &mode) const
{
Q_D(const QScriptValue);
- if (!d || !d->isObject() || !name.isValid())
+ if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name))
return 0;
return d->propertyFlags(name.d_ptr->identifier, mode);
}