diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-07-05 22:51:50 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-08-05 02:23:28 -0700 |
commit | c82ecf346a8512f22f25188e450d92938c245421 (patch) | |
tree | 4a8a85a9655bcb136136674dc3f838204bc9d202 /cop.h | |
parent | 38be3d0038ef87b22af88f80db1fbeb0292ce53b (diff) | |
download | perl-c82ecf346a8512f22f25188e450d92938c245421.tar.gz |
[perl #117855] Store CopFILEGV in a pad under ithreads
This saves having to allocate a separate string buffer for every cop
(control op; every statement has one).
Under non-threaded builds, every cop has a pointer to the GV for that
source file, namely *{"_<filename"}.
Under threaded builds, the name of the GV used to be stored instead.
Now we store an offset into the per-interpreter PL_filegvpad, which
points to the GV.
This makes no significant speed difference, but it reduces mem-
ory usage.
Diffstat (limited to 'cop.h')
-rw-r--r-- | cop.h | 49 |
1 files changed, 14 insertions, 35 deletions
@@ -389,7 +389,8 @@ struct cop { #ifdef USE_ITHREADS PADOFFSET cop_stashoff; /* offset into PL_stashpad, for the package the line was compiled in */ - char * cop_file; /* file name the following line # is from */ + PADOFFSET cop_filegvoff; /* PL_filegv offset, for the file name the + following line # is from */ #else HV * cop_stash; /* package line was compiled in */ GV * cop_filegv; /* file the following line # is from */ @@ -404,54 +405,32 @@ struct cop { }; #ifdef USE_ITHREADS -# define CopFILE(c) ((c)->cop_file) -# define CopFILEGV(c) (CopFILE(c) \ - ? gv_fetchfile(CopFILE(c)) : NULL) - -# ifdef NETWARE -# define CopFILE_set(c,pv) ((c)->cop_file = savepv(pv)) -# define CopFILE_setn(c,pv,l) ((c)->cop_file = savepv((pv),(l))) -# else -# define CopFILE_set(c,pv) ((c)->cop_file = savesharedpv(pv)) -# define CopFILE_setn(c,pv,l) ((c)->cop_file = savesharedpvn((pv),(l))) -# endif - -# define CopFILESV(c) (CopFILE(c) \ - ? GvSV(gv_fetchfile(CopFILE(c))) : NULL) -# define CopFILEAV(c) (CopFILE(c) \ - ? GvAV(gv_fetchfile(CopFILE(c))) : NULL) -# define CopFILEAVx(c) (assert_(CopFILE(c)) \ - GvAV(gv_fetchfile(CopFILE(c)))) +# define CopFILEGV(c) PL_filegvpad[(c)->cop_filegvoff] +# define CopFILEGV_set(c,gv) ((c)->cop_filegvoff = (gv) \ + ? allocfilegv((GV *)SvREFCNT_inc_NN(gv)) \ + : 0) # define CopSTASH(c) PL_stashpad[(c)->cop_stashoff] # define CopSTASH_set(c,hv) ((c)->cop_stashoff = (hv) \ ? alloccopstash(hv) \ : 0) -# ifdef NETWARE -# define CopFILE_free(c) SAVECOPFILE_FREE(c) -# else -# define CopFILE_free(c) (PerlMemShared_free(CopFILE(c)),(CopFILE(c) = NULL)) -# endif +# define CopFILE_free(c) S_CopFILE_free(aTHX_ c) #else # define CopFILEGV(c) ((c)->cop_filegv) # define CopFILEGV_set(c,gv) ((c)->cop_filegv = (GV*)SvREFCNT_inc(gv)) -# define CopFILE_set(c,pv) CopFILEGV_set((c), gv_fetchfile(pv)) -# define CopFILE_setn(c,pv,l) CopFILEGV_set((c), gv_fetchfile_flags((pv),(l),0)) -# define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : NULL) -# define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : NULL) -# ifdef DEBUGGING -# define CopFILEAVx(c) (assert(CopFILEGV(c)), GvAV(CopFILEGV(c))) -# else -# define CopFILEAVx(c) (GvAV(CopFILEGV(c))) -# endif -# define CopFILE(c) (CopFILEGV(c) && GvSV(CopFILEGV(c)) \ - ? SvPVX(GvSV(CopFILEGV(c))) : NULL) # define CopSTASH(c) ((c)->cop_stash) # define CopSTASH_set(c,hv) ((c)->cop_stash = (hv)) # define CopFILE_free(c) (SvREFCNT_dec(CopFILEGV(c)),(CopFILEGV(c) = NULL)) #endif /* USE_ITHREADS */ +#define CopFILE_set(c,pv) CopFILEGV_set((c), gv_fetchfile(pv)) +#define CopFILE_setn(c,pv,l) CopFILEGV_set((c), gv_fetchfile_flags((pv),(l),0)) +#define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : NULL) +#define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : NULL) +#define CopFILEAVx(c) (assert_(CopFILEGV(c)) GvAV(CopFILEGV(c))) +#define CopFILE(c) (CopFILEGV(c) && GvSV(CopFILEGV(c)) \ + ? SvPVX(GvSV(CopFILEGV(c))) : NULL) #define CopSTASHPV(c) (CopSTASH(c) ? HvNAME_get(CopSTASH(c)) : NULL) /* cop_stash is not refcounted */ #define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD)) |