statemachine: Move invariant code out of loop body
authorKent Hansen <kent.hansen@nokia.com>
Wed, 11 Jul 2012 23:01:17 +0000 (01:01 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 12 Jul 2012 18:38:02 +0000 (20:38 +0200)
The lca variable doesn't change inside the loop. Comparing our
implementation to the algorithm in the SCXML spec reveals that this
check should indeed be done outside the loop.

Change-Id: I5e9824758fd147766e975d107a73561bd7f5a190
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
src/corelib/statemachine/qstatemachine.cpp

index a83737d..ccc40ac 100644 (file)
@@ -517,12 +517,12 @@ QList<QAbstractState*> QStateMachinePrivate::computeStatesToEnter(const QList<QA
             for (int j = src ? 1 : 0; j < lst.size(); ++j) {
                 QAbstractState *s = lst.at(j);
                 addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry);
-                if (isParallel(lca)) {
-                    QList<QAbstractState*> lcac = QStatePrivate::get(lca)->childStates();
-                    foreach (QAbstractState* child,lcac) {
-                        if (!statesToEnter.contains(child))
-                            addStatesToEnter(child,lca,statesToEnter,statesForDefaultEntry);
-                    }
+            }
+            if (isParallel(lca)) {
+                QList<QAbstractState*> lcac = QStatePrivate::get(lca)->childStates();
+                foreach (QAbstractState* child,lcac) {
+                    if (!statesToEnter.contains(child))
+                        addStatesToEnter(child,lca,statesToEnter,statesForDefaultEntry);
                 }
             }
         }