summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2020-09-02 15:19:16 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2020-09-10 11:24:19 +0200
commit6e8985e3576a4439bd66c0767f9912d1e124682c (patch)
treeb728bc9b0db96215af3a9bf6662b9ef1b0907c0d /src/corelib/tools
parent030962b01c72ffd6e25c8322a3ee6957027d3278 (diff)
Make Q*ArrayOps erase aligned with std::vector::erase
Scoped GrowsBackwards-optimized erase to only be applied when erase starts at the beginning of the element range. In other cases, old "left-shifting" erase is used to align with std::vector::erase invalidation policy Task-number: QTBUG-84320 Change-Id: I2e7f3b96b056bc371119eb2d36cc7c74af52c394 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qarraydataops.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h
index db795e2413..0230677330 100644
--- a/src/corelib/tools/qarraydataops.h
+++ b/src/corelib/tools/qarraydataops.h
@@ -1497,11 +1497,11 @@ public:
Q_ASSERT(b >= this->begin() && b < this->end());
Q_ASSERT(e > this->begin() && e <= this->end());
- // Qt5 QList in erase: try to move less data around
- // Now:
- const T *begin = this->begin();
- const T *end = this->end();
- if (b - begin < end - e) {
+ // Comply with std::vector::erase(): erased elements and all after them
+ // are invalidated. However, erasing from the beginning effectively
+ // means that all iterators are invalidated. We can use this freedom to
+ // erase by moving towards the end.
+ if (b == this->begin()) {
Base::erase(GrowsBackwardsTag{}, b, e);
} else {
Base::erase(GrowsForwardTag{}, b, e);