Skip to content

Commit 81ca02a

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 81ca02a

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

op.c

Lines changed: 15 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,25 @@ 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+
/* Can't use 1 SV* head with 2 refcounts for attrpkg.
3928+
Perl_load_module()'s callee will modify the buf with sv_catpvs(".pm"). */
3929+
SV * sv = newSVhek(SvSHARED_HEK_FROM_PV(SvPVX(attrpkg)));
3930+
Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, sv, NULL);
3931+
}
39253932

39263933
/* Need package name for method call. */
3927-
pack = newSVOP(OP_CONST, 0, newSVpvs(ATTRSMODULE));
3934+
SvREFCNT_inc_simple_void_NN(attrpkg);
3935+
pack = newSVOP(OP_CONST, 0, attrpkg);
39283936

39293937
/* Build up the real arg-list. */
39303938
stashsv = newSVhek(HvNAME_HEK(stash));
@@ -3989,7 +3997,7 @@ Perl_apply_attrs_string(pTHX_ const char *stashpv, CV *cv,
39893997
}
39903998

39913999
Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS,
3992-
newSVpvs(ATTRSMODULE),
4000+
newSVpvs_share(ATTRSMODULE),
39934001
NULL, op_prepend_elem(OP_LIST,
39944002
newSVOP(OP_CONST, 0, newSVpv(stashpv,0)),
39954003
op_prepend_elem(OP_LIST,

0 commit comments

Comments
 (0)