From: Daniel Dragan Date: Wed, 7 Nov 2012 23:03:10 +0000 (-0500) Subject: refactor gv.c:Perl_newGP X-Git-Tag: upstream/5.20.0~4911 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2639089b2b71c9124405bd9634b99be22b265f09;p=platform%2Fupstream%2Fperl.git 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 . --- diff --git a/gv.c b/gv.c index 40f7c23..9de8886 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;