summaryrefslogtreecommitdiff
path: root/gv.c
diff options
context:
space:
mode:
authorDaniel Dragan <bulk88@hotmail.com>2012-11-07 18:03:10 -0500
committerFather Chrysostomos <sprout@cpan.org>2012-11-08 21:20:23 -0800
commit2639089b2b71c9124405bd9634b99be22b265f09 (patch)
tree6a00ec20c791c7bba10b5a00e414ad6f2f914f01 /gv.c
parent9e942bf50af043414de49df7ae0d6fffc515426e (diff)
downloadperl-2639089b2b71c9124405bd9634b99be22b265f09.tar.gz
refactor gv.c:Perl_newGP
This commit fixes a scenario was strlen("") was called unnecessarily. Replaced with 0. Also various func calls were rearranged for more calls to happen near the beginning to maximize use of volatile registers towards the end for PERL_HASH. PERL_HASH was moved to be closer to the first usage of var hash. Setting gp_line to 0 was removed since the block was just calloced and is already 0. Filling of gp.gp_egv was moved early so var gv on C stack might get reused by compiler optimizer to store something else to decrease the stack frame size of Perl_newGP. PERL_ARGS_ASSERT_NEWGP was moved to be outside of an ifdef. Also see commits 128165928a7 , 19bad6733a8 , 1df5f7c1950 , f4890806d3 .
Diffstat (limited to 'gv.c')
-rw-r--r--gv.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/gv.c b/gv.c
index 40f7c23b39..9de8886aa6 100644
--- a/gv.c
+++ b/gv.c
@@ -162,17 +162,37 @@ Perl_newGP(pTHX_ GV *const gv)
{
GP *gp;
U32 hash;
-#ifdef USE_ITHREADS
- const char *const file
- = (PL_curcop && CopFILE(PL_curcop)) ? CopFILE(PL_curcop) : "";
- const STRLEN len = strlen(file);
-#else
- SV *const temp_sv = CopFILESV(PL_curcop);
const char *file;
STRLEN len;
+#ifndef USE_ITHREADS
+ SV * temp_sv;
+#endif
PERL_ARGS_ASSERT_NEWGP;
+ Newxz(gp, 1, GP);
+ gp->gp_egv = gv; /* allow compiler to reuse gv after this */
+#ifndef PERL_DONT_CREATE_GVSV
+ gp->gp_sv = newSV(0);
+#endif
+#ifdef USE_ITHREADS
+ if (PL_curcop) {
+ gp->gp_line = CopLINE(PL_curcop); /* 0 otherwise Newxz */
+ if (CopFILE(PL_curcop)) {
+ file = CopFILE(PL_curcop);
+ len = strlen(file);
+ }
+ else goto no_file;
+ }
+ else {
+ no_file:
+ file = "";
+ len = 0;
+ }
+#else
+ if(PL_curcop)
+ gp->gp_line = CopLINE(PL_curcop); /* 0 otherwise Newxz */
+ temp_sv = CopFILESV(PL_curcop);
if (temp_sv) {
file = SvPVX(temp_sv);
len = SvCUR(temp_sv);
@@ -183,18 +203,7 @@ Perl_newGP(pTHX_ GV *const gv)
#endif
PERL_HASH(hash, file, len);
-
- Newxz(gp, 1, GP);
-
-#ifndef PERL_DONT_CREATE_GVSV
- gp->gp_sv = newSV(0);
-#endif
-
- gp->gp_line = PL_curcop ? CopLINE(PL_curcop) : 0;
- /* XXX Ideally this cast would be replaced with a change to const char*
- in the struct. */
gp->gp_file_hek = share_hek(file, len, hash);
- gp->gp_egv = gv;
gp->gp_refcnt = 1;
return gp;