Skip to content

Commit 58edeb0

Browse files
committed
pp_ord: Use utf8_to_uv over utf8n_to_uvchr
This is the more modern spelling. This also changes the code so that 0 is always explicitly returned if the SV is zero length. Previously it would only do this if the SV was marked as being in UTF-8. If it wasn't, it would return the first byte in the PV. That should also always be a NUL or 0, but now it is explicit.
1 parent a9ad65a commit 58edeb0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pp.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -4035,11 +4035,20 @@ PP(pp_ord)
40354035
STRLEN len;
40364036
const U8 *s = (U8*)SvPV_const(argsv, len);
40374037

4038-
TARGu(DO_UTF8(argsv)
4039-
? (len ? utf8n_to_uvchr(s, len, 0, UTF8_ALLOW_ANYUV) : 0)
4040-
: (UV)(*s),
4041-
1);
4038+
UV cp;
4039+
if (UNLIKELY(len == 0)) {
4040+
cp = 0;
4041+
}
4042+
else if (DO_UTF8(argsv)) {
4043+
if (! utf8_to_uv(s, s + len, &cp, 0)) {
4044+
cp = 0;
4045+
}
4046+
}
4047+
else {
4048+
cp = (UV) (*s);
4049+
}
40424050

4051+
TARGu(cp, 1);
40434052
rpp_replace_1_1_NN(TARG);
40444053
return NORMAL;
40454054
}

0 commit comments

Comments
 (0)