From cae1e9b6d2ec957f8bc4643b898308a404d00a5f Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Tue, 23 Feb 2021 13:08:15 +0200 Subject: Add KEntryMap::constFindEntry() method - This has the same logic as QMap::constFind(); less detaching and now we can use auto keyword when creating iterators and always get a const_iterator even when calling constFindEntry() on a non-const map. - Use QCOMPARE() where appropriate in the unit tests. --- src/core/kconfigdata.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/core/kconfigdata.cpp') diff --git a/src/core/kconfigdata.cpp b/src/core/kconfigdata.cpp index accf869b..5a785c45 100644 --- a/src/core/kconfigdata.cpp +++ b/src/core/kconfigdata.cpp @@ -48,7 +48,7 @@ QMap::Iterator KEntryMap::findEntry(const QByteArray &group, return find(theKey); } -QMap::ConstIterator KEntryMap::findEntry(const QByteArray &group, const QByteArray &key, KEntryMap::SearchFlags flags) const +QMap::ConstIterator KEntryMap::constFindEntry(const QByteArray &group, const QByteArray &key, SearchFlags flags) const { KEntryKey theKey(group, key, false, bool(flags & SearchDefaults)); @@ -56,14 +56,15 @@ QMap::ConstIterator KEntryMap::findEntry(const QByteArray &gr if (flags & SearchLocalized) { theKey.bLocal = true; - ConstIterator it = find(theKey); - if (it != constEnd()) { + auto it = constFind(theKey); + if (it != cend()) { return it; } theKey.bLocal = false; } - return find(theKey); + + return constFind(theKey); } bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const QByteArray &value, KEntryMap::EntryOptions options) @@ -105,7 +106,7 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q } else { // make sure the group marker is in the map KEntryMap const *that = this; - ConstIterator cit = that->findEntry(group); + auto cit = that->constFindEntry(group); if (cit == constEnd()) { insert(KEntryKey(group), KEntry()); } else if (cit->bImmutable) { @@ -212,7 +213,7 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q QString KEntryMap::getEntry(const QByteArray &group, const QByteArray &key, const QString &defaultValue, KEntryMap::SearchFlags flags, bool *expand) const { - const ConstIterator it = findEntry(group, key, flags); + const auto it = constFindEntry(group, key, flags); QString theValue = defaultValue; if (it != constEnd() && !it->bDeleted) { @@ -230,7 +231,7 @@ QString KEntryMap::getEntry(const QByteArray &group, const QByteArray &key, cons bool KEntryMap::hasEntry(const QByteArray &group, const QByteArray &key, KEntryMap::SearchFlags flags) const { - const ConstIterator it = findEntry(group, key, flags); + const auto it = constFindEntry(group, key, flags); if (it == constEnd()) { return false; } -- cgit v1.2.1