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>
This commit is contained in:
Marc Mutz 2015-02-07 00:13:16 +01:00
parent ad67867d49
commit a1036990ff

View File

@ -210,12 +210,13 @@ static QVector<QTzTransition> parseTzTransitions(QDataStream &ds, int tzh_timecn
return transitions; 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 // Parse tzh_typecnt x transition types
for (int i = 0; i < tzh_typecnt && ds.status() == QDataStream::Ok; ++i) { for (int i = 0; i < tzh_typecnt && ds.status() == QDataStream::Ok; ++i) {
QTzType type; QTzType &type = types[i];
// Parse UTC Offset, 4 bytes // Parse UTC Offset, 4 bytes
ds >> type.tz_gmtoff; ds >> type.tz_gmtoff;
// Parse Is DST flag, 1 byte // 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 // Set defaults in case not populated later
type.tz_ttisgmt = false; type.tz_ttisgmt = false;
type.tz_ttisstd = false; type.tz_ttisstd = false;
if (ds.status() == QDataStream::Ok) if (ds.status() != QDataStream::Ok)
typeList.append(type); 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 // 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 // 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 else
return map; return map;
} }
// Then extract all the substrings pointed to by typeList // Then extract all the substrings pointed to by types
foreach (const QTzType type, typeList) { foreach (const QTzType &type, types) {
QByteArray abbrev; QByteArray abbrev;
for (int i = type.tz_abbrind; input.at(i) != '\0'; ++i) for (int i = type.tz_abbrind; input.at(i) != '\0'; ++i)
abbrev.append(input.at(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; bool temp;
// Parse tzh_ttisstdcnt x 1-byte standard/wall indicators // Parse tzh_ttisstdcnt x 1-byte standard/wall indicators
for (int i = 0; i < tzh_ttisstdcnt && ds.status() == QDataStream::Ok; ++i) { for (int i = 0; i < tzh_ttisstdcnt && ds.status() == QDataStream::Ok; ++i) {
ds >> temp; ds >> temp;
if (ds.status() == QDataStream::Ok) if (ds.status() == QDataStream::Ok)
list[i].tz_ttisstd = temp; result[i].tz_ttisstd = temp;
} }
// Parse tzh_ttisgmtcnt x 1-byte UTC/local indicators // Parse tzh_ttisgmtcnt x 1-byte UTC/local indicators
for (int i = 0; i < tzh_ttisgmtcnt && ds.status() == QDataStream::Ok; ++i) { for (int i = 0; i < tzh_ttisgmtcnt && ds.status() == QDataStream::Ok; ++i) {
ds >> temp; ds >> temp;
if (ds.status() == QDataStream::Ok) if (ds.status() == QDataStream::Ok)
list[i].tz_ttisgmt = temp; result[i].tz_ttisgmt = temp;
} }
return list; return result;
} }
static QByteArray parseTzPosixRule(QDataStream &ds) static QByteArray parseTzPosixRule(QDataStream &ds)
@ -570,7 +571,7 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId)
QVector<QTzTransition> tranList = parseTzTransitions(ds, hdr.tzh_timecnt, false); QVector<QTzTransition> tranList = parseTzTransitions(ds, hdr.tzh_timecnt, false);
if (ds.status() != QDataStream::Ok) if (ds.status() != QDataStream::Ok)
return; return;
QList<QTzType> typeList = parseTzTypes(ds, hdr.tzh_typecnt); QVector<QTzType> typeList = parseTzTypes(ds, hdr.tzh_typecnt);
if (ds.status() != QDataStream::Ok) if (ds.status() != QDataStream::Ok)
return; return;
QMap<int, QByteArray> abbrevMap = parseTzAbbreviations(ds, hdr.tzh_charcnt, typeList); QMap<int, QByteArray> abbrevMap = parseTzAbbreviations(ds, hdr.tzh_charcnt, typeList);