From f30d468cd5096bf8491dcc7bd98726a91e6f745e Mon Sep 17 00:00:00 2001 From: Hamid Reza Date: Wed, 5 Aug 2020 00:30:25 +0430 Subject: [PATCH 1/7] Fix erase with two iterators invokes move / move_backward when the range is empty --- stl/inc/deque | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/stl/inc/deque b/stl/inc/deque index 73a74b7a717..f4b2c54d99a 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1291,25 +1291,25 @@ public: auto _Off = static_cast(_First - begin()); auto _Count = static_cast(_Last - _First); #endif // _ITERATOR_DEBUG_LEVEL == 2 - - if (_Off < static_cast(end() - _Last)) { // closer to front - _STD move_backward(begin(), _First, _Last); // copy over hole - for (; 0 < _Count; --_Count) { - pop_front(); // pop copied elements - } - } else { // closer to back - _STD move(_Last, end(), _First); // copy over hole - for (; 0 < _Count; --_Count) { - pop_back(); // pop copied elements - } - } + if (_Count > 0){ + if (_Off < static_cast(end() - _Last)) { // closer to front + _STD move_backward(begin(), _First, _Last); // copy over hole + for (; 0 < _Count; --_Count) { + pop_front(); // pop copied elements + } + } else { // closer to back + _STD move(_Last, end(), _First); // copy over hole + for (; 0 < _Count; --_Count) { + pop_back(); // pop copied elements + } + } #if _ITERATOR_DEBUG_LEVEL == 2 - if (_Moved) { - _Orphan_all(); - } + if (_Moved) { + _Orphan_all(); + } #endif // _ITERATOR_DEBUG_LEVEL == 2 - + } return begin() + static_cast(_Off); } From 4faede05bd85487454c70169aa394b43a6a008fb Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Wed, 5 Aug 2020 01:07:06 +0430 Subject: [PATCH 2/7] Update indentation --- stl/inc/deque | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/stl/inc/deque b/stl/inc/deque index f4b2c54d99a..c6d49ee2ec7 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1291,25 +1291,25 @@ public: auto _Off = static_cast(_First - begin()); auto _Count = static_cast(_Last - _First); #endif // _ITERATOR_DEBUG_LEVEL == 2 - if (_Count > 0){ - if (_Off < static_cast(end() - _Last)) { // closer to front - _STD move_backward(begin(), _First, _Last); // copy over hole - for (; 0 < _Count; --_Count) { - pop_front(); // pop copied elements - } - } else { // closer to back - _STD move(_Last, end(), _First); // copy over hole - for (; 0 < _Count; --_Count) { - pop_back(); // pop copied elements - } + if (_Count > 0){ + if (_Off < static_cast(end() - _Last)) { // closer to front + _STD move_backward(begin(), _First, _Last); // copy over hole + for (; 0 < _Count; --_Count) { + pop_front(); // pop copied elements } + } else { // closer to back + _STD move(_Last, end(), _First); // copy over hole + for (; 0 < _Count; --_Count) { + pop_back(); // pop copied elements + } + } #if _ITERATOR_DEBUG_LEVEL == 2 - if (_Moved) { - _Orphan_all(); - } -#endif // _ITERATOR_DEBUG_LEVEL == 2 + if (_Moved) { + _Orphan_all(); } +#endif // _ITERATOR_DEBUG_LEVEL == 2 + } return begin() + static_cast(_Off); } From 979539af80eae26480ec1d23bd4907a6020e8da9 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Wed, 5 Aug 2020 01:20:20 +0430 Subject: [PATCH 3/7] Update deque --- stl/inc/deque | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/stl/inc/deque b/stl/inc/deque index c6d49ee2ec7..fb0db2d31e2 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1291,25 +1291,27 @@ public: auto _Off = static_cast(_First - begin()); auto _Count = static_cast(_Last - _First); #endif // _ITERATOR_DEBUG_LEVEL == 2 - if (_Count > 0){ - if (_Off < static_cast(end() - _Last)) { // closer to front - _STD move_backward(begin(), _First, _Last); // copy over hole - for (; 0 < _Count; --_Count) { - pop_front(); // pop copied elements - } - } else { // closer to back - _STD move(_Last, end(), _First); // copy over hole - for (; 0 < _Count; --_Count) { - pop_back(); // pop copied elements - } - } + + if (_Count == 0) + return _First; + if (_Off < static_cast(end() - _Last)) { // closer to front + _STD move_backward(begin(), _First, _Last); // copy over hole + for (; 0 < _Count; --_Count) { + pop_front(); // pop copied elements + } + } else { // closer to back + _STD move(_Last, end(), _First); // copy over hole + for (; 0 < _Count; --_Count) { + pop_back(); // pop copied elements + } + } #if _ITERATOR_DEBUG_LEVEL == 2 - if (_Moved) { - _Orphan_all(); - } + if (_Moved) { + _Orphan_all(); + } #endif // _ITERATOR_DEBUG_LEVEL == 2 - } + return begin() + static_cast(_Off); } From 41fbf72affeabe0d4fca86da2502e8b01cae9271 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Wed, 5 Aug 2020 01:24:52 +0430 Subject: [PATCH 4/7] Update deque --- stl/inc/deque | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/deque b/stl/inc/deque index fb0db2d31e2..0e294f1c8c5 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1293,7 +1293,7 @@ public: #endif // _ITERATOR_DEBUG_LEVEL == 2 if (_Count == 0) - return _First; + return _First; if (_Off < static_cast(end() - _Last)) { // closer to front _STD move_backward(begin(), _First, _Last); // copy over hole for (; 0 < _Count; --_Count) { From 7cc1ec183053b385c2ed08f0619710166f97d50e Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Wed, 5 Aug 2020 02:49:49 +0430 Subject: [PATCH 5/7] Update deque --- stl/inc/deque | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/deque b/stl/inc/deque index 0e294f1c8c5..66eb277e53d 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1293,7 +1293,7 @@ public: #endif // _ITERATOR_DEBUG_LEVEL == 2 if (_Count == 0) - return _First; + return _First; if (_Off < static_cast(end() - _Last)) { // closer to front _STD move_backward(begin(), _First, _Last); // copy over hole for (; 0 < _Count; --_Count) { From 1c679fab79a21c5d16025f29e61334b9d6528509 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Wed, 5 Aug 2020 18:50:07 +0430 Subject: [PATCH 6/7] Update deque --- stl/inc/deque | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stl/inc/deque b/stl/inc/deque index 66eb277e53d..c958ae50a3b 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1292,8 +1292,10 @@ public: auto _Count = static_cast(_Last - _First); #endif // _ITERATOR_DEBUG_LEVEL == 2 - if (_Count == 0) + if (_Count == 0) { return _First; + } + if (_Off < static_cast(end() - _Last)) { // closer to front _STD move_backward(begin(), _First, _Last); // copy over hole for (; 0 < _Count; --_Count) { From 18761f84c4929f2e32be91384e6b4c6cb0fec337 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Wed, 5 Aug 2020 18:53:05 +0430 Subject: [PATCH 7/7] Update deque --- stl/inc/deque | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/deque b/stl/inc/deque index c958ae50a3b..0006d35ae8c 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1295,7 +1295,7 @@ public: if (_Count == 0) { return _First; } - + if (_Off < static_cast(end() - _Last)) { // closer to front _STD move_backward(begin(), _First, _Last); // copy over hole for (; 0 < _Count; --_Count) {