Skip to content

Commit 5d0e4c4

Browse files
committed
op.c auto-use attributes.pm; newSVpvs("attributes") -> newSVpvs_share()
- faster, it is guaranteed "use attributes;" creates a hash key named "attributes" that exists for the rest of the process
1 parent 563689f commit 5d0e4c4

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

op.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3888,7 +3888,7 @@ S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
38883888

38893889
Perl_load_module(
38903890
aTHX_ PERL_LOADMOD_IMPORT_OPS,
3891-
newSVpvs(ATTRSMODULE),
3891+
newSVpvs_share(ATTRSMODULE),
38923892
NULL,
38933893
op_prepend_elem(OP_LIST,
38943894
newSVOP(OP_CONST, 0, stashsv),
@@ -3903,7 +3903,7 @@ STATIC void
39033903
S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp)
39043904
{
39053905
OP *pack, *imop, *arg;
3906-
SV *meth, *stashsv, **svp;
3906+
SV *meth, *stashsv, *attrpkg, **svp;
39073907

39083908
PERL_ARGS_ASSERT_APPLY_ATTRS_MY;
39093909

@@ -3914,17 +3914,23 @@ S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp)
39143914
target->op_type == OP_PADHV ||
39153915
target->op_type == OP_PADAV);
39163916

3917+
attrpkg = newSVpvs_share(ATTRSMODULE);
3918+
/* no sv_2mortal() or its freed by time of leave_scope() -> replace_sv() */
3919+
SAVEFREESV(attrpkg);
3920+
39173921
/* Ensure that attributes.pm is loaded. */
39183922
/* Don't force the C<use> if we don't need it. */
39193923
svp = hv_fetchs(GvHVn(PL_incgv), ATTRSMODULE_PM, FALSE);
39203924
if (svp && *svp != &PL_sv_undef)
39213925
NOOP; /* already in %INC */
3922-
else
3923-
Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT,
3924-
newSVpvs(ATTRSMODULE), NULL);
3926+
else {
3927+
SvREFCNT_inc_simple_void_NN(attrpkg);
3928+
Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, attrpkg, NULL);
3929+
}
39253930

39263931
/* Need package name for method call. */
3927-
pack = newSVOP(OP_CONST, 0, newSVpvs(ATTRSMODULE));
3932+
SvREFCNT_inc_simple_void_NN(attrpkg);
3933+
pack = newSVOP(OP_CONST, 0, attrpkg);
39283934

39293935
/* Build up the real arg-list. */
39303936
stashsv = newSVhek(HvNAME_HEK(stash));
@@ -3989,7 +3995,7 @@ Perl_apply_attrs_string(pTHX_ const char *stashpv, CV *cv,
39893995
}
39903996

39913997
Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS,
3992-
newSVpvs(ATTRSMODULE),
3998+
newSVpvs_share(ATTRSMODULE),
39933999
NULL, op_prepend_elem(OP_LIST,
39944000
newSVOP(OP_CONST, 0, newSVpv(stashpv,0)),
39954001
op_prepend_elem(OP_LIST,

0 commit comments

Comments
 (0)