QSet::remove() calls QHash::remove(), which unconditionally detaches, so fixing the detach there, by pulling the isUnused() check to before detach(), fixes it for both. For removeIf(), the old code used begin()/end() for iteration, detaching unconditionally, even if nothing was removed in the end. In this case, fix by using cbegin()/cend(). That delays the detach() until the first erase(), where it belongs. The end() iterator of QHash (and therefore QSet) are stateless sentinels in all but name, so we can continue to cache end(). Add a code comment to that effect. Amends 62dad9be9e172597c56a970202299563aa04918e (for removeIf()) and 5b7c3e31b538376f2b4733bd868b5875b504cdb3 (for remove()). [ChangeLog][QtCore][QSet] remove() and removeIf() no longer unconditionally detach, but only if something is actually being removed. [ChangeLog][QtCore][QHash] remove() no longer unconditionally detaches, but only if something is actually being removed. Pick-to: 6.9 6.8 6.5 Task-number: QTBUG-106179 Fixes: QTBUG-132831 Change-Id: I807577eafa1be478b0a2da45cf8c44936d5e48ed Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
…
…
Description
Languages
C++
84.3%
HTML
4.9%
C
3.9%
CMake
3.6%
Objective-C++
2%
Other
0.8%