mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 13:40:20 +03:00
Fix Issue 21559 - Speed up walkLength for narrow strings
This commit is contained in:
parent
54f224a03d
commit
3733c9d202
2 changed files with 30 additions and 1 deletions
|
@ -1750,6 +1750,20 @@ if (isInputRange!Range && !isInfinite!Range)
|
|||
else
|
||||
{
|
||||
size_t result;
|
||||
static if (autodecodeStrings && isNarrowString!Range)
|
||||
{
|
||||
import std.utf : codeUnitLimit;
|
||||
result = range.length;
|
||||
foreach (const i, const c; range)
|
||||
{
|
||||
if (c >= codeUnitLimit!Range)
|
||||
{
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
range = range[result .. $];
|
||||
}
|
||||
for ( ; !range.empty ; range.popFront() )
|
||||
++result;
|
||||
return result;
|
||||
|
@ -1766,6 +1780,20 @@ if (isInputRange!Range)
|
|||
else
|
||||
{
|
||||
size_t result;
|
||||
static if (autodecodeStrings && isNarrowString!Range)
|
||||
{
|
||||
import std.utf : codeUnitLimit;
|
||||
result = upTo > range.length ? range.length : upTo;
|
||||
foreach (const i, const c; range[0 .. result])
|
||||
{
|
||||
if (c >= codeUnitLimit!Range)
|
||||
{
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
range = range[result .. $];
|
||||
}
|
||||
for ( ; result < upTo && !range.empty ; range.popFront() )
|
||||
++result;
|
||||
return result;
|
||||
|
|
|
@ -1410,7 +1410,8 @@ do
|
|||
assert(str.decodeBack(i) == 'å' && i == 2 && str.empty);
|
||||
}
|
||||
|
||||
// Gives the maximum value that a code unit for the given range type can hold.
|
||||
// For the given range, code unit values less than this
|
||||
// are guaranteed to be valid single-codepoint encodings.
|
||||
package template codeUnitLimit(S)
|
||||
if (isSomeChar!(ElementEncodingType!S))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue