From 59e6b15f513cc998ce13e9e49e2a6a3ace445ebb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 15 Mar 2018 21:05:06 +0300 Subject: LIST<> iterators: - new method LIST::removeItem added to save a pointer to removed record; - code cleaning related to the fact that LIST::remove() shall be the last operation inside an iterator, because otherwise the reference to it will point to a record next to deleted one; - a few remaining cycles converted to iterators --- plugins/Clist_modern/src/modern_skinengine.cpp | 23 +++++++++++------------ plugins/Clist_modern/src/modern_xptheme.cpp | 12 +++++------- 2 files changed, 16 insertions(+), 19 deletions(-) (limited to 'plugins/Clist_modern/src') diff --git a/plugins/Clist_modern/src/modern_skinengine.cpp b/plugins/Clist_modern/src/modern_skinengine.cpp index 986de4cac7..d51deeebf1 100644 --- a/plugins/Clist_modern/src/modern_skinengine.cpp +++ b/plugins/Clist_modern/src/modern_skinengine.cpp @@ -527,21 +527,20 @@ int ske_ReleaseBufferDC(HDC hDC, int keepTime) //Try to find DC in buffer list - set flag to be release after time; mir_cslock lck(BufferListCS); - for (int i = 0; i < BufferList.getCount(); i++) { - DCBUFFER *pBuf = BufferList[i]; - if (pBuf) { - if (hDC != nullptr && pBuf->hDC == hDC) { - pBuf->dwDestroyAfterTime = dwCurrentTime + keepTime; + auto T = BufferList.rev_iter(); + for (auto &it : T) { + if (it) { + if (hDC != nullptr && it->hDC == hDC) { + it->dwDestroyAfterTime = dwCurrentTime + keepTime; break; } - if ((pBuf->dwDestroyAfterTime && pBuf->dwDestroyAfterTime < dwCurrentTime) || keepTime == -1) { - SelectObject(pBuf->hDC, pBuf->oldBitmap); - DeleteObject(pBuf->hBitmap); - DeleteDC(pBuf->hDC); - mir_free(pBuf); - BufferList.remove(i); - i--; + if ((it->dwDestroyAfterTime && it->dwDestroyAfterTime < dwCurrentTime) || keepTime == -1) { + SelectObject(it->hDC, it->oldBitmap); + DeleteObject(it->hBitmap); + DeleteDC(it->hDC); + mir_free(it); + BufferList.remove(T.indexOf(&it)); } } } diff --git a/plugins/Clist_modern/src/modern_xptheme.cpp b/plugins/Clist_modern/src/modern_xptheme.cpp index 6122fa21f6..bff9e8a7fb 100644 --- a/plugins/Clist_modern/src/modern_xptheme.cpp +++ b/plugins/Clist_modern/src/modern_xptheme.cpp @@ -72,14 +72,12 @@ void xpt_FreeThemeHandle(XPTHANDLE xptHandle) void xpt_FreeThemeForWindow(HWND hwnd) { mir_cslock lck(xptCS); - for (int i = 0; i < xptObjectList.getCount();) { - XPTObject& xptObject = xptObjectList[i]; - if (xptObject.hOwnerWindow == hwnd) { - _sttXptCloseThemeData(&xptObject); - xptObjectList.remove(i); + auto T = xptObjectList.rev_iter(); + for (auto &xptObject : T) + if (xptObject->hOwnerWindow == hwnd) { + _sttXptCloseThemeData(xptObject); + xptObjectList.remove(T.indexOf(&xptObject)); } - else i++; - } } void xpt_OnWM_THEMECHANGED() -- cgit v1.2.3