diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-10-29 12:32:50 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-10-29 12:44:47 (GMT) |
commit | 84c250448f8b1a3adee4dcaf2fc8edb282dda225 (patch) | |
tree | e5c3c33fd3dbc47f19ac1464619ceb1d33068b67 /src/corelib/statemachine | |
parent | c3b4522259bbbe216b31cd66ec6ce26d68847823 (diff) | |
download | Qt-84c250448f8b1a3adee4dcaf2fc8edb282dda225.zip Qt-84c250448f8b1a3adee4dcaf2fc8edb282dda225.tar.gz Qt-84c250448f8b1a3adee4dcaf2fc8edb282dda225.tar.bz2 |
Cache a state's parent state
QAbstractState::parentState() is called heavily by the state machine
algorithm. The parent state is obtained by qobject_cast'ing
QObject::parent(). qobject_cast() is expensive. This commit introduces
caching of the result in order to improve performance.
We expect that the cache won't be invalidated much since the parent-child
relationship of states usually doesn't change after the state machine is
started.
Reviewed-by: Eskil Abrahamsen Blomfeldt
Diffstat (limited to 'src/corelib/statemachine')
-rw-r--r-- | src/corelib/statemachine/qabstractstate.cpp | 8 | ||||
-rw-r--r-- | src/corelib/statemachine/qabstractstate_p.h | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp index 72d640b..cf67cdd 100644 --- a/src/corelib/statemachine/qabstractstate.cpp +++ b/src/corelib/statemachine/qabstractstate.cpp @@ -78,7 +78,8 @@ QT_BEGIN_NAMESPACE function to perform custom processing when the state is exited. */ -QAbstractStatePrivate::QAbstractStatePrivate() +QAbstractStatePrivate::QAbstractStatePrivate() + : parentState(0) { } @@ -150,7 +151,10 @@ QAbstractState::~QAbstractState() */ QState *QAbstractState::parentState() const { - return qobject_cast<QState*>(parent()); + Q_D(const QAbstractState); + if (d->parentState != parent()) + d->parentState = qobject_cast<QState*>(parent()); + return d->parentState; } /*! diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h index 4b1306d..cd57815 100644 --- a/src/corelib/statemachine/qabstractstate_p.h +++ b/src/corelib/statemachine/qabstractstate_p.h @@ -76,6 +76,8 @@ public: void emitEntered(); void emitExited(); + + mutable QState *parentState; }; QT_END_NAMESPACE |