This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Is std::search coding fast enough?
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Paolo Carlini <pcarlini at suse dot de>
- Cc: Dimitris Xochellis <jimxoch at yahoo dot gr>, libstdc++ at gcc dot gnu dot org
- Date: Wed, 04 Jul 2007 22:27:09 +0200
- Subject: Re: Is std::search coding fast enough?
- References: <770840.20095.qm@web23112.mail.ird.yahoo.com> <468BE3B3.9080102@suse.de>
Hi,
the below will go in soon. Tested x86-linux.
Paolo.
///////////////////
2007-07-04 Jim Xochellis <jimxoch@yahoo.gr>
* include/bits/stl_algo.h (search(_ForwardIterator1,
_ForwardIterator1, _ForwardIterator2, _ForwardIterator2)): Simplify
general case loop to a for(;;).
(search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2,
_ForwardIterator2, _BinaryPredicate)): Likewise; remove redundant
inner loop.
Index: include/bits/stl_algo.h
===================================================================
--- include/bits/stl_algo.h (revision 126286)
+++ include/bits/stl_algo.h (working copy)
@@ -639,7 +639,7 @@
__p1 = __first2; ++__p1;
_ForwardIterator1 __current = __first1;
- while (__first1 != __last1)
+ for (;;)
{
__first1 = std::find(__first1, __last1, *__first2);
if (__first1 == __last1)
@@ -718,16 +718,10 @@
__p1 = __first2; ++__p1;
_ForwardIterator1 __current = __first1;
- while (__first1 != __last1)
+ for (;;)
{
- while (__first1 != __last1)
- {
- if (__predicate(*__first1, *__first2))
- break;
- ++__first1;
- }
- while (__first1 != __last1 &&
- !bool(__predicate(*__first1, *__first2)))
+ while (__first1 != __last1
+ && !bool(__predicate(*__first1, *__first2)))
++__first1;
if (__first1 == __last1)
return __last1;