Skip to content

Commit

Permalink
Favour switch over if/else if to improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Branislav Zahradník committed Jun 7, 2021
1 parent a3f8787 commit fb2ac98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 6 additions & 5 deletions op.c
Expand Up @@ -9191,17 +9191,18 @@ Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
OP *o;
I32 assign_type;

if (optype) {
if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN || optype == OP_DORASSIGN) {
switch (optype) {
case 0: break;
case OP_ANDASSIGN:
case OP_ORASSIGN:
case OP_DORASSIGN:
right = scalar(right);
return newLOGOP(optype, 0,
op_lvalue(scalar(left), optype),
newBINOP(OP_SASSIGN, OPpASSIGN_BACKWARDS<<8, right, right));
}
else {
default:
return newBINOP(optype, OPf_STACKED,
op_lvalue(scalar(left), optype), scalar(right));
}
}

if ((assign_type = assignment_type(left)) == ASSIGN_LIST) {
Expand Down
13 changes: 7 additions & 6 deletions toke.c
Expand Up @@ -535,12 +535,13 @@ S_ao(pTHX_ int toketype)
{
if (*PL_bufptr == '=') {
PL_bufptr++;
if (toketype == ANDAND)
pl_yylval.ival = OP_ANDASSIGN;
else if (toketype == OROR)
pl_yylval.ival = OP_ORASSIGN;
else if (toketype == DORDOR)
pl_yylval.ival = OP_DORASSIGN;

switch (toketype) {
case ANDAND: pl_yylval.ival = OP_ANDASSIGN; break;
case OROR: pl_yylval.ival = OP_ORASSIGN; break;
case DORDOR: pl_yylval.ival = OP_DORASSIGN; break;
}

toketype = ASSIGNOP;
}
return REPORT(toketype);
Expand Down

0 comments on commit fb2ac98

Please sign in to comment.