summaryrefslogtreecommitdiff
path: root/inline.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-11-29 08:54:43 -0700
committerKarl Williamson <khw@cpan.org>2020-12-06 09:02:53 -0700
commit4eff5eb8fa96cf12671631ada42a7f7a00d51c5b (patch)
tree490cff8b1635d517dceded96731364fd9dc6aa8d /inline.h
parent269cb1d351d144f06b2b724d50e35e7b7e6bc4b9 (diff)
downloadperl-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.h51
1 files changed, 50 insertions, 1 deletions
diff --git a/inline.h b/inline.h
index 3b34ad4667..c18637208f 100644
--- a/inline.h
+++ b/inline.h
@@ -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)
{