summaryrefslogtreecommitdiffstats
path: root/tests/auto/qstatemachine
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-10-29 12:32:50 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-10-29 12:44:47 (GMT)
commit84c250448f8b1a3adee4dcaf2fc8edb282dda225 (patch)
treee5c3c33fd3dbc47f19ac1464619ceb1d33068b67 /tests/auto/qstatemachine
parentc3b4522259bbbe216b31cd66ec6ce26d68847823 (diff)
downloadQt-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 'tests/auto/qstatemachine')
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 97057c6..975b301 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -117,6 +117,7 @@ private slots:
void cleanup();
void rootState();
+ void machineWithParent();
void addAndRemoveState();
void stateEntryAndExit();
void assignProperty();
@@ -1045,6 +1046,14 @@ void tst_QStateMachine::rootState()
QCOMPARE(s2->parentState(), static_cast<QState*>(&machine));
}
+void tst_QStateMachine::machineWithParent()
+{
+ QObject object;
+ QStateMachine *machine = new QStateMachine(&object);
+ QCOMPARE(machine->parent(), &object);
+ QCOMPARE(machine->parentState(), (QObject*)0);
+}
+
void tst_QStateMachine::addAndRemoveState()
{
#ifdef QT_BUILD_INTERNAL