mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 07:00:37 +03:00
Changes to count[Until] as suggested by review
This commit is contained in:
parent
076c853b73
commit
20d77cb8ff
1 changed files with 7 additions and 7 deletions
|
@ -4020,7 +4020,7 @@ ptrdiff_t countUntil(alias pred = "a == b", R1, R2)(R1 haystack, R2 needle)
|
||||||
is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool))
|
is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool))
|
||||||
{
|
{
|
||||||
typeof(return) result;
|
typeof(return) result;
|
||||||
static if (hasLength!R1) //Note: String don't have length
|
static if (hasLength!R1) //Note: Narrow strings don't have length.
|
||||||
{
|
{
|
||||||
//Delegate to find. Find is very efficient
|
//Delegate to find. Find is very efficient
|
||||||
//We save haystack, but we don't care for needle
|
//We save haystack, but we don't care for needle
|
||||||
|
@ -4030,7 +4030,7 @@ ptrdiff_t countUntil(alias pred = "a == b", R1, R2)(R1 haystack, R2 needle)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Default case, slower route doing startsWith iteration
|
//Default case, slower route doing startsWith iteration
|
||||||
for (; !haystack.empty; ++result, haystack.popFront())
|
for ( ; !haystack.empty ; ++result, haystack.popFront() )
|
||||||
if (startsWith!pred(haystack.save, needle.save)) return result;
|
if (startsWith!pred(haystack.save, needle.save)) return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4084,8 +4084,8 @@ ptrdiff_t countUntil(alias pred, R)(R haystack)
|
||||||
//the same time, it is more efficient this way.
|
//the same time, it is more efficient this way.
|
||||||
static if (hasLength!R)
|
static if (hasLength!R)
|
||||||
{
|
{
|
||||||
auto len = cast(typeof(return)) haystack.length;
|
immutable len = cast(typeof(return)) haystack.length;
|
||||||
for ( ; i < len ; ++i)
|
for ( ; i < len ; ++i )
|
||||||
if (unaryFun!pred(haystack[i])) return i;
|
if (unaryFun!pred(haystack[i])) return i;
|
||||||
}
|
}
|
||||||
else //if (isInfinite!R)
|
else //if (isInfinite!R)
|
||||||
|
@ -4154,7 +4154,7 @@ unittest
|
||||||
* $(RED Deprecated. It will be removed in January 2013.
|
* $(RED Deprecated. It will be removed in January 2013.
|
||||||
* Currently defaults to $(LREF countUntil) instead.)
|
* Currently defaults to $(LREF countUntil) instead.)
|
||||||
*
|
*
|
||||||
* Not to be confused with it's homonym function
|
* Not to be confused with its homonym function
|
||||||
* in $(D std.string).
|
* in $(D std.string).
|
||||||
*
|
*
|
||||||
* Please use $(D std.string.indexOf) if you wish to find
|
* Please use $(D std.string.indexOf) if you wish to find
|
||||||
|
@ -5020,8 +5020,8 @@ $(D 2).
|
||||||
The third version counts the elements for which $(D pred(x)) is $(D
|
The third version counts the elements for which $(D pred(x)) is $(D
|
||||||
true). Performs $(BIGOH r.length) evaluations of $(D pred).
|
true). Performs $(BIGOH r.length) evaluations of $(D pred).
|
||||||
|
|
||||||
Note: Regardless of the version, $(D count) will not accept infinite ranges
|
Note: Regardless of the overload, $(D count) will not accept
|
||||||
as a $(D haystack).
|
infinite ranges for $(D haystack).
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
----
|
----
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue