Skip to content

Commit 5ebf771

Browse files
committed
utf8_to_bytes_: Slight refactor
This makes the next commit smaller
1 parent 96ac690 commit 5ebf771

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

utf8.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,6 +2399,7 @@ Perl_utf8_to_bytes_(pTHX_ U8 **s_ptr, STRLEN *lenp,
23992399
U8 * const s0 = *s_ptr;
24002400
const U8 * const send = s0 + *lenp;
24012401
U8 * s = first_variant;
2402+
Size_t invariant_length = first_variant - s0;
24022403

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

@@ -2504,7 +2505,8 @@ Perl_utf8_to_bytes_(pTHX_ U8 **s_ptr, STRLEN *lenp,
25042505
s++;
25052506
}
25062507

2507-
U8 * d = s = first_variant;
2508+
U8 *d0 = s0;
2509+
U8 * d = d0 + invariant_length;
25082510

25092511
/* For the cases where the per-word algorithm wasn't used, everything is
25102512
* well-formed and can definitely be translated. When the per word
@@ -2516,6 +2518,7 @@ Perl_utf8_to_bytes_(pTHX_ U8 **s_ptr, STRLEN *lenp,
25162518
* malformed, and because we prioritize speed in the normal case over the
25172519
* malformed one, we go ahead and do the translation, and undo it if found
25182520
* to be necessary. */
2521+
s = first_variant;
25192522
while (s < send) {
25202523
U8 c = *s++;
25212524
if (! UVCHR_IS_INVARIANT(c)) {
@@ -2541,7 +2544,7 @@ Perl_utf8_to_bytes_(pTHX_ U8 **s_ptr, STRLEN *lenp,
25412544

25422545
/* Success! */
25432546
*d = '\0';
2544-
*lenp = d - s0;
2547+
*lenp = d - d0;
25452548

25462549
return true;
25472550

0 commit comments

Comments
 (0)