[Patch] To _M_extract_float for redundant operator*() and more

Paolo Carlini pcarlini@suse.de
Sun Oct 31 18:26:00 GMT 2004


Hi,

this patch deals with the most subtle issue I have faced during the
last weeks... Fiuuuu! I tried to summarize it in the ChangeLog.

Consider an istreambuf_iterator: operator*() is defined to return
sgetc() of the underlying streambuf. Now, in the unbuffered case,
underflow() is not guaranteed to return the same value if called
many times in a row! This means that, in principle, we *cannot*
dereference many times a generic input iterator and assume that
the value is always the same. Indeed, consistently, the standard
in 22.2.2.1.2, Stage 2, mandates to dereference 'in' one time
for each increment and do the whole work.

There is also a performance issue, indeed: just have a look to
the implementation of istreambuf_iterator to see what I mean:
both operator*() and operator!= are *really* expensive!

Thus the below.

The basic idea is introducing __testeof which becomes true as soon
as __beg == __end and is propagated downstream. Every time we have
to increment __beg we do:

    if (++__beg != __end)
       __c = *__beg;
    else
       __testeof = true;

and everything becomes correct.

There is also a nice performance implication: statically linked
testcases parsing floats become about 5% faster (1-2% in the
dynamically linked case).

Tested x86-linux, will test further on x86_64 and, if nobody objects,
commit tomorrow. Of course, integers and money_get will need the
same treatment...

Paolo.

////////////////
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CL_extract_float
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20041031/9776fcfa/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch_extract_float
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20041031/9776fcfa/attachment-0001.ksh>


More information about the Libstdc++ mailing list