Issue 10402 - memmove optimization for std.algorithm.copy
Summary: memmove optimization for std.algorithm.copy
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-18 05:24 UTC by Tommi
Modified: 2024-12-01 16:17 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tommi 2013-06-18 05:24:34 UTC
Add an optimization for:

Range2 copy(Range1, Range2)(Range1 source, Range2 target);

...to use the c function memmove when it is safe to do so and the two ranges overlap each other (when they don't overlap, a vectorized copy should be faster). As far as I can tell, it is safe to use memmove for copying source over target if all of the following are true:

1) Both ranges are arrays (static or dynamic)
2) Both arrays have the same element type
3) hasElaborateAssign!T is false for the element type T

I haven't benchmarked anything, but all the good C++ standard library implementations of std::copy seem to do this optimization, and I trust that they know what they are doing.
Comment 1 Tommi 2013-06-18 06:03:11 UTC
(In reply to comment #0)
> Add an optimization for:
> 
> Range2 copy(Range1, Range2)(Range1 source, Range2 target);
> 
> ...to use the c function memmove when it is safe to do so and the two ranges
> overlap each other (when they don't overlap, a vectorized copy should be
> faster). As far as I can tell, it is safe to use memmove for copying source
> over target if all of the following are true:
> 
> 1) Both ranges are arrays (static or dynamic)
> 2) Both arrays have the same element type
> 3) hasElaborateAssign!T is false for the element type T
> 
> I haven't benchmarked anything, but all the good C++ standard library
> implementations of std::copy seem to do this optimization, and I trust that
> they know what they are doing.

Also, the documentation for std.algorithm.copy should be changed to indicate that the ranges are allowed to overlap if the above conditions hold.
Comment 2 dlangBugzillaToGithub 2024-12-01 16:17:58 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9984

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB