summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-02-07 21:52:01 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-02-12 17:52:58 +0100
commitc9b967437df344b5fc95121a3560a34bf352c696 (patch)
tree941dbae9ce5a2984442eec7e54537c02bf37a0f4
parent7862453ba9cbcb601b9aad59dd821ae49661de4a (diff)
Add fast-path in QLibraryStore::findOrCreate() for !instance()
If there's no QLibraryStore::instance(), then there's no LibraryMap, so no need to construct a mapName we know we'll just throw away. We must keep locking the qt_library_mutex to check instance(), but we can drop it immediately if we find there isn't, and construct the QLibraryPrivate object outside the critical section (the hope is that the compiler sees this as an opportunity to tail-call). The final goal of this exercise is to get rid of the double-lookup in LibraryMap. Pick-to: 6.7 6.6 6.5 Change-Id: I181dd2657e831a37e2d6f1c5d4df7e2a25ac48cd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/plugin/qlibrary.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index ff1f4513ab..d584dce644 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -407,23 +407,24 @@ inline QLibraryPrivate *QLibraryStore::findOrCreate(const QString &fileName, con
QMutexLocker locker(&qt_library_mutex);
QLibraryStore *data = instance();
+ if (Q_UNLIKELY(!data)) {
+ locker.unlock();
+ return lazyNewLib();
+ }
+
QString mapName = version.isEmpty() ? fileName : fileName + u'\0' + version;
// check if this library is already loaded
- QLibraryPrivate *lib = nullptr;
- if (Q_LIKELY(data)) {
- lib = data->libraryMap.value(mapName);
- if (lib) {
- lib->libraryRefCount.ref();
- lib->mergeLoadHints(loadHints);
- }
- }
- if (!lib)
+ QLibraryPrivate *lib = data->libraryMap.value(mapName);
+ if (lib) {
+ lib->libraryRefCount.ref();
+ lib->mergeLoadHints(loadHints);
+ } else {
lib = lazyNewLib();
+ }
// track this library
- if (Q_LIKELY(data))
- data->libraryMap.insert(mapName, lib);
+ data->libraryMap.insert(mapName, lib);
return lib;
}