Skip to content

Commit

Permalink
Special case localeconv when NUMERIC, MONETARY must be C
Browse files Browse the repository at this point in the history
When both these categories are C, we don't need to call localeconv(),
which can be expensive because it may mean toggling locales.  Instead
the answers are well defined by the C Standard.  This adds a function
that returns those, and #ifdef's to locale.c to compile to use the
special function instead of the more general one if both categories must
be C.

A future commit will extend the use of this new function to more cases.
  • Loading branch information
khwilliamson committed Nov 22, 2023
1 parent 8ec4ae0 commit 0401b2a
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 61 deletions.
20 changes: 14 additions & 6 deletions embed.fnc
Expand Up @@ -4405,12 +4405,12 @@ Sf |char * |strftime_tm |NN const char *fmt \
|NN const struct tm *mytm
# if defined(HAS_LOCALECONV)
S |HV * |my_localeconv |const int item
S |void |populate_hash_from_localeconv \
|NN HV *hv \
|NN const char *locale \
|const PERL_UINT_FAST8_T which_mask \
|NN const lconv_offset_t *strings[2] \
|NULLOK const lconv_offset_t *integers[2]
S |void |populate_hash_from_C_localeconv \
|NN HV *hv \
|NN const char *locale \
|const PERL_UINT_FAST8_T which_mask \
|NN const lconv_offset_t *strings[2] \
|NN const lconv_offset_t *integers[2]
# endif
# if defined(USE_LOCALE)
S |const char *|calculate_LC_ALL_string \
Expand Down Expand Up @@ -4521,6 +4521,14 @@ ST |bool |is_codeset_name_UTF8 \
S |void |new_ctype |NN const char *newctype \
|bool force
# endif
# if defined(USE_LOCALE_MONETARY) || defined(USE_LOCALE_NUMERIC)
S |void |populate_hash_from_localeconv \
|NN HV *hv \
|NN const char *locale \
|const PERL_UINT_FAST8_T which_mask \
|NN const lconv_offset_t *strings[2] \
|NN const lconv_offset_t *integers[2]
# endif
# if defined(USE_LOCALE_NUMERIC)
S |void |new_numeric |NN const char *newnum \
|bool force
Expand Down
5 changes: 4 additions & 1 deletion embed.h
Expand Up @@ -1303,7 +1303,7 @@
# define strftime_tm(a,b) S_strftime_tm(aTHX_ a,b)
# if defined(HAS_LOCALECONV)
# define my_localeconv(a) S_my_localeconv(aTHX_ a)
# define populate_hash_from_localeconv(a,b,c,d,e) S_populate_hash_from_localeconv(aTHX_ a,b,c,d,e)
# define populate_hash_from_C_localeconv(a,b,c,d,e) S_populate_hash_from_C_localeconv(aTHX_ a,b,c,d,e)
# endif
# if defined(USE_LOCALE)
# define calculate_LC_ALL_string(a,b,c,d) S_calculate_LC_ALL_string(aTHX_ a,b,c,d)
Expand Down Expand Up @@ -1343,6 +1343,9 @@
# define is_codeset_name_UTF8 S_is_codeset_name_UTF8
# define new_ctype(a,b) S_new_ctype(aTHX_ a,b)
# endif
# if defined(USE_LOCALE_MONETARY) || defined(USE_LOCALE_NUMERIC)
# define populate_hash_from_localeconv(a,b,c,d,e) S_populate_hash_from_localeconv(aTHX_ a,b,c,d,e)
# endif
# if defined(USE_LOCALE_NUMERIC)
# define new_numeric(a,b) S_new_numeric(aTHX_ a,b)
# endif
Expand Down

0 comments on commit 0401b2a

Please sign in to comment.