Merge several Q_GLOBAL_STATICs in qresource.cpp into one
Since they are all used in a typical application, this reduces the number of memory allocations (thus, the overhead) as well as the state-keeping in the libc atexit() functions. Change-Id: Ifaee7464122d402991b6fffd14a0e59457ad9cb7 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
4f3ea30922
commit
136c5b9338
@ -149,12 +149,23 @@ static QString cleanPath(const QString &_path)
|
||||
|
||||
Q_DECLARE_TYPEINFO(QResourceRoot, Q_MOVABLE_TYPE);
|
||||
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QMutex, resourceMutex, (QMutex::Recursive))
|
||||
|
||||
typedef QList<QResourceRoot*> ResourceList;
|
||||
Q_GLOBAL_STATIC(ResourceList, resourceList)
|
||||
struct QResourceGlobalData
|
||||
{
|
||||
QMutex resourceMutex{QMutex::Recursive};
|
||||
ResourceList resourceList;
|
||||
QStringList resourceSearchPaths;
|
||||
};
|
||||
Q_GLOBAL_STATIC(QResourceGlobalData, resourceGlobalData)
|
||||
|
||||
Q_GLOBAL_STATIC(QStringList, resourceSearchPaths)
|
||||
static inline QMutex *resourceMutex()
|
||||
{ return &resourceGlobalData->resourceMutex; }
|
||||
|
||||
static inline ResourceList *resourceList()
|
||||
{ return &resourceGlobalData->resourceList; }
|
||||
|
||||
static inline QStringList *resourceSearchPaths()
|
||||
{ return &resourceGlobalData->resourceSearchPaths; }
|
||||
|
||||
/*!
|
||||
\class QResource
|
||||
@ -870,6 +881,9 @@ Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree,
|
||||
Q_CORE_EXPORT bool qUnregisterResourceData(int version, const unsigned char *tree,
|
||||
const unsigned char *name, const unsigned char *data)
|
||||
{
|
||||
if (resourceGlobalData.isDestroyed())
|
||||
return false;
|
||||
|
||||
QMutexLocker lock(resourceMutex());
|
||||
if ((version == 0x01 || version == 0x02) && resourceList()) {
|
||||
QResourceRoot res(version, tree, name, data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user