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:
parent
669487fe95
commit
657e8ffb9e
@ -299,7 +299,7 @@ QSettingsPrivate *QSettingsPrivate::create(const QString &fileName, QSettings::F
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void QSettingsPrivate::processChild(QStringRef key, ChildSpec spec, QMap<QString, QString> &result)
|
void QSettingsPrivate::processChild(QStringRef key, ChildSpec spec, QStringList &result)
|
||||||
{
|
{
|
||||||
if (spec != AllKeys) {
|
if (spec != AllKeys) {
|
||||||
int slashPos = key.indexOf(QLatin1Char('/'));
|
int slashPos = key.indexOf(QLatin1Char('/'));
|
||||||
@ -312,7 +312,7 @@ void QSettingsPrivate::processChild(QStringRef key, ChildSpec spec, QMap<QString
|
|||||||
key.truncate(slashPos);
|
key.truncate(slashPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.insert(key.toString(), QString());
|
result.append(key.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSettingsPrivate::beginGroupOrArray(const QSettingsGroup &group)
|
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
|
QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
|
||||||
{
|
{
|
||||||
QMap<QString, QString> result;
|
QStringList result;
|
||||||
ParsedSettingsMap::const_iterator j;
|
ParsedSettingsMap::const_iterator j;
|
||||||
|
|
||||||
QSettingsKey thePrefix(prefix, caseSensitivity);
|
QSettingsKey thePrefix(prefix, caseSensitivity);
|
||||||
@ -1307,7 +1307,10 @@ QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec
|
|||||||
break;
|
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()
|
void QConfFileSettingsPrivate::clear()
|
||||||
|
@ -491,7 +491,7 @@ bool QMacSettingsPrivate::get(const QString &key, QVariant *value) const
|
|||||||
|
|
||||||
QStringList QMacSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
|
QStringList QMacSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
|
||||||
{
|
{
|
||||||
QMap<QString, QString> result;
|
QStringList result;
|
||||||
int startPos = prefix.size();
|
int startPos = prefix.size();
|
||||||
|
|
||||||
for (int i = 0; i < numDomains; ++i) {
|
for (int i = 0; i < numDomains; ++i) {
|
||||||
@ -513,7 +513,10 @@ QStringList QMacSettingsPrivate::children(const QString &prefix, ChildSpec spec)
|
|||||||
if (!fallbacks)
|
if (!fallbacks)
|
||||||
break;
|
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()
|
void QMacSettingsPrivate::clear()
|
||||||
|
@ -211,7 +211,7 @@ public:
|
|||||||
const QString &organization, const QString &application);
|
const QString &organization, const QString &application);
|
||||||
static QSettingsPrivate *create(const QString &fileName, QSettings::Format format);
|
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
|
// Variant streaming functions
|
||||||
static QStringList variantListToStringList(const QVariantList &l);
|
static QStringList variantListToStringList(const QVariantList &l);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user