aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2017-06-05 11:34:13 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2017-06-05 11:34:13 +0100
commit6c2417786217d33b27e7079647ed5f1b10b235c7 (patch)
tree6bc2ea8896e22b2dcc0ccc167b52b5e8895759e7 /libstdc++-v3
parentd08606ce6ceef0cb9fb2620e7dc2685867ce00df (diff)
downloadgcc-6c2417786217d33b27e7079647ed5f1b10b235c7.zip
gcc-6c2417786217d33b27e7079647ed5f1b10b235c7.tar.gz
gcc-6c2417786217d33b27e7079647ed5f1b10b235c7.tar.bz2
Optimize std::advance for single increments
* include/bits/stl_iterator_base_funcs.h (__advance<_RandomAccessIterator, _Distance>): Optimize for next/prev cases where incrementing or decrementing a single step. From-SVN: r248875
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog4
-rw-r--r--libstdc++-v3/include/bits/stl_iterator_base_funcs.h7
2 files changed, 10 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 4ee4c42..0b08810 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,9 @@
2017-06-05 Jonathan Wakely <jwakely@redhat.com>
+ * include/bits/stl_iterator_base_funcs.h
+ (__advance<_RandomAccessIterator, _Distance>): Optimize for next/prev
+ cases where incrementing or decrementing a single step.
+
* include/bits/shared_ptr_base.h (__shared_ptr::owner_before)
(__weak_ptr::owner_before, _Sp_owner_less::operator()): Add noexcept
specifiers as per LWG 2873 and LWG 2942.
diff --git a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
index ce6c3d2..e14a22c 100644
--- a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
+++ b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
@@ -177,7 +177,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// concept requirements
__glibcxx_function_requires(_RandomAccessIteratorConcept<
_RandomAccessIterator>)
- __i += __n;
+ if (__builtin_constant_p(__n) && __n == 1)
+ ++__i;
+ else if (__builtin_constant_p(__n) && __n == -1)
+ --__i;
+ else
+ __i += __n;
}
/**