Skip to content

Commit c55f304

Browse files
committed
Perl_doref(): eliminate duplicated code
This compile-time function propagates lvalue ref context down a chain of ops. It does the same thing (setting OPf_MOD and OPpDEREF_XV flags) in three places. Consolidate this code into a single place. Should be no functional changes. Technically the code is slightly different in that OP_[AH]ELEM now checks for kids before following them, but since they always have kids, this makes no difference (except being infinitesimally slower during compilation).
1 parent 39d060c commit c55f304

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

op.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3764,12 +3764,8 @@ Perl_doref(pTHX_ OP *o, I32 type, bool set_op_ref)
37643764
op_null(cLISTOPx(cUNOPo->op_first)->op_first);
37653765
o->op_flags |= OPf_SPECIAL;
37663766
}
3767-
else if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV){
3768-
o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
3769-
: type == OP_RV2HV ? OPpDEREF_HV
3770-
: OPpDEREF_SV);
3771-
o->op_flags |= OPf_MOD;
3772-
}
3767+
else
3768+
goto set_cxt;
37733769

37743770
break;
37753771

@@ -3787,14 +3783,19 @@ Perl_doref(pTHX_ OP *o, I32 type, bool set_op_ref)
37873783
if (type == OP_DEFINED)
37883784
o->op_flags |= OPf_SPECIAL; /* don't create GV */
37893785
/* FALLTHROUGH */
3786+
case OP_AELEM:
3787+
case OP_HELEM:
37903788
case OP_PADSV:
3789+
set_cxt:
3790+
/* if the parent wants an SV/AV/HV ref, set flags indicating
3791+
* that this op should autovivify such a value if need be */
37913792
if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
37923793
o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
37933794
: type == OP_RV2HV ? OPpDEREF_HV
37943795
: OPpDEREF_SV);
37953796
o->op_flags |= OPf_MOD;
37963797
}
3797-
if (o->op_flags & OPf_KIDS) {
3798+
if (o->op_flags & OPf_KIDS && o->op_type != OP_ENTERSUB) {
37983799
type = o->op_type;
37993800
o = cUNOPo->op_first;
38003801
continue;
@@ -3826,18 +3827,6 @@ Perl_doref(pTHX_ OP *o, I32 type, bool set_op_ref)
38263827
o = cBINOPo->op_first;
38273828
continue;
38283829

3829-
case OP_AELEM:
3830-
case OP_HELEM:
3831-
if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
3832-
o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
3833-
: type == OP_RV2HV ? OPpDEREF_HV
3834-
: OPpDEREF_SV);
3835-
o->op_flags |= OPf_MOD;
3836-
}
3837-
type = o->op_type;
3838-
o = cBINOPo->op_first;
3839-
continue;;
3840-
38413830
case OP_SCOPE:
38423831
case OP_LEAVE:
38433832
set_op_ref = FALSE;

0 commit comments

Comments
 (0)