diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-07-23 08:38:47 +0300 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-08-01 07:46:29 +0300 |
commit | 6e8dd46a6f4e81617f69c5ba4eca0a74b548290a (patch) | |
tree | be98c9f3449e839f19ebec83cbea56bc065df77e | |
parent | 231b70c2941a270ff9a3fb75c0a4bb1210a1ea2e (diff) |
QResource: consistently cache resourceList()
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 <edward.welbourne@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r-- | src/corelib/io/qresource.cpp | 18 |
1 files 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<QDynamicFileResourceRoot*>(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<QDynamicBufferResourceRoot*>(res); if (root->mappingBuffer() == rccData && root->mappingRoot() == r) { - resourceList()->removeAt(i); + list->removeAt(i); if(!root->ref.deref()) { delete root; return true; |