diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-09-06 13:29:38 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-09-07 12:43:25 +0000 |
commit | 1502c59a4e0dde8c5c27ccbe3ff2d6073c77e17a (patch) | |
tree | 2a0d2be22bec688d5ad11f020f3393f4ac34a321 /src | |
parent | acbeb01a785582b6654c0bf21b06b6673d269d76 (diff) |
CanvasTextureImageFactory: fix quadratic loop in notifyLoadedImages()
The old code uses a Java-style iterator on a QList, but
failed to use the iterator's remove() function, opting
instead to call QList::removeOne(). Both would have been
quadratic, but the current code is even worse in that it
re-scans the list for the element 'it' currently points
at.
Fix by using std::remove_if, which is linear, and, since
it doesn't take a copy of the container, also avoids a
deep copy of 'm_loadingImagesList' on actual removal (it
will attempt to detach unconditional now, due to the use
of non-const begin()/end(), but the variable is now no
longer shared with anyone, so there will actually be no
detach.
Change-Id: I71cd08bd40994e86a6470fdd9bcd55c18913b8d8
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/qtcanvas3d/teximage3d.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/imports/qtcanvas3d/teximage3d.cpp b/src/imports/qtcanvas3d/teximage3d.cpp index 315b395..402313e 100644 --- a/src/imports/qtcanvas3d/teximage3d.cpp +++ b/src/imports/qtcanvas3d/teximage3d.cpp @@ -116,17 +116,20 @@ void CanvasTextureImageFactory::notifyLoadedImages() if (!m_loadingImagesList.size()) return; - QMutableListIterator<CanvasTextureImage *> it(m_loadingImagesList); - while (it.hasNext()) { - CanvasTextureImage *image = it.next(); + auto hasLoadingFinishedOrFailed = [](CanvasTextureImage *image) -> bool { if (image->imageState() == CanvasTextureImage::LOADING_FINISHED) { - m_loadingImagesList.removeOne(image); image->emitImageLoaded(); + return true; } else if (image->imageState() == CanvasTextureImage::LOADING_ERROR) { - m_loadingImagesList.removeOne(image); image->emitImageLoadingError(); + return true; } - } + return false; + }; + + m_loadingImagesList.erase(std::remove_if(m_loadingImagesList.begin(), m_loadingImagesList.end(), + hasLoadingFinishedOrFailed), + m_loadingImagesList.end()); } /*! |