Skip to content

Commit

Permalink
Avoid double-lookup in QLibraryStore::findOrCreate()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
marcmutz committed Feb 15, 2024
1 parent 5738817 commit 7192b11
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/corelib/plugin/qlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 7192b11

Please sign in to comment.