std.algorithm.copy could be better optimized

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Jun 17 10:43:33 PDT 2013


On 6/17/13 1:36 PM, TommiT wrote:
> std.algorithm.copy adheres to the specification of the C++ standard
> library function std::copy. That specification states that the source
> and target ranges may not overlap. Yet, all the major C++ standard
> libraries (libc++, libstdc++, Dinkum C++ Library) implement std::copy so
> that it becomes a memmove if the source and target element types are the
> same and the element type is std::is_trivially_copy_assignable. Thus,
> the current C++ specification seems to be too strict.
>
> The current std.algorithm.copy implementation doesn't get optimized into
> a memmove when it would be safe to do so. It really should, because it's
> the fastest way to get the job done, and it allows the ranges to
> overlap. Also, the documentation should be changed to notify of this
> relaxation.
>
> There's some benchmarks of memmove vs other methods:
> http://nadeausoftware.com/articles/2012/05/c_c_tip_how_copy_memory_quickly

Bugzilla. FWIW I did notice Duff can sometimes beat memmove, but that 
was some 10 years ago.

Andrei


More information about the Digitalmars-d mailing list