-
-
Notifications
You must be signed in to change notification settings - Fork 380
Add paragraph for dealing with ovelapping copying; issue #1317 #527
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
Conversation
|
||
$(P If overlapping is required, first make a duplicate, and then | ||
copy into the original source. Keep in mind the performance hit | ||
hit this would entail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"hit" is duplicated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
) | ||
|
||
--------- | ||
s[0..2] = s[1..3].dup; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we have some library functionality with which we can effectively do s[0] = s[1]; s[1] = s[2];
with a single call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's copy
:
import std.algorithm;
void main()
{
{
int[] s = [1, 2, 3, 4, 5];
s[1..3].copy(s[0..2]);
assert(s == [2, 3, 3, 4, 5]);
}
{
int[] s = [1, 2, 3, 4, 5];
s[0..2] = s[1..3].dup;
assert(s == [2, 3, 3, 4, 5]);
}
}
This should avoid .dup
's memory allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Remove would do this:
int[] s = [1, 2, 3, 4, 5];
s = s.remove(0);
assert(s == [2, 3, 4, 5]);
Yep, encouraging the use of |
Anyhow @Infiltrator could you please amend the example to avoid |
ping |
Looks like not. Can anyone else take this over? |
See #680. |
Closes https://d.puremagic.com/issues/show_bug.cgi?id=1317