op<< optimizations
Nathan Myers
ncm-nospam@cantrip.org
Mon Feb 3 18:54:00 GMT 2003
I've been corresponding with Jerry Quinn about op<< optimizations.
We were talking about eliminating memcpy operations from the common
execution path. (He has some shocking measurements of memcpy, and
of memmove (used by std::copy<>).)
I sent Jerry code to determine quickly the number of characters in the
decimal expansion of an integer. To make good use of this information
will require either some unholy friend access to streambuf, or (much
better) some interface improvements. I will explain those suggested
improvements here.
A not-insubstantial part of the time spent in op<< is in copying
the formatted results into the streambuf's internal buffer. It
would be better to format directly into that buffer when we can.
To that end, I am proposing three changes to basic_streambuf<>.
I mean to propose versions of them for the next standard.
The first is the simplest: a member _M_fill(_CharT, size_t n),
with obvious semantics. It would be useful for padding out to
the field width efficiently.
The second is a new member _CharT* _M_bypass(_CharT* alt, size_t n).
If there is room for n or more characters in the buffer, i.e.
epptr() - pptr() >= n, it returns pptr(), otherwise it returns alt.
The third change is in sputn(). If the pointer argument is equal
to pptr(), it just advances pptr() by n places forward, without
copying anything.
The latter two changes support formatting directly into the buffer
when there's room, or into another buffer when there isn't, and then
registering the results without needing to remember which it was.
Nathan Myers
ncm-nospam@cantrip.org
More information about the Libstdc++
mailing list