From 63b9a0430cf929eda5ccd8e8bc54f5e96155f2df Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sun, 21 Feb 2021 09:15:48 -0700 Subject: [PATCH] Swap the ordering of two locale category indices Perl internally uses a mapping of locale category values into a consecutive sequence of indices starting at 0. These are used as indexes into arrays. The reason is that the category numbers are opaque, vary by platform, aren't necessarily sequential, and hence are hard to make table driven code for. This commit makes the LC_CTYPE index 0, and LC_NUMERIC equal to 1; swapping them. The reason is to cause LC_CTYPE to get done first in the many loops through the categories. The UTF8ness of categories is an often needed value, and most of the time the categories will have the same locale. LC_CTYPE is needed to calculate the UTF8ness, and by doing it first and caching the result, the other categories likely automatically will use the same value, without having to recalculate. --- locale.c | 24 ++++++++++++------------ perl.h | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/locale.c b/locale.c index 3032c2cfadc3..6f0f2f6aef42 100644 --- a/locale.c +++ b/locale.c @@ -181,12 +181,12 @@ static const char C_thousands_sep[] = ""; STATIC const int categories[] = { -# ifdef USE_LOCALE_NUMERIC - LC_NUMERIC, -# endif # ifdef USE_LOCALE_CTYPE LC_CTYPE, # endif +# ifdef USE_LOCALE_NUMERIC + LC_NUMERIC, +# endif # ifdef USE_LOCALE_COLLATE LC_COLLATE, # endif @@ -233,12 +233,12 @@ STATIC const int categories[] = { STATIC const char * const category_names[] = { -# ifdef USE_LOCALE_NUMERIC - "LC_NUMERIC", -# endif # ifdef USE_LOCALE_CTYPE "LC_CTYPE", # endif +# ifdef USE_LOCALE_NUMERIC + "LC_NUMERIC", +# endif # ifdef USE_LOCALE_COLLATE "LC_COLLATE", # endif @@ -284,12 +284,12 @@ STATIC const char * const category_names[] = { /* A few categories require additional setup when they are changed. This table * points to the functions that do that setup */ STATIC void (*update_functions[]) (pTHX_ const char *) = { -# ifdef USE_LOCALE_NUMERIC - S_new_numeric, -# endif # ifdef USE_LOCALE_CTYPE S_new_ctype, # endif +# ifdef USE_LOCALE_NUMERIC + S_new_numeric, +# endif # ifdef USE_LOCALE_COLLATE S_new_collate, # endif @@ -591,12 +591,12 @@ Perl_locale_panic(const char * msg, /* A fourth array, parallel to the ones above to map from category to its * equivalent mask */ STATIC const int category_masks[] = { -# ifdef USE_LOCALE_NUMERIC - LC_NUMERIC_MASK, -# endif # ifdef USE_LOCALE_CTYPE LC_CTYPE_MASK, # endif +# ifdef USE_LOCALE_NUMERIC + LC_NUMERIC_MASK, +# endif # ifdef USE_LOCALE_COLLATE LC_COLLATE_MASK, # endif diff --git a/perl.h b/perl.h index e464b3b5f199..78dd04b4e14a 100644 --- a/perl.h +++ b/perl.h @@ -991,23 +991,23 @@ Example usage: # endif /* Now create LC_foo_INDEX_ #defines for just those categories on this system */ -# ifdef USE_LOCALE_NUMERIC -# define LC_NUMERIC_INDEX_ 0 -# define PERL_DUMMY_NUMERIC_ LC_NUMERIC_INDEX_ -# else -# define PERL_DUMMY_NUMERIC_ -1 -# endif # ifdef USE_LOCALE_CTYPE -# define LC_CTYPE_INDEX_ PERL_DUMMY_NUMERIC_ + 1 +# define LC_CTYPE_INDEX_ 0 # define PERL_DUMMY_CTYPE_ LC_CTYPE_INDEX_ # else -# define PERL_DUMMY_CTYPE_ PERL_DUMMY_NUMERIC_ +# define PERL_DUMMY_CTYPE_ -1 +# endif +# ifdef USE_LOCALE_NUMERIC +# define LC_NUMERIC_INDEX_ PERL_DUMMY_CTYPE_ + 1 +# define PERL_DUMMY_NUMERIC_ LC_NUMERIC_INDEX_ +# else +# define PERL_DUMMY_NUMERIC_ PERL_DUMMY_CTYPE_ # endif # ifdef USE_LOCALE_COLLATE -# define LC_COLLATE_INDEX_ PERL_DUMMY_CTYPE_ + 1 +# define LC_COLLATE_INDEX_ PERL_DUMMY_NUMERIC_ + 1 # define PERL_DUMMY_COLLATE_ LC_COLLATE_INDEX_ # else -# define PERL_DUMMY_COLLATE_ PERL_DUMMY_CTYPE_ +# define PERL_DUMMY_COLLATE_ PERL_DUMMY_NUMERIC_ # endif # ifdef USE_LOCALE_TIME # define LC_TIME_INDEX_ PERL_DUMMY_COLLATE_ + 1