mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 21:51:40 +03:00
std.string: Optimize implementation for same-type case-sensitive search
Add a special case for case-sensitive search when the character size of substrings matches. We do not need to decode in this case, so perform a basic array search on the strings' representations.
This commit is contained in:
parent
606465af0b
commit
f12e43e3b3
1 changed files with 17 additions and 9 deletions
26
std/string.d
26
std/string.d
|
@ -766,20 +766,28 @@ private template _indexOfStr(CaseSensitive cs)
|
|||
|
||||
static if (isSomeString!Range)
|
||||
{
|
||||
import std.algorithm.searching : find;
|
||||
|
||||
const(Char1)[] balance;
|
||||
static if (cs == Yes.caseSensitive)
|
||||
static if (is(Char1 == Char) && cs == Yes.caseSensitive)
|
||||
{
|
||||
balance = find(s, sub);
|
||||
import std.algorithm.searching : countUntil;
|
||||
return s.representation.countUntil(sub.representation);
|
||||
}
|
||||
else
|
||||
{
|
||||
balance = find!
|
||||
((a, b) => toLower(a) == toLower(b))
|
||||
(s, sub);
|
||||
import std.algorithm.searching : find;
|
||||
|
||||
const(Char1)[] balance;
|
||||
static if (cs == Yes.caseSensitive)
|
||||
{
|
||||
balance = find(s, sub);
|
||||
}
|
||||
else
|
||||
{
|
||||
balance = find!
|
||||
((a, b) => toLower(a) == toLower(b))
|
||||
(s, sub);
|
||||
}
|
||||
return () @trusted { return balance.empty ? -1 : balance.ptr - s.ptr; } ();
|
||||
}
|
||||
return () @trusted { return balance.empty ? -1 : balance.ptr - s.ptr; } ();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue