path: root/src/corelib/tools/
diff options
authorMarc Mutz <>2014-07-26 01:43:18 +0200
committerMarc Mutz <>2015-02-17 15:02:45 +0000
commit81a45e1f13fdf56129aed952a6e3479e16c14a2c (patch)
treeac8bbaa74a61735e98cce177791b034ac1bd38fd /src/corelib/tools/
parentb63c721a0e8d637dd2a34cc5d335195349443366 (diff)
QTimeZone: don't use QSet, use sorted QList
QSet, as a node-based container, requires one memory allocation per element inserted. QList, as a contiguous-memory container (at least in the case of a QByteArray payload), requires one memory allocation per container. The higher lookup speed might still speak for using QSet, but there are only two uses of the sets: 1. Checking for existence (or lack thereof) of timezone names. For this, first generating a container full of data just to check for existence of one item of data is extremely wasteful. The QTZPrivate API should be extended to allow said lookup to be performed on the native data store instead. That leaves 2. Returning a sorted(!) list(!) from the public QTimeZone API. There is no reason why, during the construction of those sorted lists, the data should be held in a set. Instead, the well-known technique of first cramming everything into a result container, which is subsequently sorted and has its duplicates removed, can be used here. Saves more than 8K of text size on AMD64 stripped release builds. Change-Id: I71c2298e94e02d55b0c9fb6f7ebeaed79a1fe2db Reviewed-by: Thiago Macieira <>
Diffstat (limited to 'src/corelib/tools/')
1 files changed, 9 insertions, 4 deletions
diff --git a/src/corelib/tools/ b/src/corelib/tools/
index b0c3c9e64f..f316fe0a6d 100644
--- a/src/corelib/tools/
+++ b/src/corelib/tools/
@@ -41,6 +41,8 @@
#include <qdebug.h>
+#include <algorithm>
@@ -247,18 +249,21 @@ QByteArray QMacTimeZonePrivate::systemTimeZoneId() const
return QCFString::toQString([[NSTimeZone systemTimeZone] name]).toUtf8();
-QSet<QByteArray> QMacTimeZonePrivate::availableTimeZoneIds() const
+QList<QByteArray> QMacTimeZonePrivate::availableTimeZoneIds() const
NSEnumerator *enumerator = [[NSTimeZone knownTimeZoneNames] objectEnumerator];
QByteArray tzid = QCFString::toQString([enumerator nextObject]).toUtf8();
- QSet<QByteArray> set;
+ QList<QByteArray> list;
while (!tzid.isEmpty()) {
- set << tzid;
+ list << tzid;
tzid = QCFString::toQString([enumerator nextObject]).toUtf8();
- return set;
+ std::sort(list.begin(), list.end());
+ list.erase(std::unique(list.begin(), list.end()), list.end());
+ return list;