[Patch] Fix libstdc++/11722
Nathan Myers
ncm-nospam@cantrip.org
Tue Sep 14 13:05:00 GMT 2004
On Mon, Sep 13, 2004 at 04:19:58PM -0500, Benjamin Kosnik wrote:
>
> >mainline
> >--------
> >22.190u 25.310s 0:47.68 99.6% 0+0k 0+0io 200pf+0w
> >
> >mainline + patch
> >----------------
> > 0.250u 0.250s 0:00.50 100.0% 0+0k 0+0io 199pf+0w
>
> You are to be congratulated sir! This end result is great, and the patch
> looks quite fine as well.
>
> >(*) After a period of testing maybe suited for 3_4-branch too.
Sorry for being late with this, but isn't
+ if (__avail == 1)
+ *__s = *this->gptr();
+ else if (__avail > 1)
+ traits_type::move(__s, this->gptr(), __avail);
+ __s += __avail;
+ this->gbump(__avail);
+ __ret += __avail;
+ __n -= __avail;
a bit too precious? Maybe
if (__avail != 0)
{
traits_type::copy(__s, this->gptr(), __avail);
__s += __avail;
this->gbump(__avail);
__ret += __avail;
__n -= __avail;
}
This way it doesn't waste time checking __gptr < __egptr again
when __avail == 1, and doesn't waste time adding zeroes to __s,
__ret, and __n when __avail == 0. A really smart optimizer
might do part of that transformation, but it seems clearer not
to depend on it.
We are at least certain that the target __s doesn't overlap the
buffer, so traits_type::copy suffices, and ought to be faster.
(If not, then std::copy needs work too.)
Nathan Myers
ncm-nospam@cantrip.org
More information about the Libstdc++
mailing list