This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [RFC] A comment in string::_S_construct(input_iterator)
- From: Nathan Myers <ncm-nospam at cantrip dot org>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Sat, 17 Jan 2004 20:35:58 -0800
- Subject: Re: [RFC] A comment in string::_S_construct(input_iterator)
- References: <40092139.8090501@suse.de>
On Sat, Jan 17, 2004 at 12:49:13PM +0100, Paolo Carlini wrote:
> there is a long standing comment in the code special cased for
> Input Iterators that I have trouble understanding completely:
>
> // NB: this loop looks precisely this way because
> // it avoids comparing __beg != __end any more
> // than strictly necessary; != might be expensive!
>
> ... [is] the comment is really about _comparing_ Input Iterators?
>
> In that case, the chosen loop is really able to reduce the
> number of comparisons? Which are the (so bad) alternatives?
Look at the object code generated when comparing istreambuf_iterators.
You don't want to compare them even one time more than strictly
necessary.
Other formulations of the loop (vs. its original form -- I don't know
if it has been rewritten without changing the comment!) tend to do
a redundant comparison.
Nathan Myers
ncm@cantrip.org