summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-03-08 14:21:38 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-03-09 08:42:42 (GMT)
commit7a52e5948c0305ca41a9b66d591a12d171fd2bae (patch)
tree02a840f0a5b2bd2c4798e1b6732d2f9a6ae540fe /src
parent8870d7173fce840277d15cab9daf75aa1b587a87 (diff)
downloadQt-7a52e5948c0305ca41a9b66d591a12d171fd2bae.zip
Qt-7a52e5948c0305ca41a9b66d591a12d171fd2bae.tar.gz
Qt-7a52e5948c0305ca41a9b66d591a12d171fd2bae.tar.bz2
Improve performance of QTimer::singleShot
Avoid allocation of QObject and OS timer. Reviewed-by: Olivier Goffart
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qtimer.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp
index e17c995..7650f6a 100644
--- a/src/corelib/kernel/qtimer.cpp
+++ b/src/corelib/kernel/qtimer.cpp
@@ -339,8 +339,20 @@ QT_END_INCLUDE_NAMESPACE
void QTimer::singleShot(int msec, QObject *receiver, const char *member)
{
- if (receiver && member)
+ if (receiver && member) {
+ if (msec == 0) {
+ // special code shortpath for 0-timers
+ const char* bracketPosition = strchr(member, '(');
+ if (!bracketPosition || !(member[0] >= '0' && member[0] <= '3')) {
+ qWarning("QTimer::singleShot: Invalid slot specification");
+ return;
+ }
+ QByteArray methodName(member+1, bracketPosition - 1 - member); // extract method name
+ QMetaObject::invokeMethod(receiver, methodName.constData(), Qt::QueuedConnection);
+ return;
+ }
(void) new QSingleShotTimer(msec, receiver, member);
+ }
}
/*!