The selection of which set to iterate over and which one to remove
from based on their relative size violates the function's
documentation, which clearly states that items are removed from *this,
and not from `other`, so the result must never contain any elements
from `other`.
Amends 4f2c96eaa8bfa4d8a6dfb92096e4e4030d0cdea7. Instead of reverting
to the gruesome old code with the forced detach-just-to-remove copies,
distinguish four cases:
- if the two sets are shallow copies of each other, then their
intersection is *this
- otherwise, if either set is empty, clear() *this. This is required
for one of the tests that 29017f1395b1bc52e60760fa58c92f6fa4ee4f60
added to succeed.
- otherwise, if *this is detached, perform the operation in-place,
using removeIf()
- otherwise, create a new set and move-assign to *this to avoid
detaching just to remove something again. In this case, we can
continue to iterate over the smaller set, but we need to keep
picking elements from LHS into the result.
[ChangeLog][QtCore][QSet] Fixed a regression (introduced for Qt 5.2)
in intersect() that caused equivalent elements of `*this` to be
overwritten by elements of `other` if `other.size()` was larger than
`this->size()`.
Not picking to 5.15, as users will have likely adjusted their code to
the buggy behavior, and because removeIf() isn't available there.
Pick-to: 6.9 6.8 6.5
Fixes: QTBUG-132536
Task-number: QTBUG-106179
Change-Id: Idfa17c3b3589c4eacec27259fc01df6aeaa6c45f
Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>