Avoid expensive QHash::values() calls
qcocoawindow.mm: we can replace QHash::values() with std::vector since CoW is needless here and std::vector is more cache-friendly. Also replace foreach with range-based for. qitemeditorfactory.cpp: QHash::values() is used as auxiliary container to create QSet. Replace it with std::vector since CoW is needless here and apply sort-unique idiom to remove duplicates. Also avoid needless allocations. Change-Id: If34c7016977ceb7fab68e9298bf2e1944af79139 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
81b5aa792f
commit
bae0c4c11a
@ -58,6 +58,8 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
defaultWindowWidth = 160,
|
defaultWindowWidth = 160,
|
||||||
defaultWindowHeight = 160
|
defaultWindowHeight = 160
|
||||||
@ -2068,10 +2070,10 @@ void QCocoaWindow::applyContentBorderThickness(NSWindow *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find consecutive registered border areas, starting from the top.
|
// Find consecutive registered border areas, starting from the top.
|
||||||
QList<BorderRange> ranges = m_contentBorderAreas.values();
|
std::vector<BorderRange> ranges(m_contentBorderAreas.cbegin(), m_contentBorderAreas.cend());
|
||||||
std::sort(ranges.begin(), ranges.end());
|
std::sort(ranges.begin(), ranges.end());
|
||||||
int effectiveTopContentBorderThickness = m_topContentBorderThickness;
|
int effectiveTopContentBorderThickness = m_topContentBorderThickness;
|
||||||
foreach (BorderRange range, ranges) {
|
for (BorderRange range : ranges) {
|
||||||
// Skip disiabled ranges (typically hidden tool bars)
|
// Skip disiabled ranges (typically hidden tool bars)
|
||||||
if (!m_enabledContentBorderAreas.value(range.identifier, false))
|
if (!m_enabledContentBorderAreas.value(range.identifier, false))
|
||||||
continue;
|
continue;
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
#include <qapplication.h>
|
#include <qapplication.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -191,9 +192,11 @@ QByteArray QItemEditorFactory::valuePropertyName(int userType) const
|
|||||||
QItemEditorFactory::~QItemEditorFactory()
|
QItemEditorFactory::~QItemEditorFactory()
|
||||||
{
|
{
|
||||||
//we make sure we delete all the QItemEditorCreatorBase
|
//we make sure we delete all the QItemEditorCreatorBase
|
||||||
//this has to be done only once, hence the QSet
|
//this has to be done only once, hence the sort-unique idiom
|
||||||
QSet<QItemEditorCreatorBase*> set = creatorMap.values().toSet();
|
std::vector<QItemEditorCreatorBase*> creators(creatorMap.cbegin(), creatorMap.cend());
|
||||||
qDeleteAll(set);
|
std::sort(creators.begin(), creators.end());
|
||||||
|
const auto it = std::unique(creators.begin(), creators.end());
|
||||||
|
qDeleteAll(creators.begin(), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Loading…
Reference in New Issue
Block a user