Skip to content

Commit 4072f11

Browse files
committed
newSVbool/_true/_false - assign the required values directly.
Prior to this commit, `newSVbool`, `newSV_true`, and `newSV_false` used `newSVsv`, but that is less efficient than directly setting up the new SV as it needs to be.
1 parent fd88a92 commit 4072f11

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

sv.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10563,9 +10563,7 @@ SV *
1056310563
Perl_newSVbool(pTHX_ bool bool_val)
1056410564
{
1056510565
PERL_ARGS_ASSERT_NEWSVBOOL;
10566-
SV *sv = newSVsv(bool_val ? &PL_sv_yes : &PL_sv_no);
10567-
10568-
return sv;
10566+
return (bool_val ? newSV_true() : newSV_false());
1056910567
}
1057010568

1057110569
/*
@@ -10579,7 +10577,18 @@ SV *
1057910577
Perl_newSV_true(pTHX)
1058010578
{
1058110579
PERL_ARGS_ASSERT_NEWSV_TRUE;
10582-
SV *sv = newSVsv(&PL_sv_yes);
10580+
10581+
/* Equivalent to: SV *sv = newSVsv(&PL_sv_yes); */
10582+
SV *sv;
10583+
new_SV(sv);
10584+
SvFLAGS(sv) = SVt_PVNV|SVf_IOK|SVp_IOK|SVf_NOK|SVp_NOK
10585+
|SVf_POK|SVp_POK|SVf_IsCOW|SVppv_STATIC;
10586+
SvPV_set(sv, (char*)PL_Yes);
10587+
SvANY(sv) = new_XPVNV();
10588+
SvCUR_set(sv, 1);
10589+
SvLEN_set(sv, 0);
10590+
SvIV_set(sv, 1);
10591+
SvNV_set(sv, 1);
1058310592

1058410593
return sv;
1058510594
}
@@ -10596,7 +10605,18 @@ SV *
1059610605
Perl_newSV_false(pTHX)
1059710606
{
1059810607
PERL_ARGS_ASSERT_NEWSV_FALSE;
10599-
SV *sv = newSVsv(&PL_sv_no);
10608+
10609+
/* Equivalent to: SV *sv = newSVsv(&PL_sv_no); */
10610+
SV *sv;
10611+
new_SV(sv);
10612+
SvFLAGS(sv) = SVt_PVNV|SVf_IOK|SVp_IOK|SVf_NOK|SVp_NOK
10613+
|SVf_POK|SVp_POK|SVf_IsCOW|SVppv_STATIC;
10614+
SvPV_set(sv, (char*)PL_No);
10615+
SvANY(sv) = new_XPVNV();
10616+
SvCUR_set(sv, 0);
10617+
SvLEN_set(sv, 0);
10618+
SvIV_set(sv, 0);
10619+
SvNV_set(sv, 0);
1060010620

1060110621
return sv;
1060210622
}

0 commit comments

Comments
 (0)