-
-
Notifications
You must be signed in to change notification settings - Fork 700
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
Fix Issue 16996 - std.algorithm.remove with SwapStrategy.unstable rem… #4979
Conversation
|
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. Thanks a lot for the quick fix!
This LGTM, but given that I accidentally found this while adding trying to find simple public examples, how about adding a couple of internal tests to ensure everything is working fine?
Maybe with the famous DummyRange (there's also a "potential buggy" remove
specialization for only bidirectional ranges).
Last but not least it would be great if you could annotate a unittest
block with @nogc
, s.t. we ensure that at least the unstable
SwappingStrategy doesn't allocate.
Ok, I'll add more thorough unit testing for both stable and unstable |
24a0454
to
229d373
Compare
I've added a rather extreme
Swapping strategy does not affect whether it allocates, so I included every function in the annotated |
if (i < prev) | ||
return false; | ||
prev = i; | ||
} |
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.
you could also use https://dlang.org/phobos/std_algorithm_sorting.html#isStrictlyMonotonic
foreach (i; r) | ||
foreach (offset; offsets) | ||
if (i >= offset[0] && i < offset[1]) | ||
return false; |
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.
If you want to avoid the "red", uncovered line you could do sth. like:
import std.algorithm.searching : any, canFind;
import std.range : only;
return r.any!(e => !offsets.only.canFind!(o => o[0] <= e && e < o[1]));
r = r.remove!(pred, SwapStrategy.stable); | ||
} | ||
|
||
unittest |
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.
FYI: (not important for now) in the near future there might be a new check that ensures that all unittests have either a @safe
or a `@system attribute, because it helps to avoid regressions.
Excellent work! (I have marked this for 2.073.0-b0 milestone) |
…oves more entries
229d373
to
7c784a6
Compare
7c784a6
to
99b74fb
Compare
Regarding your latest feedback: |
Auto-merge toggled on |
…oves more entries
https://issues.dlang.org/show_bug.cgi?id=16996
#4973 (comment)
Note: since I renamed the
steps
variable, the split diff view is recommended.