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: [RFA] Algorithms vs operator* and operator==


Paolo Carlini wrote:

Hi,

seems to me the natural development of the improvements to locale_facets
and stl_numeric but want to make sure I'm not missing something before
actually starting on it.

The fundamental observation is rather trivial: for a generic input_iterator
both operator* and operator== can be expensive and we should do our best
to minimize the number of calls throughout in the library.


This morning I changed tentatively std::replace_copy (see attached) and
benchmarked this type of test on my home machine:

....

+ const _ValueType __value = *__first;


I apologise for the (I suspect) slightly confusing mails I've been sending on this subject, but I believe I have finally sorted out what I want to say...

This seems to be the line we have trouble with, as it could lead to an expensive copy. I haven't fully tested it yet, but I wonder if this line would be better expressed as:
typeof(*__first) __value = *__first; (where I've only just found typeof).


I've done some benchmarks, and I'm reasonably convinced that this is both safe and the most efficent way of doing things. If *__first is a reference, we just store the reference and access it twice. If *__first is returned by value, then we only get it by value once and use it twice. Does this seem safe / sensible?

Chris


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