Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Use sv_catpvs where appropriate vs sv_catpv
Browse files Browse the repository at this point in the history
This moves calculations definitely to compile time; some optimizing
compilers may already do this, but some may not.

(cherry picked from commit f8db7d5)

cperl: They picked a very unfortunate name, not sv_catpvc for
constant strings.
  • Loading branch information
khwilliamson authored and rurban committed Apr 2, 2019
1 parent 0fa15e6 commit 056abbd
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 75 deletions.
10 changes: 5 additions & 5 deletions doio.c
Expand Up @@ -3273,24 +3273,24 @@ Perl_vms_start_glob
# if defined(OS2)
sv_setpv(tmpcmd, "for a in ");
sv_catsv(tmpcmd, tmpglob);
sv_catpv(tmpcmd, "; do echo \"$a\\0\\c\"; done |");
sv_catpvs(tmpcmd, "; do echo \"$a\\0\\c\"; done |");
# elif defined(DJGPP)
sv_setpv(tmpcmd, "/dev/dosglob/"); /* File System Extension */
sv_catsv(tmpcmd, tmpglob);
# else
sv_setpv(tmpcmd, "perlglob ");
sv_catsv(tmpcmd, tmpglob);
sv_catpv(tmpcmd, " |");
sv_catpvs(tmpcmd, " |");
# endif
# elif defined(CSH)
sv_setpvn(tmpcmd, PL_cshname, PL_cshlen);
sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
sv_catpvs(tmpcmd, " -cf 'set nonomatch; glob ");
sv_catsv(tmpcmd, tmpglob);
sv_catpv(tmpcmd, "' 2>/dev/null |");
sv_catpvs(tmpcmd, "' 2>/dev/null |");
# else
sv_setpv(tmpcmd, "echo ");
sv_catsv(tmpcmd, tmpglob);
sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\n\\n\\n\\n'|");
sv_catpvs(tmpcmd, "|tr -s ' \t\f\r' '\\n\\n\\n\\n'|");
# endif /* !DOSISH && !CSH */
{
SV ** const svp = hv_fetchs(GvHVn(PL_envgv), "LS_COLORS", 0);
Expand Down
105 changes: 53 additions & 52 deletions dump.c
Expand Up @@ -460,23 +460,23 @@ Perl_sv_peek(pTHX_ SV *sv)
SvPVCLEAR(t);
retry:
if (!sv) {
sv_catpv(t, "VOID");
sv_catpvs(t, "VOID");
goto finish;
}
else if (sv == (const SV *)0x55555555 || ((char)SvTYPE(sv)) == 'U') {
/* detect data corruption under memory poisoning */
sv_catpv(t, "WILD");
sv_catpvs(t, "WILD");
goto finish;
}
else if (SvIMMORTAL(sv)) { /* the 4 sv_immortals or sv_placeholder */
if (sv == UNDEF) {
sv_catpv(t, "SV_UNDEF");
sv_catpvs(t, "SV_UNDEF");
if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
SVs_GMG|SVs_SMG|SVs_RMG)))
goto finish;
}
else if (sv == SV_NO) {
sv_catpv(t, "SV_NO");
sv_catpvs(t, "SV_NO");
if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
SVs_GMG|SVs_SMG|SVs_RMG)) &&
!(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
Expand All @@ -486,7 +486,7 @@ Perl_sv_peek(pTHX_ SV *sv)
goto finish;
}
else if (sv == SV_YES) {
sv_catpv(t, "SV_YES");
sv_catpvs(t, "SV_YES");
if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
SVs_GMG|SVs_SMG|SVs_RMG)) &&
!(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
Expand All @@ -497,7 +497,7 @@ Perl_sv_peek(pTHX_ SV *sv)
goto finish;
}
else if (sv == SV_ZERO) {
sv_catpv(t, "SV_ZERO");
sv_catpvs(t, "SV_ZERO");
if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
SVs_GMG|SVs_SMG|SVs_RMG)) &&
!(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
Expand All @@ -508,15 +508,16 @@ Perl_sv_peek(pTHX_ SV *sv)
goto finish;
}
else if (sv == PLACEHOLDER) {
sv_catpv(t, "SV_PLACEHOLDER");
sv_catpvs(t, "SV_PLACEHOLDER");
if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
SVs_GMG|SVs_SMG|SVs_RMG)))
SVs_GMG|SVs_SMG|SVs_RMG)) &&
SvREADONLY(sv))
goto finish;
}
sv_catpv(t, ":");
sv_catpvs(t, ":");
}
else if (SvREFCNT(sv) == 0) {
sv_catpv(t, "(");
sv_catpvs(t, "(");
unref++;
}
else if (DEBUG_R_TEST_) {
Expand All @@ -540,11 +541,11 @@ Perl_sv_peek(pTHX_ SV *sv)
}

if (SvROK(sv)) {
sv_catpv(t, "\\");
sv_catpvs(t, "\\");
if (SvCUR(t) + unref > 10) {
SvCUR_set(t, unref + 3);
*SvEND(t) = '\0';
sv_catpv(t, "...");
sv_catpvs(t, "...");
goto finish;
}
sv = SvRV(sv);
Expand Down Expand Up @@ -574,16 +575,16 @@ Perl_sv_peek(pTHX_ SV *sv)
if (type == SVt_NULL)
goto finish;
} else {
sv_catpv(t, "FREED");
sv_catpvs(t, "FREED");
goto finish;
}

if (SvPOKp(sv)) {
if (!SvPVX_const(sv))
sv_catpv(t, "(null)");
sv_catpvs(t, "(null)");
else {
SV * const tmp = newSVpvs("");
sv_catpv(t, "(");
sv_catpvs(t, "(");
if (SvOOK(sv)) {
STRLEN delta;
SvOOK_offset(sv, delta);
Expand Down Expand Up @@ -611,13 +612,13 @@ Perl_sv_peek(pTHX_ SV *sv)
Perl_sv_catpvf(aTHX_ t, "(%" IVdf ")", (IV)SvIVX(sv));
}
else
sv_catpv(t, "()");
sv_catpvs(t, "()");

finish:
while (unref--)
sv_catpv(t, ")");
sv_catpvs(t, ")");
if (TAINTING_get && sv && SvTAINTED(sv))
sv_catpv(t, " [tainted]");
sv_catpvs(t, " [tainted]");
return SvPV_nolen(t);
}

Expand Down Expand Up @@ -1088,26 +1089,26 @@ S_pm_description(pTHX_ const PMOP *pm)
PERL_ARGS_ASSERT_PM_DESCRIPTION;

if (pmflags & PMf_ONCE)
sv_catpv(desc, ",ONCE");
sv_catpvs(desc, ",ONCE");
#ifdef USE_ITHREADS
if (SvREADONLY(PL_regex_pad[pm->op_pmoffset]))
sv_catpv(desc, ":USED");
sv_catpvs(desc, ":USED");
#else
if (pmflags & PMf_USED)
sv_catpv(desc, ":USED");
sv_catpvs(desc, ":USED");
#endif

if (regex) {
if (RX_ISTAINTED(regex))
sv_catpv(desc, ",TAINTED");
sv_catpvs(desc, ",TAINTED");
if (SAFE_RX_CHECK_SUBSTR(regex)) {
if (!(RX_INTFLAGS(regex) & PREGf_NOSCAN))
sv_catpv(desc, ",SCANFIRST");
sv_catpvs(desc, ",SCANFIRST");
if (RX_EXTFLAGS(regex) & RXf_CHECK_ALL)
sv_catpv(desc, ",ALL");
sv_catpvs(desc, ",ALL");
}
if (RX_EXTFLAGS(regex) & RXf_SKIPWHITE)
sv_catpv(desc, ",SKIPWHITE");
sv_catpvs(desc, ",SKIPWHITE");
}

append_flags(desc, pmflags, pmflags_flags_names);
Expand Down Expand Up @@ -1242,16 +1243,16 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o, const CV *c
SV * const tmpsv = newSVpvs("");
switch (o->op_flags & OPf_WANT) {
case OPf_WANT_VOID:
sv_catpv(tmpsv, ",VOID");
sv_catpvs(tmpsv, ",VOID");
break;
case OPf_WANT_SCALAR:
sv_catpv(tmpsv, ",SCALAR");
sv_catpvs(tmpsv, ",SCALAR");
break;
case OPf_WANT_LIST:
sv_catpv(tmpsv, ",LIST");
sv_catpvs(tmpsv, ",LIST");
break;
default:
sv_catpv(tmpsv, ",UNKNOWN");
sv_catpvs(tmpsv, ",UNKNOWN");
break;
}
append_flags(tmpsv, o->op_flags, op_flags_names);
Expand Down Expand Up @@ -1316,10 +1317,10 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o, const CV *c
/* don't display anonymous zero values */
continue;

sv_catpv(tmpsv, ",");
sv_catpvs(tmpsv, ",");
if (label != -1) {
sv_catpv(tmpsv, &PL_op_private_labels[label]);
sv_catpv(tmpsv, "=");
sv_catpvs(tmpsv, "=");
}
if (enum_label == -1)
Perl_sv_catpvf(aTHX_ tmpsv, "0x%" UVxf, (UV)val);
Expand All @@ -1334,13 +1335,13 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o, const CV *c
&& PL_op_private_labels[ix+1] == '\0'))
{
oppriv -= (1<<bit);
sv_catpv(tmpsv, ",");
sv_catpvs(tmpsv, ",");
sv_catpv(tmpsv, &PL_op_private_labels[ix]);
}
}
}
if (oppriv) {
sv_catpv(tmpsv, ",");
sv_catpvs(tmpsv, ",");
Perl_sv_catpvf(aTHX_ tmpsv, "0x%" UVxf, (UV)oppriv);
}
}
Expand Down Expand Up @@ -2231,22 +2232,22 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest,
(int)(PL_dumpindent*level), "", (UV)flags);

if ((flags & SVs_PADSTALE))
sv_catpv(d, "PADSTALE,");
sv_catpvs(d, "PADSTALE,");
if ((flags & SVs_PADTMP))
sv_catpv(d, "PADTMP,");
sv_catpvs(d, "PADTMP,");
append_flags(d, flags, first_sv_flags_names);
if (flags & SVf_ROK) {
sv_catpv(d, "ROK,");
if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,");
sv_catpvs(d, "ROK,");
if (SvWEAKREF(sv)) sv_catpvs(d, "WEAKREF,");
}
if (flags & SVf_IsCOW && type != SVt_PVHV) sv_catpvs(d, "IsCOW,");
append_flags(d, flags, second_sv_flags_names);
if (flags & SVp_SCREAM && type != SVt_PVHV && !isGV_with_GP(sv)
&& type != SVt_PVAV) {
if (SvPCS_IMPORTED(sv))
sv_catpv(d, "PCS_IMPORTED,");
sv_catpvs(d, "PCS_IMPORTED,");
else
sv_catpv(d, "SCREAM,");
sv_catpvs(d, "SCREAM,");
}

/* process type-specific SV flags */
Expand All @@ -2262,30 +2263,30 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest,
case SVt_PVGV:
case SVt_PVLV:
if (isGV_with_GP(sv))
sv_catpv(d, "with_GP,");
sv_catpvs(d, "with_GP,");
/* FALLTHROUGH */
case SVt_PVMG:
default:
if (SvIsUV(sv) && !(flags & SVf_ROK)) sv_catpv(d, "IsUV,");
if (SvIsUV(sv) && !(flags & SVf_ROK)) sv_catpvs(d, "IsUV,");
break;

case SVt_PVAV:
if (AvSHAPED(sv)) sv_catpv(d, "SHAPED,");
if (AvREAL(sv)) sv_catpv(d, "REAL,");
if (AvREIFY(sv)) sv_catpv(d, "REIFY,");
if (AvSTATIC(sv)) sv_catpv(d, "STATIC,");
if (AvIsCOW(sv)) sv_catpv(d, "IsCOW,");
if (AvSHAPED(sv)) sv_catpvs(d, "SHAPED,");
if (AvREAL(sv)) sv_catpvs(d, "REAL,");
if (AvREIFY(sv)) sv_catpvs(d, "REIFY,");
if (AvSTATIC(sv)) sv_catpvs(d, "STATIC,");
if (AvIsCOW(sv)) sv_catpvs(d, "IsCOW,");
break;
}
/* SVphv_SHAREKEYS and SVpav_SHAPED are also 0x20000000 */
if ((type != SVt_PVHV) && (type != SVt_PVAV) && SvUTF8(sv))
sv_catpv(d, "UTF8");
sv_catpvs(d, "UTF8");

if (*(SvEND(d) - 1) == ',') {
SvCUR_set(d, SvCUR(d) - 1);
SvPVX(d)[SvCUR(d)] = '\0';
}
sv_catpv(d, ")");
sv_catpvs(d, ")");
s = SvPVX_const(d);

/* dump initial SV details */
Expand Down Expand Up @@ -2873,13 +2874,13 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest,
do_hv_dump (level, file, " GvSTASH", GvSTASH(sv));
SV_SET_STRINGIFY_FLAGS(d,GvFLAGS(sv),gv_flags_names);
if (GvIMPORTED(sv)) {
sv_catpv(d, "IMPORT");
sv_catpvs(d, "IMPORT");
if (GvIMPORTED(sv) == GVf_IMPORTED)
sv_catpv(d, "ALL,");
sv_catpvs(d, "ALL,");
else {
sv_catpv(d, "(");
sv_catpvs(d, "(");
append_flags(d, GvFLAGS(sv), gv_flags_imported_names);
sv_catpv(d, " ),");
sv_catpvs(d, " ),");
}
}
Perl_dump_indent(aTHX_ level, file, " GvFLAGS = 0x%" UVxf " (%s)\n",
Expand Down
2 changes: 1 addition & 1 deletion os2/os2.c
Expand Up @@ -1151,7 +1151,7 @@ do_spawn_ve(pTHX_ SV *really, const char **argv, U32 flag, U32 execf, char *inic
documentation, DosQueryAppType sometimes (?)
does not append ".exe", so we could have
reached this place). */
sv_catpv(scrsv, ".exe");
sv_catpvs(scrsv, ".exe");
argv[0] = scr = SvPV(scrsv, n_a); /* Reload */
if (PerlLIO_stat(scr,&statbuf) >= 0
&& !S_ISDIR(statbuf.st_mode)) { /* Found */
Expand Down
8 changes: 4 additions & 4 deletions pp_ctl.c
Expand Up @@ -4479,7 +4479,7 @@ S_require_file(pTHX_ SV *sv)
}

if (c == e && isIDFIRST_lazy_if_safe(name, e, utf8)) {
sv_catpv(msg, " (you may need to install the ");
sv_catpvs(msg, " (you may need to install the ");
for (c = name; c < e; c++) {
if (*c == '/') {
sv_catpvs(msg, "::");
Expand All @@ -4488,14 +4488,14 @@ S_require_file(pTHX_ SV *sv)
sv_catpvn(msg, c, 1);
}
}
sv_catpv(msg, " module)");
sv_catpvs(msg, " module)");
}
}
else if (memENDs(name, len, ".h")) {
sv_catpv(msg, " (change .h to .ph maybe?) (did you run h2ph?)");
sv_catpvs(msg, " (change .h to .ph maybe?) (did you run h2ph?)");
}
else if (memENDs(name, len, ".ph")) {
sv_catpv(msg, " (did you run h2ph?)");
sv_catpvs(msg, " (did you run h2ph?)");
}

/* diag_listed_as: Can't locate %s */
Expand Down

0 comments on commit 056abbd

Please sign in to comment.