Fix Issue 8472 - Replace walkLength() with an improved count()#5545
Fix Issue 8472 - Replace walkLength() with an improved count()#5545RazvanN7 wants to merge 2 commits 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 references
|
std/algorithm/searching.d
Outdated
| foreach (T elem; haystack) | ||
| if (unaryFun!pred(elem)) ++result; | ||
| return result; | ||
| static if (hasLength!R && is(typeof(unary!fun(pred) == unary!fun("true")))) |
There was a problem hiding this comment.
Your is swallows all errors (even your typos), but comparing functions doesn't work in D, e.g.:
void main(string[] args)
{
import std.functional;
static assert(is(typeof(unaryFun!("true") == unaryFun!("true"))));
}Regarding the specialization, you should see #4265 (comment) and its final version (#5001).
tl;dr: use overloads, not strings
There was a problem hiding this comment.
I guess in this case I should create an overload which doesn't receive a string function, but calls the one I just modified
std/range/primitives.d
Outdated
| Infinite ranges are compatible, provided the parameter $(D upTo) is | ||
| specified, in which case the implementation simply returns upTo. | ||
| */ | ||
| deprecated("use std.algorithm.searching.count instead.") |
There was a problem hiding this comment.
You should use the deprecated string, so it's easy to grep for:
// Explicitly undocumented. It will be removed in July 2018. @@@DEPRECATED_2018-07@@@
And of course, undocument or state in the document with $(RED) that it's deprecated.
There was a problem hiding this comment.
Also, that deprecated string is for symbols that have already been through a year of deprecation and are now undocumented. So, even if we deprecated walkLength (which IMHO, we shouldn't), this would not be the message to use. It would have to be one from a symbol that's still documented with a ddoc comment.
|
I suggest keeping the remaining walkLength and deprecating the one that count can take care off |
|
I'm guessing the jenkins failure is due to the fact that the use of deprecated functions is forbidden in phobos? |
No it's simply broken atm (or has a lot of transient failures), however CircleCi isn't:
Wishful thinking -> #5546 |
|
@wilzbach seems kind of awkward to document deprecated functions. |
|
Please do not deprecate |
|
|
@RazvanN7 I suggest to split this PR and submit the optimization for |
|
Also, if |
|
@RazvanN7 deprecation of anything is a tall order and should be confined to its own pull request (as opposed to mixed with other work). I'll close this and comment in the other. |
I am not sure how the deprecation cycle works, but I deprecated the first walkLength overload which is obsolete. I don't know if the walkLength overload which walks up to a given number of elements should be deprecated too. I think that the best way is to deprecated one overload of walkLength and keep the other.