summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-02-16 15:24:38 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-02-29 07:57:47 +0000
commita7885c9756d423042bd0670d82d78d8dffe9be54 (patch)
tree913f0db5b4ef655c6d708781e7de5a352e5c5043 /src/widgets
parent85c2a128ef8d1b5fbddf551691bccc0770e558ba (diff)
QVector: preserve capacity in clear()
This is what std::vector implementations usually do, because it minimizes memory fragmentation and useless allocations since no user will call clear() unless she intends to append new data afterwards. Fix calls to resize(0) that show how existing code tried to work around the issue. Adjust test. Port from QVERIFY(==) to QCOMPARE as a drive-by. [ChangeLog][QtCore][QVector] clear() now preserves capacity. To shed capacity, call squeeze() or swap with a default-constructed QVector object, see the documentation for an example. Change-Id: I9cebe611a97e027a89e821e64408a4741b31f1f6 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/widgets/qmdiarea.cpp2
-rw-r--r--src/widgets/widgets/qmenubar.cpp2
-rw-r--r--src/widgets/widgets/qtextbrowser.cpp2
3 files changed, 3 insertions, 3 deletions
diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp
index 2b734b603f..b42ebe7e48 100644
--- a/src/widgets/widgets/qmdiarea.cpp
+++ b/src/widgets/widgets/qmdiarea.cpp
@@ -516,7 +516,7 @@ QVector<QRect> MinOverlapPlacer::findMaxOverlappers(const QRect &domain, const Q
if (overlap >= maxOverlap || maxOverlap == -1) {
if (overlap > maxOverlap) {
maxOverlap = overlap;
- result.resize(0);
+ result.clear();
}
result << srcRect;
}
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp
index f15ce06e23..261ff0bca3 100644
--- a/src/widgets/widgets/qmenubar.cpp
+++ b/src/widgets/widgets/qmenubar.cpp
@@ -200,7 +200,7 @@ void QMenuBarPrivate::updateGeometries()
if(itemsDirty) {
for(int j = 0; j < shortcutIndexMap.size(); ++j)
q->releaseShortcut(shortcutIndexMap.value(j));
- shortcutIndexMap.resize(0); // faster than clear
+ shortcutIndexMap.clear();
const int actionsCount = actions.count();
shortcutIndexMap.reserve(actionsCount);
for (int i = 0; i < actionsCount; i++)
diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp
index d8a7b27d60..db66d39089 100644
--- a/src/widgets/widgets/qtextbrowser.cpp
+++ b/src/widgets/widgets/qtextbrowser.cpp
@@ -1141,7 +1141,7 @@ void QTextBrowser::clearHistory()
d->forwardStack.clear();
if (!d->stack.isEmpty()) {
QTextBrowserPrivate::HistoryEntry historyEntry = d->stack.top();
- d->stack.resize(0);
+ d->stack.clear();
d->stack.push(historyEntry);
d->home = historyEntry.url;
}