QSettings: replace a QMap with a QList

The QMap<QString, QString> was only used to create a sorted,
unique list of keys. The associativeness was never used (the
value was always the null QString).

Better to use a QStringList instead and sort-unique the
whole thing at the end.

Saves ~1.6K in text size on Linux AMD64 GCC 4.9 release C++11
builds, and a tremendous amount of heap allocations.

Change-Id: Idf749dd8924b3894e436aa1cee0304002b898975
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-05-20 19:03:42 +02:00
parent 669487fe95
commit 657e8ffb9e
3 changed files with 13 additions and 7 deletions

View File

@ -299,7 +299,7 @@ QSettingsPrivate *QSettingsPrivate::create(const QString &fileName, QSettings::F
}
#endif
void QSettingsPrivate::processChild(QStringRef key, ChildSpec spec, QMap<QString, QString> &result)
void QSettingsPrivate::processChild(QStringRef key, ChildSpec spec, QStringList &result)
{
if (spec != AllKeys) {
int slashPos = key.indexOf(QLatin1Char('/'));
@ -312,7 +312,7 @@ void QSettingsPrivate::processChild(QStringRef key, ChildSpec spec, QMap<QString
key.truncate(slashPos);
}
}
result.insert(key.toString(), QString());
result.append(key.toString());
}
void QSettingsPrivate::beginGroupOrArray(const QSettingsGroup &group)
@ -1272,7 +1272,7 @@ bool QConfFileSettingsPrivate::get(const QString &key, QVariant *value) const
QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
{
QMap<QString, QString> result;
QStringList result;
ParsedSettingsMap::const_iterator j;
QSettingsKey thePrefix(prefix, caseSensitivity);
@ -1307,7 +1307,10 @@ QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec
break;
}
}
return result.keys();
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()),
result.end());
return result;
}
void QConfFileSettingsPrivate::clear()

View File

@ -491,7 +491,7 @@ bool QMacSettingsPrivate::get(const QString &key, QVariant *value) const
QStringList QMacSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
{
QMap<QString, QString> result;
QStringList result;
int startPos = prefix.size();
for (int i = 0; i < numDomains; ++i) {
@ -513,7 +513,10 @@ QStringList QMacSettingsPrivate::children(const QString &prefix, ChildSpec spec)
if (!fallbacks)
break;
}
return result.keys();
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()),
result.end());
return result;
}
void QMacSettingsPrivate::clear()

View File

@ -211,7 +211,7 @@ public:
const QString &organization, const QString &application);
static QSettingsPrivate *create(const QString &fileName, QSettings::Format format);
static void processChild(QStringRef key, ChildSpec spec, QMap<QString, QString> &result);
static void processChild(QStringRef key, ChildSpec spec, QStringList &result);
// Variant streaming functions
static QStringList variantListToStringList(const QVariantList &l);