summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-02-07 22:06:26 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-02-15 22:29:53 +0100
commit7192b1184190982b6422196121821838d9fcbba6 (patch)
tree4bc2866b3cb634e871b34ecfcf036fd2dafac1a5
parent57388179a41a169d4f6d65a385f605af31722bf2 (diff)
Avoid double-lookup in QLibraryStore::findOrCreate()
The code is in a critical section, so don't waste time traversing the QMap twice. Now that two previous commits have re-arranged the code such that lookup and insertion are symmetric, we can combine them into a single lookup using operator[]. Pick-to: 6.7 6.6 6.5 Change-Id: I4a10cece65b8c35d05a9b80967bf15d2e15bd73f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/plugin/qlibrary.cpp7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index d584dce644..622b244d19 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -414,18 +414,15 @@ inline QLibraryPrivate *QLibraryStore::findOrCreate(const QString &fileName, con
QString mapName = version.isEmpty() ? fileName : fileName + u'\0' + version;
- // check if this library is already loaded
- QLibraryPrivate *lib = data->libraryMap.value(mapName);
+ QLibraryPrivate *&lib = data->libraryMap[std::move(mapName)];
if (lib) {
+ // already loaded
lib->libraryRefCount.ref();
lib->mergeLoadHints(loadHints);
} else {
lib = lazyNewLib();
}
- // track this library
- data->libraryMap.insert(mapName, lib);
-
return lib;
}