remove redundant Zero() from JMPENV_BOOTSTRAP
authorDaniel Dragan <bulk88@hotmail.com>
Fri, 1 Nov 2013 21:50:39 +0000 (17:50 -0400)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 2 Nov 2013 12:39:00 +0000 (05:39 -0700)
In commit 14dd3ad8c9 , a 3 NULL assigns were converted to a Zero() for what
I guess was an optimization. This also caused the large je_buf to be
zeroed even though je_buf was uninit before. At that time, JMPENV had
2 extra members that don't exist anymore. The 2 extra members in JMPENV
were removed in commit 766f891612 . The comment about je_throw was made
obsolete in commit 766f891612 so rework it.

One function call free NULL assign is faster than a memset() call.
je_buf is 0x40 bytes long on 32 bit VC2003 Win32 Perl. No need to zero it
since je_buf is never read unless je_prev is not NULL. Also there is no
need to zero the last 2 members je_ret and je_mustcatch since they are
immediatley assigned to. Move PL_top_env assignment to near je_prev so
compiler tries to optimize better since je_prev is the start of the struct
and hopefully will calculate the pointer once.

Also put some poisoning in case JMPENV gets new members in the future.
To conditionally poison in a macro, PERL_POISON_EXPR is being introduced
instead of 2 different definitions of JMPENV_BOOTSTRAP.

cop.h
handy.h

diff --git a/cop.h b/cop.h
index 2a976ad..6950814 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -31,7 +31,7 @@
 
 struct jmpenv {
     struct jmpenv *    je_prev;
-    Sigjmp_buf         je_buf;         /* only for use if !je_throw */
+    Sigjmp_buf         je_buf;         /* uninit if je_prev is NULL */
     int                        je_ret;         /* last exception thrown */
     bool               je_mustcatch;   /* need to call longjmp()? */
 };
@@ -50,10 +50,11 @@ typedef struct jmpenv JMPENV;
 
 #define JMPENV_BOOTSTRAP \
     STMT_START {                               \
-       Zero(&PL_start_env, 1, JMPENV);         \
+       PERL_POISON_EXPR(PoisonNew(&PL_start_env, 1, JMPENV));\
+       PL_top_env = &PL_start_env;             \
+       PL_start_env.je_prev = NULL;            \
        PL_start_env.je_ret = -1;               \
        PL_start_env.je_mustcatch = TRUE;       \
-       PL_top_env = &PL_start_env;             \
     } STMT_END
 
 /*
diff --git a/handy.h b/handy.h
index d345abe..78e5284 100644 (file)
--- a/handy.h
+++ b/handy.h
@@ -1780,6 +1780,12 @@ void Perl_mem_log_del_sv(const SV *sv, const char *filename, const int linenumbe
 #define PoisonFree(d,n,t)      PoisonWith(d,n,t,0xEF)
 #define Poison(d,n,t)          PoisonFree(d,n,t)
 
+#ifdef PERL_POISON
+#  define PERL_POISON_EXPR(x) x
+#else
+#  define PERL_POISON_EXPR(x)
+#endif
+
 #ifdef USE_STRUCT_COPY
 #define StructCopy(s,d,t) (*((t*)(d)) = *((t*)(s)))
 #else