From dae8ab819b9ffd6d540355efffacf225aff00a0f Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sun, 14 Jun 2020 11:24:35 -0600 Subject: Change SvIV and kin to inline functions So that they will evaluate the argument just once. --- sv.h | 66 ++++-------------------------------------------------------------- 1 file changed, 4 insertions(+), 62 deletions(-) (limited to 'sv.h') diff --git a/sv.h b/sv.h index c312e4add4..639fb6386e 100644 --- a/sv.h +++ b/sv.h @@ -1811,51 +1811,6 @@ their respective forms without. C doesn't have a corresponding non-C form. Instead it is like C, but when C is undef, it returns C. -=for apidoc Am|IV|SvIV|SV* sv -=for apidoc_item SvIVx -=for apidoc_item SvIV_nomg - -These coerce the given SV to IV and return it. The returned value in many -circumstances will get stored in C's IV slot, but not in all cases. (Use -C> to make sure it does). - -C is different from the others in that it is guaranteed to evaluate -C exactly once; the others may evaluate it multiple times. Only use this -form if C is an expression with side effects, otherwise use the more -efficient C. - -C is the same as C, but does not perform 'get' magic. - -=for apidoc Am|NV|SvNV|SV* sv -=for apidoc_item SvNVx -=for apidoc_item SvNV_nomg - -These coerce the given SV to NV and return it. The returned value in many -circumstances will get stored in C's NV slot, but not in all cases. (Use -C> to make sure it does). - -C is different from the others in that it is guaranteed to evaluate -C exactly once; the others may evaluate it multiple times. Only use this -form if C is an expression with side effects, otherwise use the more -efficient C. - -C is the same as C, but does not perform 'get' magic. - -=for apidoc Am|UV|SvUV|SV* sv -=for apidoc_item SvUVx -=for apidoc_item SvUV_nomg - -These coerce the given SV to UV and return it. The returned value in many -circumstances will get stored in C's UV slot, but not in all cases. (Use -C> to make sure it does). - -C is different from the others in that it is guaranteed to evaluate -C exactly once; the others may evaluate it multiple times. Only use this -form if C is an expression with side effects, otherwise use the more -efficient C. - -C is the same as C, but does not perform 'get' magic. - =for apidoc SvTRUE =for apidoc_item SvTRUEx =for apidoc_item SvTRUE_nomg @@ -1893,17 +1848,6 @@ scalar. =cut */ -/* Let us hope that bitmaps for UV and IV are the same */ -#define SvIV(sv) (SvIOK_nog(sv) ? SvIVX(sv) : sv_2iv(sv)) -#define SvUV(sv) (SvUOK_nog(sv) ? SvUVX(sv) : sv_2uv(sv)) -#define SvNV(sv) (SvNOK_nog(sv) ? SvNVX(sv) : sv_2nv(sv)) - -#define SvIV_nomg(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv_flags(sv, 0)) -#define SvUV_nomg(sv) (SvUOK(sv) ? SvUVX(sv) : sv_2uv_flags(sv, 0)) -#define SvNV_nomg(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv_flags(sv, 0)) - -/* ----*/ - #define SvPV(sv, len) SvPV_flags(sv, len, SV_GMAGIC) #define SvPV_const(sv, len) SvPV_flags_const(sv, len, SV_GMAGIC) #define SvPV_mutable(sv, len) SvPV_flags_mutable(sv, len, SV_GMAGIC) @@ -2042,11 +1986,12 @@ scalar. #define SvTRUEx_nomg(sv) SvTRUE_nomg(sv) #define SvTRUE_nomg_NN(sv) SvTRUE_common(sv, TRUE) +# define SvIVx(sv) SvIV(sv) +# define SvUVx(sv) SvUV(sv) +# define SvNVx(sv) SvNV(sv) + #if defined(PERL_USE_GCC_BRACE_GROUPS) -# define SvIVx(sv) ({SV *_sv = MUTABLE_SV(sv); SvIV(_sv); }) -# define SvUVx(sv) ({SV *_sv = MUTABLE_SV(sv); SvUV(_sv); }) -# define SvNVx(sv) ({SV *_sv = MUTABLE_SV(sv); SvNV(_sv); }) # define SvPVx(sv, len) ({SV *_sv = (sv); SvPV(_sv, len); }) # define SvPVx_const(sv, len) ({SV *_sv = (sv); SvPV_const(_sv, len); }) # define SvPVx_nolen(sv) ({SV *_sv = (sv); SvPV_nolen(_sv); }) @@ -2060,9 +2005,6 @@ scalar. /* These inlined macros use globals, which will require a thread * declaration in user code, so we avoid them under threads */ -# define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv)) -# define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv)) -# define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv)) # define SvPVx(sv, len) ((PL_Sv = (sv)), SvPV(PL_Sv, len)) # define SvPVx_const(sv, len) ((PL_Sv = (sv)), SvPV_const(PL_Sv, len)) # define SvPVx_nolen(sv) ((PL_Sv = (sv)), SvPV_nolen(PL_Sv)) -- cgit v1.2.1