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: [Patch] Fix istream::ignore + minor things


Would your ignore code benefit from using __builtin_expect (see example
below)?

-          if (__n != numeric_limits<streamsize>::max())
+          if (__builtin_expect(__n !=
numeric_limits<streamsize>::max(),1))

-----Original Message-----
From: Paolo Carlini [mailto:pcarlini@suse.de] 
Sent: Sunday, May 23, 2004 11:50 AM
To: libstdc++
Subject: [Patch] Fix istream::ignore + minor things

Hi,

eventually I fixed ignore this way (__n is > 0 here):

-          while (_M_gcount < __n

+          if (__n != numeric_limits<streamsize>::max())
+            --__n;
+          while (_M_gcount <= __n

Another possibility, would be playing with _M_gcount, inizializing it to
1 and the --_M_gcount at the end. This permits to spare the conditional
but breaks the general assumption that, at any given moment, _M_gcount
<= number extracted chars. I don't like that.

Took the occasion to tweak a few other bits, tighten some testcases and
add a new one.

Tested x86-linux.

Paolo.

////////////




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