summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qresource.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-02-06 20:05:02 -0800
committerThiago Macieira <thiago.macieira@intel.com>2017-02-09 01:22:54 +0000
commit136c5b9338f71775eb42528cfc7c23b2b4e5dff9 (patch)
tree2638b7c14e0593b9d60da5f915948bb4a1b606bd /src/corelib/io/qresource.cpp
parent4f3ea309222bf9af61f721b39265b651ab297914 (diff)
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>
Diffstat (limited to 'src/corelib/io/qresource.cpp')
-rw-r--r--src/corelib/io/qresource.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp
index febf22639c..32639759e4 100644
--- a/src/corelib/io/qresource.cpp
+++ b/src/corelib/io/qresource.cpp
@@ -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)
+
+static inline QMutex *resourceMutex()
+{ return &resourceGlobalData->resourceMutex; }
-Q_GLOBAL_STATIC(QStringList, resourceSearchPaths)
+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);