In perl.git, the branch smoke-me/jkeenan/hv/134172-sprintf has been updated
<https://perl5.git.perl.org/perl.git/commitdiff/3bb520e09cfcbe57fb478255db7417fc9697dda8?hp=faef172d72c55e8e2f171243b347f32b2213ab85> - Log ----------------------------------------------------------------- commit 3bb520e09cfcbe57fb478255db7417fc9697dda8 Author: Hugo van der Sanden <[email protected]> Date: Mon Jul 22 17:08:45 2019 +0100 Avoid multiple checks of IN_LC(LC_NUMERIC) ----------------------------------------------------------------------- Summary of changes: perl.h | 20 ++++++++++++++------ sv.c | 12 ++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/perl.h b/perl.h index 3be4a53756..c4afb3f2c7 100644 --- a/perl.h +++ b/perl.h @@ -6476,12 +6476,12 @@ is equivalent to: # define DECLARATION_FOR_LC_NUMERIC_MANIPULATION \ void (*_restore_LC_NUMERIC_function)(pTHX) = NULL -# define STORE_LC_NUMERIC_SET_TO_NEEDED() \ +# define STORE_LC_NUMERIC_SET_TO_NEEDED_i(in_lc_numeric) \ STMT_START { \ LC_NUMERIC_LOCK( \ - ( ( IN_LC(LC_NUMERIC) && _NOT_IN_NUMERIC_UNDERLYING) \ - || (! IN_LC(LC_NUMERIC) && _NOT_IN_NUMERIC_STANDARD)));\ - if (IN_LC(LC_NUMERIC)) { \ + ( ( in_lc_numeric && _NOT_IN_NUMERIC_UNDERLYING) \ + || (! in_lc_numeric && _NOT_IN_NUMERIC_STANDARD))); \ + if (in_lc_numeric) { \ if (_NOT_IN_NUMERIC_UNDERLYING) { \ Perl_set_numeric_underlying(aTHX); \ _restore_LC_NUMERIC_function \ @@ -6497,6 +6497,9 @@ is equivalent to: } \ } STMT_END +# define STORE_LC_NUMERIC_SET_TO_NEEDED() \ + STORE_LC_NUMERIC_SET_TO_NEEDED_i(IN_LC(LC_NUMERIC)) + # define RESTORE_LC_NUMERIC() \ STMT_START { \ if (_restore_LC_NUMERIC_function) { \ @@ -6571,14 +6574,17 @@ is equivalent to: __FILE__, __LINE__, PL_numeric_standard)); \ } STMT_END -# define WITH_LC_NUMERIC_SET_TO_NEEDED(block) \ +# define WITH_LC_NUMERIC_SET_TO_NEEDED_i(in_lc_numeric, block) \ STMT_START { \ DECLARATION_FOR_LC_NUMERIC_MANIPULATION; \ - STORE_LC_NUMERIC_SET_TO_NEEDED(); \ + STORE_LC_NUMERIC_SET_TO_NEEDED_i(in_lc_numeric); \ block; \ RESTORE_LC_NUMERIC(); \ } STMT_END; +# define WITH_LC_NUMERIC_SET_TO_NEEDED(block) \ + WITH_LC_NUMERIC_SET_TO_NEEDED_i(IN_LC(LC_NUMERIC), block) + #else /* !USE_LOCALE_NUMERIC */ # define SET_NUMERIC_STANDARD() @@ -6587,10 +6593,12 @@ is equivalent to: # define DECLARATION_FOR_LC_NUMERIC_MANIPULATION # define STORE_LC_NUMERIC_SET_STANDARD() # define STORE_LC_NUMERIC_FORCE_TO_UNDERLYING() +# define STORE_LC_NUMERIC_SET_TO_NEEDED_i() # define STORE_LC_NUMERIC_SET_TO_NEEDED() # define RESTORE_LC_NUMERIC() # define LOCK_LC_NUMERIC_STANDARD() # define UNLOCK_LC_NUMERIC_STANDARD() +# define WITH_LC_NUMERIC_SET_TO_NEEDED_i(in_lc_numeric, block) block; # define WITH_LC_NUMERIC_SET_TO_NEEDED(block) block; #endif /* !USE_LOCALE_NUMERIC */ diff --git a/sv.c b/sv.c index ef2c71126c..dfe5f88e52 100644 --- a/sv.c +++ b/sv.c @@ -11784,7 +11784,7 @@ S_format_hexfp(pTHX_ char * const buf, const STRLEN bufsize, const char c, #else if (in_lc_numeric) { STRLEN n; - WITH_LC_NUMERIC_SET_TO_NEEDED({ + WITH_LC_NUMERIC_SET_TO_NEEDED_i(TRUE, { const char* r = SvPV(PL_numeric_radix_sv, n); Copy(r, p, n, char); }); @@ -12978,7 +12978,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p } if (in_lc_numeric) { - WITH_LC_NUMERIC_SET_TO_NEEDED({ + WITH_LC_NUMERIC_SET_TO_NEEDED_i(TRUE, { /* this can't wrap unless PL_numeric_radix_sv is a string * consuming virtually all the 32-bit or 64-bit address * space @@ -13071,7 +13071,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p && !fill && intsize != 'q' ) { - WITH_LC_NUMERIC_SET_TO_NEEDED( + WITH_LC_NUMERIC_SET_TO_NEEDED_i(in_lc_numeric, SNPRINTF_G(fv, ebuf, sizeof(ebuf), precis) ); elen = strlen(ebuf); @@ -13174,7 +13174,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p const char* qfmt = quadmath_format_single(ptr); if (!qfmt) Perl_croak_nocontext("panic: quadmath invalid format \"%s\"", ptr); - WITH_LC_NUMERIC_SET_TO_NEEDED( + WITH_LC_NUMERIC_SET_TO_NEEDED_i(in_lc_numeric, elen = quadmath_snprintf(PL_efloatbuf, PL_efloatsize, qfmt, nv); ); @@ -13187,13 +13187,13 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p Safefree(qfmt); } #elif defined(HAS_LONG_DOUBLE) - WITH_LC_NUMERIC_SET_TO_NEEDED( + WITH_LC_NUMERIC_SET_TO_NEEDED_i(in_lc_numeric, elen = ((intsize == 'q') ? my_snprintf(PL_efloatbuf, PL_efloatsize, ptr, fv) : my_snprintf(PL_efloatbuf, PL_efloatsize, ptr, (double)fv)) ); #else - WITH_LC_NUMERIC_SET_TO_NEEDED( + WITH_LC_NUMERIC_SET_TO_NEEDED_i(in_lc_numeric, elen = my_snprintf(PL_efloatbuf, PL_efloatsize, ptr, fv) ); #endif -- Perl5 Master Repository
