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: Doubts about in_avail vs showmanyc


Nathan Myers wrote:

This should end up as:


inline streamsize
in_avail()
{
streamsize __ret = this->egptr() - this->gptr();
return (__ret != 0) ? __ret : this->showmanyc();
}


In other words, in_avail() doesn't care if there's anything in some
putback cell; if there is, that's what's available without a call to
underflow(), and that's what this->gptr() points to, so that's all it
reports. In general, you can cut and _cut_ and *cut* the members of
basic_streambuf<> until they are really easy to understand (and fast).
Put all complexity into the virtuals of the derived classes where speed is less important, because time spent there is amortized over
many characters.


Note that there's no need to test for null pointers because if
one is 0, the others are 0 too and the difference is 0.

Thanks Nathan for this reply and the other.

In general, "cutting and cutting" really scares me, since, until I'm completely sure to understand
the smallest details, I'm _so_ afraid to broke something: I keep asking myself: "if someone put
this here, there must be a reason!". A basic example are those checks for null pointers: there are
many of them!


You'll have to review attentively any patch I wrote in the near future and, in case, reassure me
that I'm doing the right thing.


Paolo.


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