summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-02-07 00:13:16 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-02-12 09:58:42 +0000
commita1036990ff0cefc3558702284c68fa5aff0f3174 (patch)
tree916440cceb5556221fc991fb2fd85d8c02386ad0 /src
parentad67867d49c4a7a130084723bfe149fd26c3a9c5 (diff)
QTzTimeZonePrivate: replace an inefficient QList with QVector (III)
The implementation-private QTzType type is larger than void*, so holding them in QLists is horribly inefficient. Fix by holding it in QVector instead (it was already marked as a primitive type before). Text size grows by ca. 0.5K, but of course we got rid of all those pesky heap allocations. Change-Id: I3b70ed36fa9947b695ffc87c6f6199daa13cb7cd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qtimezoneprivate_tz.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp
index da1cadd3ef..233dd9d516 100644
--- a/src/corelib/tools/qtimezoneprivate_tz.cpp
+++ b/src/corelib/tools/qtimezoneprivate_tz.cpp
@@ -210,12 +210,13 @@ static QVector<QTzTransition> parseTzTransitions(QDataStream &ds, int tzh_timecn
return transitions;
}
-static QList<QTzType> parseTzTypes(QDataStream &ds, int tzh_typecnt)
+static QVector<QTzType> parseTzTypes(QDataStream &ds, int tzh_typecnt)
{
- QList<QTzType> typeList;
+ QVector<QTzType> types(tzh_typecnt);
+
// Parse tzh_typecnt x transition types
for (int i = 0; i < tzh_typecnt && ds.status() == QDataStream::Ok; ++i) {
- QTzType type;
+ QTzType &type = types[i];
// Parse UTC Offset, 4 bytes
ds >> type.tz_gmtoff;
// Parse Is DST flag, 1 byte
@@ -227,14 +228,14 @@ static QList<QTzType> parseTzTypes(QDataStream &ds, int tzh_typecnt)
// Set defaults in case not populated later
type.tz_ttisgmt = false;
type.tz_ttisstd = false;
- if (ds.status() == QDataStream::Ok)
- typeList.append(type);
+ if (ds.status() != QDataStream::Ok)
+ types.resize(i);
}
- return typeList;
+ return types;
}
-static QMap<int, QByteArray> parseTzAbbreviations(QDataStream &ds, int tzh_charcnt, QList<QTzType> typeList)
+static QMap<int, QByteArray> parseTzAbbreviations(QDataStream &ds, int tzh_charcnt, const QVector<QTzType> &types)
{
// Parse the abbreviation list which is tzh_charcnt long with '\0' separated strings. The
// QTzType.tz_abbrind index points to the first char of the abbreviation in the array, not the
@@ -252,8 +253,8 @@ static QMap<int, QByteArray> parseTzAbbreviations(QDataStream &ds, int tzh_charc
else
return map;
}
- // Then extract all the substrings pointed to by typeList
- foreach (const QTzType type, typeList) {
+ // Then extract all the substrings pointed to by types
+ foreach (const QTzType &type, types) {
QByteArray abbrev;
for (int i = type.tz_abbrind; input.at(i) != '\0'; ++i)
abbrev.append(input.at(i));
@@ -288,26 +289,26 @@ static void parseTzLeapSeconds(QDataStream &ds, int tzh_leapcnt, bool longTran)
}
}
-static QList<QTzType> parseTzIndicators(QDataStream &ds, const QList<QTzType> &typeList, int tzh_ttisstdcnt, int tzh_ttisgmtcnt)
+static QVector<QTzType> parseTzIndicators(QDataStream &ds, const QVector<QTzType> &types, int tzh_ttisstdcnt, int tzh_ttisgmtcnt)
{
- QList<QTzType> list = typeList;
+ QVector<QTzType> result = types;
bool temp;
// Parse tzh_ttisstdcnt x 1-byte standard/wall indicators
for (int i = 0; i < tzh_ttisstdcnt && ds.status() == QDataStream::Ok; ++i) {
ds >> temp;
if (ds.status() == QDataStream::Ok)
- list[i].tz_ttisstd = temp;
+ result[i].tz_ttisstd = temp;
}
// Parse tzh_ttisgmtcnt x 1-byte UTC/local indicators
for (int i = 0; i < tzh_ttisgmtcnt && ds.status() == QDataStream::Ok; ++i) {
ds >> temp;
if (ds.status() == QDataStream::Ok)
- list[i].tz_ttisgmt = temp;
+ result[i].tz_ttisgmt = temp;
}
- return list;
+ return result;
}
static QByteArray parseTzPosixRule(QDataStream &ds)
@@ -570,7 +571,7 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId)
QVector<QTzTransition> tranList = parseTzTransitions(ds, hdr.tzh_timecnt, false);
if (ds.status() != QDataStream::Ok)
return;
- QList<QTzType> typeList = parseTzTypes(ds, hdr.tzh_typecnt);
+ QVector<QTzType> typeList = parseTzTypes(ds, hdr.tzh_typecnt);
if (ds.status() != QDataStream::Ok)
return;
QMap<int, QByteArray> abbrevMap = parseTzAbbreviations(ds, hdr.tzh_charcnt, typeList);