This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move unlikely executed macro to function
authorKarl Williamson <khw@cpan.org>
Tue, 13 Jan 2015 05:31:07 +0000 (22:31 -0700)
committerKarl Williamson <khw@cpan.org>
Tue, 13 Jan 2015 19:19:59 +0000 (12:19 -0700)
The bulk of this macro is extremely rarely executed, so it makes sense
to optimize for space, as it is called from a fair number of places, and
move as much as possible to a single function.

For whatever it's worth, on my system with my typical compilation
options, including -O0, the savings was 19640 bytes in regexec.o, 4528
in utf8.o, at a cost of 1488 in locale.o.

embed.fnc
embed.h
locale.c
perl.h
proto.h

index dc2ed43..bf3b35e 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1130,6 +1130,7 @@ ApOM      |int    |init_i18nl14n  |int printwarn
 ApM    |char*  |my_strerror    |const int errnum
 ApOM   |void   |new_collate    |NULLOK const char* newcoll
 ApOM   |void   |new_ctype      |NN const char* newctype
+ApMn   |void   |_warn_problematic_locale
 ApOM   |void   |new_numeric    |NULLOK const char* newcoll
 Ap     |void   |set_numeric_local
 Ap     |void   |set_numeric_radix
diff --git a/embed.h b/embed.h
index c1f98be..2342c98 100644 (file)
--- a/embed.h
+++ b/embed.h
@@ -45,6 +45,7 @@
 #define _to_utf8_lower_flags(a,b,c,d)  Perl__to_utf8_lower_flags(aTHX_ a,b,c,d)
 #define _to_utf8_title_flags(a,b,c,d)  Perl__to_utf8_title_flags(aTHX_ a,b,c,d)
 #define _to_utf8_upper_flags(a,b,c,d)  Perl__to_utf8_upper_flags(aTHX_ a,b,c,d)
+#define _warn_problematic_locale       Perl__warn_problematic_locale
 #define amagic_call(a,b,c,d)   Perl_amagic_call(aTHX_ a,b,c,d)
 #define amagic_deref_call(a,b) Perl_amagic_deref_call(aTHX_ a,b)
 #define append_utf8_from_native_byte   S_append_utf8_from_native_byte
index e25a789..e267c98 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -414,6 +414,29 @@ Perl_new_ctype(pTHX_ const char *newctype)
 }
 
 void
+Perl__warn_problematic_locale()
+{
+    dTHX;
+
+    /* Outputs the message in PL_warn_locale, and then NULLS it */
+
+#ifdef USE_LOCALE_CTYPE
+
+    if (PL_warn_locale) {
+        /*GCC_DIAG_IGNORE(-Wformat-security);   Didn't work */
+        Perl_ck_warner(aTHX_ packWARN(WARN_LOCALE),
+                             SvPVX(PL_warn_locale),
+                             0 /* dummy to avoid compiler warning */ );
+        /* GCC_DIAG_RESTORE; */
+        SvREFCNT_dec_NN(PL_warn_locale);
+        PL_warn_locale = NULL;
+    }
+
+#endif
+
+}
+
+void
 Perl_new_collate(pTHX_ const char *newcoll)
 {
 #ifdef USE_LOCALE_COLLATE
diff --git a/perl.h b/perl.h
index 2d3e1f7..09a1de2 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -5796,17 +5796,14 @@ typedef struct am_table_short AMTS;
 
         /* This internal macro should be called from places that operate under
          * locale rules.  It there is a problem with the current locale that
-         * hasn't been raised yet, it will output a warning this time */
+         * hasn't been raised yet, it will output a warning this time.  Because
+         * this will so rarely  be true, there is no point to optimize for
+         * time; instead it makes sense to minimize space used and do all the
+         * work in the rarely called function */
 #       define _CHECK_AND_WARN_PROBLEMATIC_LOCALE                           \
        STMT_START {                                                        \
-            if (PL_warn_locale) {                                           \
-                /*GCC_DIAG_IGNORE(-Wformat-security);   Didn't work */      \
-                Perl_ck_warner(aTHX_ packWARN(WARN_LOCALE),                 \
-                                     SvPVX(PL_warn_locale),                 \
-                                     0 /* dummy to avoid comp warning */ ); \
-                /* GCC_DIAG_RESTORE; */                                     \
-                SvREFCNT_dec_NN(PL_warn_locale);                            \
-                PL_warn_locale = NULL;                                      \
+            if (UNLIKELY(PL_warn_locale)) {                                 \
+                _warn_problematic_locale();                                 \
             }                                                               \
         }  STMT_END
 
diff --git a/proto.h b/proto.h
index f113827..0728c45 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -140,6 +140,7 @@ PERL_CALLCONV UV    Perl__to_utf8_upper_flags(pTHX_ const U8 *p, U8* ustrp, STRLEN
 #define PERL_ARGS_ASSERT__TO_UTF8_UPPER_FLAGS  \
        assert(p); assert(ustrp)
 
+PERL_CALLCONV void     Perl__warn_problematic_locale(void);
 PERL_CALLCONV PADOFFSET        Perl_allocmy(pTHX_ const char *const name, const STRLEN len, const U32 flags)
                        __attribute__nonnull__(pTHX_1);
 #define PERL_ARGS_ASSERT_ALLOCMY       \