mirror of https://github.com/qt/qtbase.git
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>
This commit is contained in:
parent
7862453ba9
commit
c9b967437d
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue