This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] A comment in string::_S_construct(input_iterator)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]