Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memmove optimization for std.algorithm.copy #9984

Open
dlangBugzillaToGithub opened this issue Jun 18, 2013 · 1 comment
Open

memmove optimization for std.algorithm.copy #9984

dlangBugzillaToGithub opened this issue Jun 18, 2013 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

tommitissari reported this on 2013-06-18T05:24:34Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=10402

Description

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.
@dlangBugzillaToGithub
Copy link
Author

tommitissari commented on 2013-06-18T06:03:11Z

(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.

@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants