From 136c5b9338f71775eb42528cfc7c23b2b4e5dff9 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 6 Feb 2017 20:05:02 -0800 Subject: 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) --- src/corelib/io/qresource.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/corelib/io/qresource.cpp') 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 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); -- cgit v1.2.3