From bd15b23987e9d6d1f42fa8987e5c1ff5a1eeee8b Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 20 Mar 2015 14:20:16 +0100 Subject: QStateMachine: cache expensive calculations. As nothing changes in the state machine when selecting transitions for events and then calculating the exit- and entry-sets, some calculations can be cached. The exit set for a transition was calculated multiple times. First in removeConflictingTransitions, where the two loops would each calculate them multiple times. Then secondly in microstep(), which would calculate the exit set for all transitions. Transition selection, exit set calculation, and entry set calculation all calculate the transition domain and effective target states for transitions. Change-Id: I217328a73db2f71e371eb5f60a0c7b222303f0ca Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../qstatemachine/tst_qstatemachine.cpp | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'tests/auto/corelib/statemachine') diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 96d0a62f6b..9fb2e40cb8 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -256,10 +256,12 @@ public: Entry, Exit }; - TestState(QState *parent) - : QState(parent) {} - TestState(ChildMode mode) - : QState(mode) {} + TestState(QState *parent, const QString &objectName = QString()) + : QState(parent) + { setObjectName(objectName); } + TestState(ChildMode mode, const QString &objectName = QString()) + : QState(mode) + { setObjectName(objectName); } QList > events; protected: virtual void onEntry(QEvent *) { @@ -273,9 +275,9 @@ protected: class TestTransition : public QAbstractTransition { public: - TestTransition(QAbstractState *target) + TestTransition(QAbstractState *target, const QString &objectName = QString()) : QAbstractTransition() - { setTargetState(target); } + { setTargetState(target); setObjectName(objectName); } QList triggers; protected: virtual bool eventTest(QEvent *) { @@ -1352,15 +1354,16 @@ void tst_QStateMachine::stateEntryAndExit() { QStateMachine machine; - TestState *s1 = new TestState(&machine); - TestState *s11 = new TestState(s1); - TestState *s12 = new TestState(s1); - TestState *s2 = new TestState(&machine); + TestState *s1 = new TestState(&machine, "s1"); + TestState *s11 = new TestState(s1, "s11"); + TestState *s12 = new TestState(s1, "s12"); + TestState *s2 = new TestState(&machine, "s2"); QFinalState *s3 = new QFinalState(&machine); + s3->setObjectName("s3"); s1->setInitialState(s11); - TestTransition *t1 = new TestTransition(s12); + TestTransition *t1 = new TestTransition(s12, "t1"); s11->addTransition(t1); - TestTransition *t2 = new TestTransition(s2); + TestTransition *t2 = new TestTransition(s2, "t2"); s12->addTransition(t2); s2->addTransition(s3); -- cgit v1.2.3