diff options
author | Karl Williamson <khw@cpan.org> | 2020-11-29 08:54:43 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2020-12-06 09:02:53 -0700 |
commit | 4eff5eb8fa96cf12671631ada42a7f7a00d51c5b (patch) | |
tree | 490cff8b1635d517dceded96731364fd9dc6aa8d /inline.h | |
parent | 269cb1d351d144f06b2b724d50e35e7b7e6bc4b9 (diff) | |
download | perl-4eff5eb8fa96cf12671631ada42a7f7a00d51c5b.tar.gz |
Evaluate arg once in all forms of SvTRUE
5.32 did this for one form; now all do.
Diffstat (limited to 'inline.h')
-rw-r--r-- | inline.h | 51 |
1 files changed, 50 insertions, 1 deletions
@@ -212,13 +212,62 @@ Perl_ReANY(const REGEXP * const re) /* ------------------------------- sv.h ------------------------------- */ PERL_STATIC_INLINE bool -Perl_SvTRUE(pTHX_ SV *sv) { +Perl_SvTRUE(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_SVTRUE; + if (UNLIKELY(sv == NULL)) return FALSE; SvGETMAGIC(sv); return SvTRUE_nomg_NN(sv); } +PERL_STATIC_INLINE bool +Perl_SvTRUE_nomg(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_SVTRUE_NOMG; + + if (UNLIKELY(sv == NULL)) + return FALSE; + return SvTRUE_nomg_NN(sv); +} + +PERL_STATIC_INLINE bool +Perl_SvTRUE_NN(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_SVTRUE_NN; + + SvGETMAGIC(sv); + return SvTRUE_nomg_NN(sv); +} + +PERL_STATIC_INLINE bool +Perl_SvTRUE_common(pTHX_ SV * sv, const bool sv_2bool_is_fallback) +{ + PERL_ARGS_ASSERT_SVTRUE_COMMON; + + if (UNLIKELY(SvIMMORTAL_INTERP(sv))) + return SvIMMORTAL_TRUE(sv); + + if (! SvOK(sv)) + return FALSE; + + if (SvPOK(sv)) + return SvPVXtrue(sv); + + if (SvIOK(sv)) + return SvIVX(sv) != 0; /* casts to bool */ + + if (SvROK(sv) && !(SvOBJECT(SvRV(sv)) && HvAMAGIC(SvSTASH(SvRV(sv))))) + return TRUE; + + if (sv_2bool_is_fallback) + return sv_2bool_nomg(sv); + + return isGV_with_GP(sv); +} + + PERL_STATIC_INLINE SV * Perl_SvREFCNT_inc(SV *sv) { |