From 827d1ed633b13719964d82e06195d9df4bd34419 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 17 Aug 2014 20:44:39 +0200 Subject: QMenu: don't hold QPointers in QList MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Ia224a4fe01acc1d4ca9b57c62941dd0f37780c67 Reviewed-by: Sérgio Martins Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qmenu.cpp | 14 +++++++------- src/widgets/widgets/qmenu_p.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 3148b140bc..a7c58ab332 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -102,9 +102,9 @@ class QTornOffMenu : public QMenu causedPopup.action = ((QTornOffMenu*)p)->d_func()->causedPopup.action; causedStack = ((QTornOffMenu*)p)->d_func()->calcCausedStack(); } - QList > calcCausedStack() const Q_DECL_OVERRIDE { return causedStack; } + QVector > calcCausedStack() const Q_DECL_OVERRIDE { return causedStack; } QPointer causedMenu; - QList > causedStack; + QVector > causedStack; }; public: QTornOffMenu(QMenu *p) : QMenu(*(new QTornOffMenuPrivate(p))) @@ -236,9 +236,9 @@ QRect QMenuPrivate::popupGeometry(int screen) const } } -QList > QMenuPrivate::calcCausedStack() const +QVector > QMenuPrivate::calcCausedStack() const { - QList > ret; + QVector > ret; for(QWidget *widget = causedPopup.widget; widget; ) { ret.append(widget); if (QTornOffMenu *qtmenu = qobject_cast(widget)) @@ -1122,7 +1122,7 @@ bool QMenuPrivate::mouseEventTaken(QMouseEvent *e) return false; } -void QMenuPrivate::activateCausedStack(const QList > &causedStack, QAction *action, QAction::ActionEvent action_e, bool self) +void QMenuPrivate::activateCausedStack(const QVector > &causedStack, QAction *action, QAction::ActionEvent action_e, bool self) { QBoolBlocker guard(activationRecursionGuard); if(self) @@ -1170,7 +1170,7 @@ void QMenuPrivate::activateAction(QAction *action, QAction::ActionEvent action_e /* I have to save the caused stack here because it will be undone after popup execution (ie in the hide). Then I iterate over the list to actually send the events. --Sam */ - const QList > causedStack = calcCausedStack(); + const QVector > causedStack = calcCausedStack(); if (action_e == QAction::Trigger) { #ifndef QT_NO_WHATSTHIS if (!inWhatsThisMode) @@ -1232,7 +1232,7 @@ void QMenuPrivate::_q_actionTriggered() if (!activationRecursionGuard && actionGuard) { //in case the action has not been activated by the mouse //we check the parent hierarchy - QList< QPointer > list; + QVector< QPointer > list; for(QWidget *widget = q->parentWidget(); widget; ) { if (qobject_cast(widget) #ifndef QT_NO_MENUBAR diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index ab6ca068fb..3acf73af90 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -422,7 +422,7 @@ public: QPointer widget; QPointer action; }; - virtual QList > calcCausedStack() const; + virtual QVector > calcCausedStack() const; QMenuCaused causedPopup; void hideUpToMenuBar(); void hideMenu(QMenu *menu); @@ -450,7 +450,7 @@ public: //firing of events void activateAction(QAction *, QAction::ActionEvent, bool self=true); - void activateCausedStack(const QList > &, QAction *, QAction::ActionEvent, bool); + void activateCausedStack(const QVector > &, QAction *, QAction::ActionEvent, bool); void _q_actionTriggered(); void _q_actionHovered(); -- cgit v1.2.3