This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Minor tweak to search_n
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 30 Sep 2003 19:05:13 +0200
- Subject: [v3] Minor tweak to search_n
Hi,
subject says it all. Tested x86-linux, committed.
Paolo.
//////////////
2003-09-30 Paolo Carlini <pcarlini@unitus.it>
* include/bits/stl_algo.h (search_n): Tweak, to spare the
first --__n.
diff -urN libstdc++-v3-orig/include/bits/stl_algo.h libstdc++-v3/include/bits/stl_algo.h
--- libstdc++-v3-orig/include/bits/stl_algo.h 2003-09-29 20:09:01.000000000 +0200
+++ libstdc++-v3/include/bits/stl_algo.h 2003-09-29 22:46:14.000000000 +0200
@@ -610,14 +610,13 @@
__first = std::find(__first, __last, __val);
while (__first != __last) {
typename iterator_traits<_ForwardIterator>::difference_type __n = __count;
- --__n;
_ForwardIterator __i = __first;
++__i;
- while (__i != __last && __n != 0 && *__i == __val) {
+ while (__i != __last && __n != 1 && *__i == __val) {
++__i;
--__n;
}
- if (__n == 0)
+ if (__n == 1)
return __first;
else
__first = std::find(__i, __last, __val);
@@ -663,14 +662,13 @@
}
while (__first != __last) {
typename iterator_traits<_ForwardIterator>::difference_type __n = __count;
- --__n;
_ForwardIterator __i = __first;
++__i;
- while (__i != __last && __n != 0 && __binary_pred(*__i, __val)) {
+ while (__i != __last && __n != 1 && __binary_pred(*__i, __val)) {
++__i;
--__n;
}
- if (__n == 0)
+ if (__n == 1)
return __first;
else {
while (__i != __last) {