From 2482fe157fb23b1ebf65cb2ee2fbde1f5699f3af Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Tue, 2 May 2023 11:01:06 -0600 Subject: [PATCH] locale.c: Simplify S_new_ctype By creating a temporary variable, an else is eliminated, and the lock/unlock are brought close together. --- locale.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/locale.c b/locale.c index ab3e66d5b0c6..f6fd38a97d9f 100644 --- a/locale.c +++ b/locale.c @@ -4332,8 +4332,10 @@ S_new_ctype(pTHX_ const char *newctype, bool force) * */ LC_CTYPE_LOCK; + const int mb_cur_max = MB_CUR_MAX; + LC_CTYPE_UNLOCK; - if (MB_CUR_MAX > 1 && ! PL_in_utf8_CTYPE_locale + if (mb_cur_max > 1 && ! PL_in_utf8_CTYPE_locale /* Some platforms return MB_CUR_MAX > 1 for even the "C" locale. * Just assume that the implementation for them (plus for POSIX) is @@ -4342,19 +4344,14 @@ S_new_ctype(pTHX_ const char *newctype, bool force) * as this is the only problem, everything should work fine */ && ! isNAME_C_OR_POSIX(newctype)) { - LC_CTYPE_UNLOCK; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "Unsupported, MB_CUR_MAX=%d\n", (int) MB_CUR_MAX)); + "Unsupported, MB_CUR_MAX=%d\n", mb_cur_max)); Perl_ck_warner_d(aTHX_ packWARN(WARN_LOCALE), "Locale '%s' is unsupported, and may crash the" " interpreter.\n", newctype); } - else { - LC_CTYPE_UNLOCK; - } # endif