Skip to content

Commit 9acaa98

Browse files
committed
bytes_to_utf8: Don't redo work
We have gone to some trouble to find the first UTF-8 variant character in the input string. There is no need to look again for variants in the portion of the string that we have already determined doesn't have any such variants. This missing statement appears to have been an oversight.
1 parent a5fd0a0 commit 9acaa98

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

utf8.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,14 +2397,14 @@ Perl_utf8_to_bytes(pTHX_ U8 *s, STRLEN *lenp)
23972397

23982398
U8 * const save = s;
23992399
U8 * const send = s + *lenp;
2400-
U8 * d;
2400+
s = first_variant;
24012401

24022402
#ifndef EBCDIC /* The below relies on the bit patterns of UTF-8 */
24032403

24042404
/* There is some start-up/tear-down overhead with this, so no real gain
2405-
* unless the string is long enough. The current value is just a
2406-
* guess. */
2407-
if (*lenp > 5 * PERL_WORDSIZE) {
2405+
* unless the remaining portion of the string is long enough. The current
2406+
* value is just a guess. */
2407+
if ((send - s) > 5 * PERL_WORDSIZE) {
24082408

24092409
/* First, go through the string a word at-a-time to verify that it is
24102410
* downgradable. If it contains any start byte besides C2 and C3, then
@@ -2517,7 +2517,7 @@ Perl_utf8_to_bytes(pTHX_ U8 *s, STRLEN *lenp)
25172517
* and should a malformed one come along, it undoes what it already has
25182518
* done */
25192519

2520-
d = s = first_variant;
2520+
U8 * d = s = first_variant;
25212521

25222522
while (s < send) {
25232523
U8 * s1;

0 commit comments

Comments
 (0)