Skip to content

Commit 2955c8c

Browse files
authored
Merge pull request #4642 from JackStouffer/utf2
Added fast paths in std.utf.byUTF
2 parents 2a2cb32 + 6c5f8a4 commit 2955c8c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

std/utf.d

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,8 +3599,27 @@ template byUTF(C) if (isSomeChar!C)
35993599
if (pos == fill)
36003600
{
36013601
pos = 0;
3602-
fill = cast(ushort)encode!(UseReplacementDchar.yes)(
3603-
buf, decodeFront!(UseReplacementDchar.yes)(r));
3602+
auto c = r.front;
3603+
3604+
if (c <= 0x7F)
3605+
{
3606+
fill = 1;
3607+
r.popFront;
3608+
buf[pos] = cast(C) c;
3609+
}
3610+
else
3611+
{
3612+
static if (is(RC == dchar))
3613+
{
3614+
fill = cast(ushort) encode!(UseReplacementDchar.yes)(buf, c);
3615+
r.popFront;
3616+
}
3617+
else
3618+
{
3619+
fill = cast(ushort) encode!(UseReplacementDchar.yes)(
3620+
buf, decodeFront!(UseReplacementDchar.yes)(r));
3621+
}
3622+
}
36043623
}
36053624
return buf[pos];
36063625
}

0 commit comments

Comments
 (0)