From 0b3e94832fd1b1f8ffb70b39b3a55ca453138f45 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Mon, 20 Nov 2023 11:46:12 -0700 Subject: [PATCH] locale.c: Do an adjustment in a critical section This adjustment was deferred until after the critical section, but it is only an extra conditional and variable set, whose time should be dwarfed by the store to the hash, so I think it's all right to add it to the critical section. --- locale.c | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/locale.c b/locale.c index a6368202cf4e..e425092619e9 100644 --- a/locale.c +++ b/locale.c @@ -5703,18 +5703,12 @@ S_my_localeconv(pTHX_ const int item) /* Here, the hash has been completely populated. * * Now go through all the items and: - * a) For string items, see if they should be marked as UTF-8 or not. + * For string items, see if they should be marked as UTF-8 or not. * This would have been more convenient and faster to do while * populating the hash in the first place, but that operation has to be * done within a critical section, keeping other threads from * executing, so only the minimal amount of work necessary is done at * that time. - * b) For integer items, convert the C CHAR_MAX value into -1. Again, - * this could have been done in the critical section, but was deferred - * to here to keep to the bare minimum amount the time spent owning the - * processor. CHAR_MAX is a C concept for an 8-bit character type. - * Perl has no such type; the closest fit is a -1. - * * XXX On unthreaded perls, this code could be #ifdef'd out, and the * corrections determined at hash population time, at an extra maintenance * cost which khw doesn't think is worth it @@ -5747,29 +5741,6 @@ S_my_localeconv(pTHX_ const int item) SvUTF8_on(*value); } } - - if (integers[i] == NULL) { - continue; - } - - /* And each integer */ - for (const lconv_offset_t *intp = integers[i]; intp->name; intp++) { - const char * name = intp->name; - - if (! name) { /* Reached the end */ - break; - } - - SV ** value = hv_fetch(hv, name, strlen(name), true); - if (! value) { - continue; - } - - /* Change CHAR_MAX to -1 */ - if (SvIV(*value) == CHAR_MAX) { - sv_setiv(*value, -1); - } - } } return hv; @@ -6023,8 +5994,12 @@ S_populate_hash_from_localeconv(pTHX_ HV * hv, if (integers[i]) { const lconv_offset_t * current = integers[i]; while (current->name) { - const char value = *((const char *)( lcbuf_as_string - + current->offset)); + int value = *((const char *)( lcbuf_as_string + + current->offset)); + if (value == CHAR_MAX) { /* Change CHAR_MAX to -1 */ + value = -1; + } + (void) hv_store(hv, current->name, strlen(current->name), newSViv(value),