Use QHash::tryEmplace

Instead of size != oldSize pattern.

Just some locations I could find using a simple regex lookup.

Task-number: QTBUG-130259
Change-Id: I0ac6a4faf8705ce54cb8dd875ee5524ef13f03dc
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Mårten Nordheim 2024-11-28 13:08:25 +01:00
parent 6a5e2c6f9b
commit 370031f809
2 changed files with 4 additions and 10 deletions

View File

@ -337,11 +337,9 @@ void QLoggingRegistry::registerCategory(QLoggingCategory *cat, QtMsgType enableF
{
const auto locker = qt_scoped_lock(registryMutex);
const auto oldSize = categories.size();
auto &e = categories[cat];
if (categories.size() != oldSize) {
auto r = categories.tryEmplace(cat, enableForLevel);
if (r.inserted) {
// new entry
e = enableForLevel;
(*categoryFilter)(cat);
}
}

View File

@ -1688,12 +1688,8 @@ public:
bool insertIfNotContains(Key k, const T &f)
{
const QWriteLocker locker(&lock);
const qsizetype oldSize = map.size();
auto &e = map[k];
if (map.size() == oldSize) // already present
return false;
e = f;
return true;
auto r = map.tryEmplace(k, f);
return r.inserted;
}
const T *function(Key k) const