Permalink
Browse files

locale.c: Avoid rescanning a string

We can use a parameter to find out where in the string the portion of
interest starts.  Do that to avoid starting again from scratch.
  • Loading branch information...
khwilliamson committed Jan 2, 2018
1 parent 3f1e445 commit 42888ca8d413d6d19e0a681c5dbe16258b74189b
Showing with 13 additions and 5 deletions.
  1. +13 −5 locale.c
View
@@ -372,20 +372,28 @@ S_set_numeric_radix(pTHX_ const bool use_locale)
if (use_locale) {
const char * radix = my_nl_langinfo(PERL_RADIXCHAR, FALSE);
/* FALSE => already in dest locale */
/* ... and the character being used isn't a dot */
if (strNE(radix, ".")) {
const U8 * first_variant;
if (PL_numeric_radix_sv) {
sv_setpv(PL_numeric_radix_sv, radix);
}
else {
PL_numeric_radix_sv = newSVpv(radix, 0);
}
if ( ! is_utf8_invariant_string(
(U8 *) SvPVX(PL_numeric_radix_sv), SvCUR(PL_numeric_radix_sv))
&& is_utf8_string(
(U8 *) SvPVX(PL_numeric_radix_sv), SvCUR(PL_numeric_radix_sv))
/* If there is a byte variant under UTF-8, and if the remainder of
* the string starting there is valid UTF-8, and we are in a UTF-8
* locale, then mark the radix as being in UTF-8 */
if ( ! is_utf8_invariant_string_loc(
(U8 *) SvPVX(PL_numeric_radix_sv),
SvCUR(PL_numeric_radix_sv),
&first_variant)
&& is_utf8_string(first_variant,
SvCUR(PL_numeric_radix_sv)
- ((char *) first_variant
- SvPVX(PL_numeric_radix_sv)))
&& _is_cur_LC_category_utf8(LC_NUMERIC))
{
SvUTF8_on(PL_numeric_radix_sv);

0 comments on commit 42888ca

Please sign in to comment.