Bug 18280 – std.algorithm.comparison.cmp for non-strings should call opCmp only once per item pair
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-01-22T23:27:26Z
Last change time
2018-01-24T18:05:30Z
Assigned to
No Owner
Creator
Nathan S.
Comments
Comment #0 by n8sh.secondary — 2018-01-22T23:27:26Z
Right now when comparing non-string ranges std.algorithm.comparison.cmp calls the comparison predicate twice for every pair of elements to determine their order. When the elements have overloaded `opCmp` and the predicate is "a < b" we only need to call `opCmp` once for each pair.
Comment #1 by github-bugzilla — 2018-01-24T18:05:29Z
Commits pushed to master at https://github.com/dlang/phoboshttps://github.com/dlang/phobos/commit/7f59e5ad526ee4bf856e8235e3042bb5cd442ad4
Fix Issue 18280 - std.algorithm.comparison.cmp for non-strings should call opCmp only once per item pair
split cmp into two overloads per @andralex
https://github.com/dlang/phobos/pull/6056#pullrequestreview-90687092
Minor adjustments, again
cmp should return auto and let opCmp drive
https://github.com/dlang/phobos/pull/6056#issuecomment-359665184
Fix Issue 18285 - std.algorithm.comparison.cmp for strings with custom predicate compares lengths wrong
Test std.algorithm.comparison.cmp when opCmp returns float
Promotions should not use cast
Optimize cmp's endgame
There are some redundant tests when the end of the ranges is reached. Eliminated that, and improved threeWayByPred.
Fix Issue 18286 - std.algorithm.comparison.cmp for string with custom predicate fails if distinct chars can compare equal
Fix Issue 18288 - std.algorithm.comparison.cmp for wide strings should be @safe
re-apply remove cast in promotions
https://github.com/dlang/phobos/commit/2174695151633e64c33ef8c73dcd98ae2c27606e
Merge pull request #6056 from n8sh/algorithm-cmp
Fix Issue 18280 - std.algorithm.comparison.cmp for non-strings should call opCmp only once per item pair