Skip to content

Commit 5a979ea

Browse files
committed
bytes_from_utf8_loc: Move declarations, rename variable
Now that we have c99, we can declare close to first use. s0 seems to be the more common name for a variable that preserves the position a string 's' had on input. This also adds a const to make sure the function doesn't change s0.
1 parent 060589f commit 5a979ea

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

utf8.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,24 +2668,24 @@ and subtracting the after-call value of C<*lenp> from it.
26682668
U8 *
26692669
Perl_bytes_from_utf8_loc(const U8 *s, STRLEN *lenp, bool *is_utf8p, const U8** first_unconverted)
26702670
{
2671-
U8 *d;
2672-
const U8 *original = s;
2673-
U8 *converted_start;
2674-
const U8 *send = s + *lenp;
2675-
26762671
PERL_ARGS_ASSERT_BYTES_FROM_UTF8_LOC;
26772672

26782673
if (! *is_utf8p) {
26792674
if (first_unconverted) {
26802675
*first_unconverted = NULL;
26812676
}
26822677

2683-
return (U8 *) original;
2678+
return (U8 *) s;
26842679
}
26852680

2681+
const U8 * const s0 = s;
2682+
const U8 * send = s + *lenp;
2683+
2684+
U8 *d;
26862685
Newx(d, (*lenp) + 1, U8);
26872686

2688-
converted_start = d;
2687+
U8 *converted_start = d;
2688+
26892689
while (s < send) {
26902690
U8 c = *s++;
26912691
if (! UTF8_IS_INVARIANT(c)) {
@@ -2699,7 +2699,7 @@ Perl_bytes_from_utf8_loc(const U8 *s, STRLEN *lenp, bool *is_utf8p, const U8** f
26992699
}
27002700
else {
27012701
Safefree(converted_start);
2702-
return (U8 *) original;
2702+
return (U8 *) s0;
27032703
}
27042704
}
27052705

0 commit comments

Comments
 (0)