From 6e8dd46a6f4e81617f69c5ba4eca0a74b548290a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 23 Jul 2019 08:38:47 +0300 Subject: QResource: consistently cache resourceList() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each call to reourceList() uses atomic operations to check whether resourceGLobalData has not expired, yet. Some functions already cached the value, but then went on to use the function directly afterwards. In some cases, this was due to the cached value being a pointer-to-const and the function later deciding to mutate the list. But all the code is safe from detaches, so this distinction need not be made. Standardize on caching, and using the cached value, except in functions which call it only once. Change-Id: I79780b990da539bf7beaa8104e13cb8187f84812 Reviewed-by: Edward Welbourne Reviewed-by: MÃ¥rten Nordheim --- src/corelib/io/qresource.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 11d117c990..52b746d04a 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -951,11 +951,12 @@ Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree, if (resourceGlobalData.isDestroyed()) return false; QMutexLocker lock(resourceMutex()); + ResourceList *list = resourceList(); if (version >= 0x01 && version <= 0x3) { bool found = false; QResourceRoot res(version, tree, name, data); - for(int i = 0; i < resourceList()->size(); ++i) { - if(*resourceList()->at(i) == res) { + for (int i = 0; i < list->size(); ++i) { + if (*list->at(i) == res) { found = true; break; } @@ -963,7 +964,7 @@ Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree, if(!found) { QResourceRoot *root = new QResourceRoot(version, tree, name, data); root->ref.ref(); - resourceList()->append(root); + list->append(root); } return true; } @@ -979,9 +980,10 @@ Q_CORE_EXPORT bool qUnregisterResourceData(int version, const unsigned char *tre QMutexLocker lock(resourceMutex()); if (version >= 0x01 && version <= 0x3) { QResourceRoot res(version, tree, name, data); - for(int i = 0; i < resourceList()->size(); ) { - if(*resourceList()->at(i) == res) { - QResourceRoot *root = resourceList()->takeAt(i); + ResourceList *list = resourceList(); + for (int i = 0; i < list->size(); ) { + if (*list->at(i) == res) { + QResourceRoot *root = list->takeAt(i); if(!root->ref.deref()) delete root; } else { @@ -1227,7 +1229,7 @@ QResource::unregisterResource(const QString &rccFilename, const QString &resourc if(res->type() == QResourceRoot::Resource_File) { QDynamicFileResourceRoot *root = reinterpret_cast(res); if (root->mappingFile() == rccFilename && root->mappingRoot() == r) { - resourceList()->removeAt(i); + list->removeAt(i); if(!root->ref.deref()) { delete root; return true; @@ -1298,7 +1300,7 @@ QResource::unregisterResource(const uchar *rccData, const QString &resourceRoot) if(res->type() == QResourceRoot::Resource_Buffer) { QDynamicBufferResourceRoot *root = reinterpret_cast(res); if (root->mappingBuffer() == rccData && root->mappingRoot() == r) { - resourceList()->removeAt(i); + list->removeAt(i); if(!root->ref.deref()) { delete root; return true; -- cgit v1.2.3