Skip to content

Commit 0258694

Browse files
committed
Tidy up test for conditional opcodes
1 parent 0278706 commit 0258694

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Include/internal/pycore_opcode_utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ extern "C" {
4545
(opcode) == JUMP_BACKWARD || \
4646
(opcode) == JUMP_BACKWARD_NO_INTERRUPT)
4747

48+
#define IS_CONDITIONAL_JUMP_OPCODE(opcode) \
49+
((opcode) == POP_JUMP_IF_FALSE || \
50+
(opcode) == POP_JUMP_IF_TRUE || \
51+
(opcode) == POP_JUMP_IF_NONE || \
52+
(opcode) == POP_JUMP_IF_NOT_NONE)
53+
4854
#define IS_SCOPE_EXIT_OPCODE(opcode) \
4955
((opcode) == RETURN_VALUE || \
5056
(opcode) == RAISE_VARARGS || \

Python/codegen.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,8 @@ codegen_addop_j(instr_sequence *seq, location loc,
409409
if (_PyInstructionSequence_Addop(seq, opcode, target.id, loc) != SUCCESS) {
410410
return ERROR;
411411
}
412-
switch (opcode) {
413-
case POP_JUMP_IF_FALSE:
414-
case POP_JUMP_IF_TRUE:
415-
case POP_JUMP_IF_NONE:
416-
case POP_JUMP_IF_NOT_NONE:
417-
case FOR_ITER:
418-
return _PyInstructionSequence_Addop(seq, NOT_TAKEN, 0, NO_LOCATION);
412+
if (IS_CONDITIONAL_JUMP_OPCODE(opcode) || opcode == FOR_ITER) {
413+
return _PyInstructionSequence_Addop(seq, NOT_TAKEN, 0, NO_LOCATION);
419414
}
420415
return SUCCESS;
421416
}

0 commit comments

Comments
 (0)