This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Is std::search coding fast enough #2
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Dimitris Xochellis <jimxoch at yahoo dot gr>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Sun, 08 Jul 2007 23:21:06 +0200
- Subject: Re: Is std::search coding fast enough #2
- References: <105771.31911.qm@web23113.mail.ird.yahoo.com>
Ok, thanks.
I'm finishing testing the below.
Paolo.
////////////
2007-07-08 Jim Xochellis <jimxoch@yahoo.gr>
Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_algo.h (search(_ForwardIterator1,
_ForwardIterator1, _ForwardIterator2, _ForwardIterator2)): Tidy.
(search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2,
_ForwardIterator2, _BinaryPredicate)): Likewise.
Index: stl_algo.h
===================================================================
--- stl_algo.h (revision 126347)
+++ stl_algo.h (working copy)
@@ -624,19 +624,18 @@
typename iterator_traits<_ForwardIterator2>::value_type>)
__glibcxx_requires_valid_range(__first1, __last1);
__glibcxx_requires_valid_range(__first2, __last2);
+
// Test for empty ranges
if (__first1 == __last1 || __first2 == __last2)
return __first1;
// Test for a pattern of length 1.
- _ForwardIterator2 __tmp(__first2);
- ++__tmp;
- if (__tmp == __last2)
+ _ForwardIterator2 __p1(__first2);
+ if (++__p1 == __last2)
return std::find(__first1, __last1, *__first2);
// General case.
- _ForwardIterator2 __p1, __p;
- __p1 = __first2; ++__p1;
+ _ForwardIterator2 __p;
_ForwardIterator1 __current = __first1;
for (;;)
@@ -703,9 +702,8 @@
return __first1;
// Test for a pattern of length 1.
- _ForwardIterator2 __tmp(__first2);
- ++__tmp;
- if (__tmp == __last2)
+ _ForwardIterator2 __p1(__first2);
+ if (++__p1 == __last2)
{
while (__first1 != __last1
&& !bool(__predicate(*__first1, *__first2)))
@@ -714,8 +712,7 @@
}
// General case.
- _ForwardIterator2 __p1, __p;
- __p1 = __first2; ++__p1;
+ _ForwardIterator2 __p;
_ForwardIterator1 __current = __first1;
for (;;)