From 6066af7f09460bbf72d7aaca12836ca002dcea2a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 17 Dec 2015 01:38:57 +0100 Subject: QLineEdit: hold SideWidgetEntry in std::vector, not QVector This is private implementation, so there's no BC issue here. The collections ported here also do not benefit from CoW, because they are never copied. Adapt to STL API and replace foreach with C++11 range-for loops, because the former deep-copies STL containers. Also replace index-based for loops with C++11 range-for, to evade the int/size_t problem on MSVC. Saves a bit more than 1KiB in text size on optimized GCC 4.9 Linux AMD64 builds, not all of which can be attributed to the ports to range-for. Change-Id: I240030180bd1b2ca40c002b03ab72319a99a87c3 Reviewed-by: Friedemann Kleint --- src/widgets/widgets/qlineedit_p.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/widgets/widgets/qlineedit_p.cpp') diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 599ebce0ab..5afedf6823 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -382,11 +382,11 @@ void QLineEditPrivate::_q_textChanged(const QString &text) lastTextSize = newTextSize; #ifndef QT_NO_ANIMATION const bool fadeIn = newTextSize > 0; - foreach (const SideWidgetEntry &e, leadingSideWidgets) { + for (const SideWidgetEntry &e : leadingSideWidgets) { if (e.flags & SideWidgetFadeInWithText) static_cast(e.widget)->animateShow(fadeIn); } - foreach (const SideWidgetEntry &e, trailingSideWidgets) { + for (const SideWidgetEntry &e : trailingSideWidgets) { if (e.flags & SideWidgetFadeInWithText) static_cast(e.widget)->animateShow(fadeIn); } @@ -453,13 +453,17 @@ void QLineEditPrivate::positionSideWidgets() QLineEditPrivate::PositionIndexPair QLineEditPrivate::findSideWidget(const QAction *a) const { - for (int i = 0; i < leadingSideWidgets.size(); ++i) { - if (a == leadingSideWidgets.at(i).action) + int i = 0; + for (const auto &e : leadingSideWidgets) { + if (a == e.action) return PositionIndexPair(QLineEdit::LeadingPosition, i); + ++i; } - for (int i = 0; i < trailingSideWidgets.size(); ++i) { - if (a == trailingSideWidgets.at(i).action) + i = 0; + for (const auto &e : trailingSideWidgets) { + if (a == e.action) return PositionIndexPair(QLineEdit::TrailingPosition, i); + ++i; } return PositionIndexPair(QLineEdit::LeadingPosition, -1); } @@ -493,8 +497,8 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE PositionIndexPair positionIndex = before ? findSideWidget(before) : PositionIndexPair(position, -1); SideWidgetEntryList &list = positionIndex.first == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets; if (positionIndex.second < 0) - positionIndex.second = list.size(); - list.insert(positionIndex.second, SideWidgetEntry(w, newAction, flags)); + positionIndex.second = int(list.size()); + list.insert(list.begin() + positionIndex.second, SideWidgetEntry(w, newAction, flags)); positionSideWidgets(); w->show(); return w; @@ -507,7 +511,8 @@ void QLineEditPrivate::removeAction(QAction *action) if (positionIndex.second == -1) return; SideWidgetEntryList &list = positionIndex.first == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets; - SideWidgetEntry entry = list.takeAt(positionIndex.second); + SideWidgetEntry entry = list[positionIndex.second]; + list.erase(list.begin() + positionIndex.second); if (entry.flags & SideWidgetCreatedByWidgetAction) static_cast(entry.action)->releaseWidget(entry.widget); else -- cgit v1.2.3