diff options
author | Nicholas Clark <nick@ccl4.org> | 2002-08-19 00:17:01 +0100 |
---|---|---|
committer | hv <hv@crypt.org> | 2002-08-20 14:07:56 +0000 |
commit | 46187eeb6d9336144ec364973ed57177c89816cf (patch) | |
tree | 476bf6483bf8a7a30003c193ed84a916e42af83c /sv.h | |
parent | 30e7fb8a3219c29103ee46480c5ed6162f1ce92b (diff) | |
download | perl-46187eeb6d9336144ec364973ed57177c89816cf.tar.gz |
Clean up copy-on-write macros and debug facilities (new flag 'C').
Handle CoW in hashes:
Subject: Re: why would tr/// be performing hash copies?
Message-id: <20020818221700.GD294@Bagpuss.unfortu.net>
p4raw-id: //depot/perl@17740
Diffstat (limited to 'sv.h')
-rw-r--r-- | sv.h | 34 |
1 files changed, 15 insertions, 19 deletions
@@ -556,27 +556,16 @@ Set the length of the string which is in the SV. See C<SvCUR>. #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK) -#ifdef PERL_COPY_ON_WRITE -#define SvRELEASE_IVX(sv) ((SvFLAGS(sv) & (SVf_OOK|SVf_READONLY|SVf_FAKE)) \ - && sv_release_IVX(sv)) -#define SvIOKp_on(sv) ((void)sv_release_IVX(sv), \ +#define SvIOKp_on(sv) (SvRELEASE_IVX(sv), \ SvFLAGS(sv) |= SVp_IOK) -#else -#define SvIOKp_on(sv) ((void)SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK) -#endif #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK) #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK) #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK) #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK) #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK) -#ifdef PERL_COPY_ON_WRITE -#define SvIOK_on(sv) ((void)sv_release_IVX(sv), \ +#define SvIOK_on(sv) (SvRELEASE_IVX(sv), \ SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) -#else -#define SvIOK_on(sv) ((void)SvOOK_off(sv), \ - SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) -#endif #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV)) #define SvIOK_only(sv) ((void)SvOK_off(sv), \ SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) @@ -1077,23 +1066,30 @@ otherwise. #define SvIsCOW(sv) ((SvFLAGS(sv) & (SVf_FAKE | SVf_READONLY)) == \ (SVf_FAKE | SVf_READONLY)) +#define SvIsCOW_shared_hash(sv) (SvIsCOW(sv) && SvLEN(sv) == 0) /* flag values for sv_*_flags functions */ #define SV_IMMEDIATE_UNREF 1 #define SV_GMAGIC 2 - -#ifdef PERL_COPY_ON_WRITE #define SV_COW_DROP_PV 4 -#define SvIsCOW_shared_hash(sv) (SvIsCOW(sv) && SvLEN(sv) == 0) -#define SvIsCOW_normal(sv) (SvIsCOW(sv) && SvLEN(sv)) +/* We are about to replace the SV's current value. So if it's copy on write + we need to normalise it. Use the SV_COW_DROP_PV flag hint to say that + the value is about to get thrown away, so drop the PV rather than go to + the effort of making a read-write copy only for it to get immediately + discarded. */ #define SV_CHECK_THINKFIRST_COW_DROP(sv) if (SvTHINKFIRST(sv)) \ sv_force_normal_flags(sv, SV_COW_DROP_PV) + +#ifdef PERL_COPY_ON_WRITE +# define SvRELEASE_IVX(sv) ((void)((SvFLAGS(sv) & (SVf_OOK|SVf_READONLY|SVf_FAKE)) \ + && sv_release_IVX(sv))) +# define SvIsCOW_normal(sv) (SvIsCOW(sv) && SvLEN(sv)) #else -#define SV_CHECK_THINKFIRST_COW_DROP(sv) if (SvTHINKFIRST(sv)) \ - sv_force_normal_flags(sv, 0) +# define SvRELEASE_IVX(sv) ((void)SvOOK_off(sv)) #endif /* PERL_COPY_ON_WRITE */ + #define SV_CHECK_THINKFIRST(sv) if (SvTHINKFIRST(sv)) \ sv_force_normal_flags(sv, 0) |