* Improve std::rotate usages
@ 2018-05-02 5:26 François Dumont
2018-05-14 20:15 ` François Dumont
0 siblings, 1 reply; 8+ messages in thread
From: François Dumont @ 2018-05-02 5:26 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 187 bytes --]
Hi
   std::rotate already returns the expected iterator so there is no
need for calls to std::advance/std::distance.
Tested under Linux x86_64, ok to commit ?
François
[-- Attachment #2: rotate_usages.patch --]
[-- Type: text/x-patch, Size: 3057 bytes --]
diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index e10a692..9c1b2d4 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -1245,11 +1245,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_ForwardIterator __last,
forward_iterator_tag)
{
- if (__first == __middle)
- return __last;
- else if (__last == __middle)
- return __first;
-
_ForwardIterator __first2 = __middle;
do
{
@@ -1290,11 +1285,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
_BidirectionalIterator>)
- if (__first == __middle)
- return __last;
- else if (__last == __middle)
- return __first;
-
std::__reverse(__first, __middle, bidirectional_iterator_tag());
std::__reverse(__middle, __last, bidirectional_iterator_tag());
@@ -1328,11 +1318,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>)
- if (__first == __middle)
- return __last;
- else if (__last == __middle)
- return __first;
-
typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance;
typedef typename iterator_traits<_RandomAccessIterator>::value_type
@@ -1434,6 +1419,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__glibcxx_requires_valid_range(__first, __middle);
__glibcxx_requires_valid_range(__middle, __last);
+ if (__first == __middle)
+ return __last;
+ else if (__last == __middle)
+ return __first;
+
return std::__rotate(__first, __middle, __last,
std::__iterator_category(__first));
}
@@ -1595,9 +1585,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__right_len,
__buffer, __buffer_size);
- std::rotate(__left_split, __middle, __right_split);
- std::advance(__left_split, std::distance(__middle, __right_split));
- return __left_split;
+ return std::rotate(__left_split, __middle, __right_split);
}
template<typename _ForwardIterator, typename _Predicate>
@@ -2396,11 +2384,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __last;
}
else
- {
- std::rotate(__first, __middle, __last);
- std::advance(__first, std::distance(__middle, __last));
- return __first;
- }
+ return std::rotate(__first, __middle, __last);
}
/// This is a helper function for the merge routines.
@@ -2507,9 +2491,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__len11 = std::distance(__first, __first_cut);
}
- std::rotate(__first_cut, __middle, __second_cut);
- _BidirectionalIterator __new_middle = __first_cut;
- std::advance(__new_middle, std::distance(__middle, __second_cut));
+ _BidirectionalIterator __new_middle
+ = std::rotate(__first_cut, __middle, __second_cut);
std::__merge_without_buffer(__first, __first_cut, __new_middle,
__len11, __len22, __comp);
std::__merge_without_buffer(__new_middle, __second_cut, __last,
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Improve std::rotate usages
2018-05-02 5:26 Improve std::rotate usages François Dumont
@ 2018-05-14 20:15 ` François Dumont
2018-05-27 22:01 ` François Dumont
0 siblings, 1 reply; 8+ messages in thread
From: François Dumont @ 2018-05-14 20:15 UTC (permalink / raw)
To: libstdc++, gcc-patches
Any feedback regarding this patch ?
On 02/05/2018 07:26, François Dumont wrote:
> Hi
>
> Â Â Â std::rotate already returns the expected iterator so there is no
> need for calls to std::advance/std::distance.
>
> Tested under Linux x86_64, ok to commit ?
>
> François
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Improve std::rotate usages
2018-05-14 20:15 ` François Dumont
@ 2018-05-27 22:01 ` François Dumont
2018-06-08 5:55 ` François Dumont
2018-08-07 14:12 ` Jonathan Wakely
0 siblings, 2 replies; 8+ messages in thread
From: François Dumont @ 2018-05-27 22:01 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1131 bytes --]
Still no chance to review it ?
I'd like this one to go in before submitting other algo related patches.
   * include/bits/stl_algo.h
   (__rotate(_Ite, _Ite, _Ite, forward_iterator_tag))
   (__rotate(_Ite, _Ite, _Ite, bidirectional_iterator_tag))
   (__rotate(_Ite, _Ite, _Ite, random_access_iterator_tag)): Move code
duplication...
   (rotate(_Ite, _Ite, _Ite)): ...here.
   (__stable_partition_adaptive(_FIt, _FIt, _Pred, _Dist, _Pointer,
_Dist)):
   Simplify rotate call.
   (__rotate_adaptive(_BIt1, _BIt1, _BIt1, _Dist, _Dist, _Bit2, _Dist)):
   Likewise.
   (__merge_without_buffer(_BIt, _BIt, _BIt, _Dist, _Dist, _Comp)):
   Likewise.
François
On 14/05/2018 22:14, François Dumont wrote:
> Any feedback regarding this patch ?
>
>
> On 02/05/2018 07:26, François Dumont wrote:
>> Hi
>>
>> Â Â Â std::rotate already returns the expected iterator so there is no
>> need for calls to std::advance/std::distance.
>>
>> Tested under Linux x86_64, ok to commit ?
>>
>> François
>>
>
[-- Attachment #2: rotate_usages.patch --]
[-- Type: text/x-patch, Size: 3057 bytes --]
diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index e10a692..9c1b2d4 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -1245,11 +1245,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_ForwardIterator __last,
forward_iterator_tag)
{
- if (__first == __middle)
- return __last;
- else if (__last == __middle)
- return __first;
-
_ForwardIterator __first2 = __middle;
do
{
@@ -1290,11 +1285,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
_BidirectionalIterator>)
- if (__first == __middle)
- return __last;
- else if (__last == __middle)
- return __first;
-
std::__reverse(__first, __middle, bidirectional_iterator_tag());
std::__reverse(__middle, __last, bidirectional_iterator_tag());
@@ -1328,11 +1318,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>)
- if (__first == __middle)
- return __last;
- else if (__last == __middle)
- return __first;
-
typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance;
typedef typename iterator_traits<_RandomAccessIterator>::value_type
@@ -1434,6 +1419,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__glibcxx_requires_valid_range(__first, __middle);
__glibcxx_requires_valid_range(__middle, __last);
+ if (__first == __middle)
+ return __last;
+ else if (__last == __middle)
+ return __first;
+
return std::__rotate(__first, __middle, __last,
std::__iterator_category(__first));
}
@@ -1595,9 +1585,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__right_len,
__buffer, __buffer_size);
- std::rotate(__left_split, __middle, __right_split);
- std::advance(__left_split, std::distance(__middle, __right_split));
- return __left_split;
+ return std::rotate(__left_split, __middle, __right_split);
}
template<typename _ForwardIterator, typename _Predicate>
@@ -2396,11 +2384,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __last;
}
else
- {
- std::rotate(__first, __middle, __last);
- std::advance(__first, std::distance(__middle, __last));
- return __first;
- }
+ return std::rotate(__first, __middle, __last);
}
/// This is a helper function for the merge routines.
@@ -2507,9 +2491,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__len11 = std::distance(__first, __first_cut);
}
- std::rotate(__first_cut, __middle, __second_cut);
- _BidirectionalIterator __new_middle = __first_cut;
- std::advance(__new_middle, std::distance(__middle, __second_cut));
+ _BidirectionalIterator __new_middle
+ = std::rotate(__first_cut, __middle, __second_cut);
std::__merge_without_buffer(__first, __first_cut, __new_middle,
__len11, __len22, __comp);
std::__merge_without_buffer(__new_middle, __second_cut, __last,
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Improve std::rotate usages
2018-05-27 22:01 ` François Dumont
@ 2018-06-08 5:55 ` François Dumont
2018-06-12 20:39 ` François Dumont
2018-07-24 10:23 ` François Dumont
2018-08-07 14:12 ` Jonathan Wakely
1 sibling, 2 replies; 8+ messages in thread
From: François Dumont @ 2018-06-08 5:55 UTC (permalink / raw)
To: libstdc++, gcc-patches
Gentle reminder.
On 27/05/2018 19:25, François Dumont wrote:
> Still no chance to review it ?
>
> I'd like this one to go in before submitting other algo related patches.
>
> Â Â Â * include/bits/stl_algo.h
> Â Â Â (__rotate(_Ite, _Ite, _Ite, forward_iterator_tag))
> Â Â Â (__rotate(_Ite, _Ite, _Ite, bidirectional_iterator_tag))
> Â Â Â (__rotate(_Ite, _Ite, _Ite, random_access_iterator_tag)): Move
> code duplication...
> Â Â Â (rotate(_Ite, _Ite, _Ite)): ...here.
> Â Â Â (__stable_partition_adaptive(_FIt, _FIt, _Pred, _Dist, _Pointer,
> _Dist)):
> Â Â Â Simplify rotate call.
> Â Â Â (__rotate_adaptive(_BIt1, _BIt1, _BIt1, _Dist, _Dist, _Bit2, _Dist)):
> Â Â Â Likewise.
> Â Â Â (__merge_without_buffer(_BIt, _BIt, _BIt, _Dist, _Dist, _Comp)):
> Â Â Â Likewise.
>
> François
>
> On 14/05/2018 22:14, François Dumont wrote:
>> Any feedback regarding this patch ?
>>
>>
>> On 02/05/2018 07:26, François Dumont wrote:
>>> Hi
>>>
>>> Â Â Â std::rotate already returns the expected iterator so there is no
>>> need for calls to std::advance/std::distance.
>>>
>>> Tested under Linux x86_64, ok to commit ?
>>>
>>> François
>>>
>>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Improve std::rotate usages
2018-06-08 5:55 ` François Dumont
@ 2018-06-12 20:39 ` François Dumont
2018-06-12 23:13 ` Jonathan Wakely
2018-07-24 10:23 ` François Dumont
1 sibling, 1 reply; 8+ messages in thread
From: François Dumont @ 2018-06-12 20:39 UTC (permalink / raw)
To: libstdc++, gcc-patches
I'm struggling having a validation for this patch.
As it is a trivial one and to not bother you I plan to commit it
tomorrow if not told otherwise.
François
On 08/06/2018 07:54, François Dumont wrote:
> Gentle reminder.
>
> On 27/05/2018 19:25, François Dumont wrote:
>> Still no chance to review it ?
>>
>> I'd like this one to go in before submitting other algo related patches.
>>
>> Â Â Â * include/bits/stl_algo.h
>> Â Â Â (__rotate(_Ite, _Ite, _Ite, forward_iterator_tag))
>> Â Â Â (__rotate(_Ite, _Ite, _Ite, bidirectional_iterator_tag))
>> Â Â Â (__rotate(_Ite, _Ite, _Ite, random_access_iterator_tag)): Move
>> code duplication...
>> Â Â Â (rotate(_Ite, _Ite, _Ite)): ...here.
>> Â Â Â (__stable_partition_adaptive(_FIt, _FIt, _Pred, _Dist, _Pointer,
>> _Dist)):
>> Â Â Â Simplify rotate call.
>> Â Â Â (__rotate_adaptive(_BIt1, _BIt1, _BIt1, _Dist, _Dist, _Bit2,
>> _Dist)):
>> Â Â Â Likewise.
>> Â Â Â (__merge_without_buffer(_BIt, _BIt, _BIt, _Dist, _Dist, _Comp)):
>> Â Â Â Likewise.
>>
>> François
>>
>> On 14/05/2018 22:14, François Dumont wrote:
>>> Any feedback regarding this patch ?
>>>
>>>
>>> On 02/05/2018 07:26, François Dumont wrote:
>>>> Hi
>>>>
>>>> Â Â Â std::rotate already returns the expected iterator so there is
>>>> no need for calls to std::advance/std::distance.
>>>>
>>>> Tested under Linux x86_64, ok to commit ?
>>>>
>>>> François
>>>>
>>>
>>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Improve std::rotate usages
2018-06-12 20:39 ` François Dumont
@ 2018-06-12 23:13 ` Jonathan Wakely
0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Wakely @ 2018-06-12 23:13 UTC (permalink / raw)
To: François Dumont; +Cc: libstdc++, gcc-patches
On 12/06/18 22:39 +0200, François Dumont wrote:
>I'm struggling having a validation for this patch.
>
>As it is a trivial one and to not bother you I plan to commit it
>tomorrow if not told otherwise.
No, please wait for review.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Improve std::rotate usages
2018-06-08 5:55 ` François Dumont
2018-06-12 20:39 ` François Dumont
@ 2018-07-24 10:23 ` François Dumont
1 sibling, 0 replies; 8+ messages in thread
From: François Dumont @ 2018-07-24 10:23 UTC (permalink / raw)
To: libstdc++, gcc-patches
Ping.
On 08/06/2018 07:54, François Dumont wrote:
> Gentle reminder.
>
> On 27/05/2018 19:25, François Dumont wrote:
>> Still no chance to review it ?
>>
>> I'd like this one to go in before submitting other algo related patches.
>>
>> Â Â Â * include/bits/stl_algo.h
>> Â Â Â (__rotate(_Ite, _Ite, _Ite, forward_iterator_tag))
>> Â Â Â (__rotate(_Ite, _Ite, _Ite, bidirectional_iterator_tag))
>> Â Â Â (__rotate(_Ite, _Ite, _Ite, random_access_iterator_tag)): Move
>> code duplication...
>> Â Â Â (rotate(_Ite, _Ite, _Ite)): ...here.
>> Â Â Â (__stable_partition_adaptive(_FIt, _FIt, _Pred, _Dist, _Pointer,
>> _Dist)):
>> Â Â Â Simplify rotate call.
>> Â Â Â (__rotate_adaptive(_BIt1, _BIt1, _BIt1, _Dist, _Dist, _Bit2,
>> _Dist)):
>> Â Â Â Likewise.
>> Â Â Â (__merge_without_buffer(_BIt, _BIt, _BIt, _Dist, _Dist, _Comp)):
>> Â Â Â Likewise.
>>
>> François
>>
>> On 14/05/2018 22:14, François Dumont wrote:
>>> Any feedback regarding this patch ?
>>>
>>>
>>> On 02/05/2018 07:26, François Dumont wrote:
>>>> Hi
>>>>
>>>> Â Â Â std::rotate already returns the expected iterator so there is
>>>> no need for calls to std::advance/std::distance.
>>>>
>>>> Tested under Linux x86_64, ok to commit ?
>>>>
>>>> François
>>>>
>>>
>>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Improve std::rotate usages
2018-05-27 22:01 ` François Dumont
2018-06-08 5:55 ` François Dumont
@ 2018-08-07 14:12 ` Jonathan Wakely
1 sibling, 0 replies; 8+ messages in thread
From: Jonathan Wakely @ 2018-08-07 14:12 UTC (permalink / raw)
To: François Dumont; +Cc: libstdc++, gcc-patches
On 27/05/18 19:25 +0200, François Dumont wrote:
>Still no chance to review it ?
>
>I'd like this one to go in before submitting other algo related patches.
>
>Â Â Â * include/bits/stl_algo.h
>Â Â Â (__rotate(_Ite, _Ite, _Ite, forward_iterator_tag))
>Â Â Â (__rotate(_Ite, _Ite, _Ite, bidirectional_iterator_tag))
>Â Â Â (__rotate(_Ite, _Ite, _Ite, random_access_iterator_tag)): Move
>code duplication...
>Â Â Â (rotate(_Ite, _Ite, _Ite)): ...here.
>Â Â Â (__stable_partition_adaptive(_FIt, _FIt, _Pred, _Dist, _Pointer,
>_Dist)):
>Â Â Â Simplify rotate call.
>Â Â Â (__rotate_adaptive(_BIt1, _BIt1, _BIt1, _Dist, _Dist, _Bit2, _Dist)):
>Â Â Â Likewise.
>Â Â Â (__merge_without_buffer(_BIt, _BIt, _BIt, _Dist, _Dist, _Comp)):
>Â Â Â Likewise.
>
>François
>
>On 14/05/2018 22:14, François Dumont wrote:
>>Any feedback regarding this patch ?
>>
>>
>>On 02/05/2018 07:26, François Dumont wrote:
>>>Hi
>>>
>>>Â Â Â std::rotate already returns the expected iterator so there is
>>>no need for calls to std::advance/std::distance.
Yes, looks like that code predated DR 488 which changed the return
type of std::rotate.
OK for trunk, thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-08-07 14:12 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-02 5:26 Improve std::rotate usages François Dumont
2018-05-14 20:15 ` François Dumont
2018-05-27 22:01 ` François Dumont
2018-06-08 5:55 ` François Dumont
2018-06-12 20:39 ` François Dumont
2018-06-12 23:13 ` Jonathan Wakely
2018-07-24 10:23 ` François Dumont
2018-08-07 14:12 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).