Optimize count with an overload which calls walkLength#5557
Optimize count with an overload which calls walkLength#5557dlang-bot merged 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
|
Why is that needed. The ddoc is bigger then the function ? |
|
@UplinkCoder That was the consensus reached in #5545. I guess creating an alias might be better, still the documentation needs to be there |
Would break code, due to the different default behavior.
Because documentation is a lot more important than code. This is a common pattern in Phobos ;-) |
|
@wilzbach I created an overload anyway so making an alias won't break any code, but it seems cleaner to me to have an overload, rather then an alias. |
wilzbach
left a comment
There was a problem hiding this comment.
LGTM to me in general. If we decide to deprecate on of the symbols we can always do this afterwards as this is just an optimization.
|
(keeping this open for one or two days to give people enough time to veto this approach as a general good practice) |
std/algorithm/searching.d
Outdated
|
|
||
| The fourth version counts the number of elements in a range. It is | ||
| an optimization for the third version: if the given range has the | ||
| length property the count is returned right away, otherwise |
There was a problem hiding this comment.
length in code font (e.g. backticks)
|
Aliases are generally better, but here we have overloading so that wouldn't work well. This improves the situation whereby someone calls count with the default predicate - avoid the goofy walking the whole range. That's fine, as is to allow two distinct library functions sometimes do the same thing under certain circumstances. |
|
@andralex done |
Following the discussion in #5545 , I created this separate PR for the count optimization. The implementation uses walkLength to compute the count. If walkLength will be deprecated, then I will replace the call with the code, otherwise we can close the other PR and keep just this oprimization