[PATCH] Optimize std::advance for single increments

Jonathan Wakely jwakely@redhat.com
Mon Jun 5 11:51:00 GMT 2017


On 05/06/17 12:47 +0200, Marc Glisse wrote:
>On Mon, 5 Jun 2017, Jonathan Wakely wrote:
>
>>LWG 2931 suggests a new overload of std::next for the default n==1
>>case, because it can be simpler for some random access iterators to do
>>++i than i += 1, e.g. for std::deque::iterator.
>>
>>I've suggested we close that issue as NAD, because we don't need a new
>>overload to do that, and here's the proof. This performs the same
>>optimisation when the argument to __advance<RandomAccessIterator> is
>>known at compile-time to be +1 or -1, as is the case when called from
>>std::next(i) or std::prev(i).
>
>Do you want to optimize the case __n == 0 as well? ;-)

I didn't think of that, but we certainly could. With
__builtin_constant_p there's no downside to adding that.




More information about the Gcc-patches mailing list