QAbstractTransition: don't hold QPointers in QList
QPointer is larger than a void*, so holding them in a QList is needlessly inefficient. Worse, the code could come to depend on the fragile property of (inefficient) QLists that references to elements therein never are invalidated. Change-Id: I52e83a26eda06fb9826e9c4773a7a0b84b0f59c7 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
931f9c23ee
commit
aa79adef6f
@ -254,7 +254,7 @@ QList<QAbstractState*> QAbstractTransition::targetStates() const
|
|||||||
void QAbstractTransition::setTargetStates(const QList<QAbstractState*> &targets)
|
void QAbstractTransition::setTargetStates(const QList<QAbstractState*> &targets)
|
||||||
{
|
{
|
||||||
Q_D(QAbstractTransition);
|
Q_D(QAbstractTransition);
|
||||||
QList<QPointer<QAbstractState> > copy(d->targetStates);
|
QVector<QPointer<QAbstractState> > copy(d->targetStates);
|
||||||
bool sameList = true;
|
bool sameList = true;
|
||||||
for (int i = 0; i < targets.size(); ++i) {
|
for (int i = 0; i < targets.size(); ++i) {
|
||||||
QAbstractState *target = targets.at(i);
|
QAbstractState *target = targets.at(i);
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
#include <private/qobject_p.h>
|
#include <private/qobject_p.h>
|
||||||
|
|
||||||
#include <QtCore/qlist.h>
|
#include <QtCore/qlist.h>
|
||||||
|
#include <QtCore/qvector.h>
|
||||||
#include <QtCore/qsharedpointer.h>
|
#include <QtCore/qsharedpointer.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -72,7 +73,7 @@ public:
|
|||||||
QStateMachine *machine() const;
|
QStateMachine *machine() const;
|
||||||
void emitTriggered();
|
void emitTriggered();
|
||||||
|
|
||||||
QList<QPointer<QAbstractState> > targetStates;
|
QVector<QPointer<QAbstractState> > targetStates;
|
||||||
QAbstractTransition::TransitionType transitionType;
|
QAbstractTransition::TransitionType transitionType;
|
||||||
|
|
||||||
#ifndef QT_NO_ANIMATION
|
#ifndef QT_NO_ANIMATION
|
||||||
|
@ -320,7 +320,7 @@ void QState::addTransition(QAbstractTransition *transition)
|
|||||||
}
|
}
|
||||||
|
|
||||||
transition->setParent(this);
|
transition->setParent(this);
|
||||||
const QList<QPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates;
|
const QVector<QPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates;
|
||||||
for (int i = 0; i < targets.size(); ++i) {
|
for (int i = 0; i < targets.size(); ++i) {
|
||||||
QAbstractState *t = targets.at(i).data();
|
QAbstractState *t = targets.at(i).data();
|
||||||
if (!t) {
|
if (!t) {
|
||||||
|
Loading…
Reference in New Issue
Block a user