From f4c975aa030b7ad74a7efda242fb8b771ea41c14 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Sat, 8 Jul 2017 15:47:23 +0100 Subject: make callers of SvTRUE() more efficient Where its obvious that the args can't be null, use SvTRUE_NN() instead. Avoid possible multiple evaluations of the arg by assigning to a local var first if necessary. --- universal.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'universal.c') diff --git a/universal.c b/universal.c index be39310da7..6ee65a6a11 100644 --- a/universal.c +++ b/universal.c @@ -233,7 +233,7 @@ Perl_sv_does_sv(pTHX_ SV *sv, SV *namesv, U32 flags) call_sv(methodname, G_SCALAR | G_METHOD); SPAGAIN; - does_it = SvTRUE( TOPs ); + does_it = SvTRUE_NN( TOPs ); FREETMPS; LEAVE; @@ -509,9 +509,10 @@ XS(XS_utf8_downgrade) if (items < 1 || items > 2) croak_xs_usage(cv, "sv, failok=0"); else { - SV * const sv = ST(0); - const bool failok = (items < 2) ? 0 : SvTRUE(ST(1)) ? 1 : 0; - const bool RETVAL = sv_utf8_downgrade(sv, failok); + SV * const sv0 = ST(0); + SV * const sv1 = ST(1); + const bool failok = (items < 2) ? 0 : SvTRUE_NN(sv1) ? 1 : 0; + const bool RETVAL = sv_utf8_downgrade(sv0, failok); ST(0) = boolSV(RETVAL); } @@ -564,7 +565,8 @@ XS(XS_Internals_SvREADONLY) /* This is dangerous stuff. */ XSRETURN_NO; } else if (items == 2) { - if (SvTRUE(ST(1))) { + SV *sv1 = ST(1); + if (SvTRUE_NN(sv1)) { SvFLAGS(sv) |= SVf_READONLY; XSRETURN_YES; } @@ -820,7 +822,7 @@ XS(XS_re_regname) if (!rx) XSRETURN_UNDEF; - if (items == 2 && SvTRUE(ST(1))) { + if (items == 2 && SvTRUE_NN(ST(1))) { flags = RXapif_ALL; } else { flags = RXapif_ONE; @@ -853,7 +855,7 @@ XS(XS_re_regnames) if (!rx) XSRETURN_UNDEF; - if (items == 1 && SvTRUE(ST(0))) { + if (items == 1 && SvTRUE_NN(ST(0))) { flags = RXapif_ALL; } else { flags = RXapif_ONE; -- cgit v1.2.1