summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2017-08-10 21:39:06 -0600
committerKarl Williamson <khw@cpan.org>2017-11-08 20:21:44 -0700
commit604d7733597968dd3d3b15a0c50861ee7ade3f96 (patch)
treee85ef95ef25e831555da23c4220967d793e1aeb2 /ext
parent9eda1ea6670ffea7d0f59d985c0ad45d7b53cdb8 (diff)
downloadperl-604d7733597968dd3d3b15a0c50861ee7ade3f96.tar.gz
POSIX.xs: Move constant tests out of loop
Whether or not a locale is in UTF-8 doesn't change in this loop; calculate it once, prior to the loop
Diffstat (limited to 'ext')
-rw-r--r--ext/POSIX/POSIX.xs44
1 files changed, 30 insertions, 14 deletions
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index f4a93290ce..047a84f61d 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -2124,14 +2124,29 @@ localeconv()
#else
struct lconv *lcbuf;
+ DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
+
/* localeconv() deals with both LC_NUMERIC and LC_MONETARY, but
* LC_MONETARY is already in the correct locale */
- DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
+# ifdef USE_LOCALE_MONETARY
+
+ const bool is_monetary_utf8 = _is_cur_LC_category_utf8(LC_MONETARY);
+# endif
+# ifdef USE_LOCALE_NUMERIC
+
+ bool is_numeric_utf8;
+
STORE_LC_NUMERIC_FORCE_TO_UNDERLYING();
+ is_numeric_utf8 = _is_cur_LC_category_utf8(LC_NUMERIC);
+# endif
+
RETVAL = newHV();
sv_2mortal((SV*)RETVAL);
- if ((lcbuf = localeconv())) {
+
+ lcbuf = localeconv();
+
+ if (lcbuf) {
const struct lconv_offset *strings = lconv_strings;
const struct lconv_offset *integers = lconv_integers;
const char *ptr = (const char *) lcbuf;
@@ -2139,18 +2154,18 @@ localeconv()
while (strings->name) {
/* This string may be controlled by either LC_NUMERIC, or
* LC_MONETARY */
- bool is_utf8_locale
-#if defined(USE_LOCALE_NUMERIC) && defined(USE_LOCALE_MONETARY)
- = _is_cur_LC_category_utf8((isLC_NUMERIC_STRING(strings->name))
- ? LC_NUMERIC
- : LC_MONETARY);
-#elif defined(USE_LOCALE_NUMERIC)
- = _is_cur_LC_category_utf8(LC_NUMERIC);
-#elif defined(USE_LOCALE_MONETARY)
- = _is_cur_LC_category_utf8(LC_MONETARY);
-#else
- = FALSE;
-#endif
+ const bool is_utf8_locale =
+# if defined(USE_LOCALE_NUMERIC) && defined(USE_LOCALE_MONETARY)
+ (isLC_NUMERIC_STRING(strings->name))
+ ? is_numeric_utf8
+ : is_monetary_utf8;
+# elif defined(USE_LOCALE_NUMERIC)
+ is_numeric_utf8;
+# elif defined(USE_LOCALE_MONETARY)
+ is_monetary_utf8;
+# else
+ FALSE;
+# endif
const char *value = *((const char **)(ptr + strings->offset));
@@ -2181,6 +2196,7 @@ localeconv()
integers++;
}
}
+
RESTORE_LC_NUMERIC_STANDARD();
#endif /* HAS_LOCALECONV */
OUTPUT: