8000 gh-101169: reduce the implementation of except* by one bytecode instr… · python/cpython@9ec9b20 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ec9b20

Browse files
authored
gh-101169: reduce the implementation of except* by one bytecode instruction (#101170)
1 parent 6036c3e commit 9ec9b20

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

Python/compile.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,16 +3586,15 @@ compiler_try_except(struct compiler *c, stmt_ty s)
35863586
[] POP_BLOCK
35873587
[] JUMP L0
35883588
3589-
[exc] L1: COPY 1 ) save copy of the original exception
3590-
[orig, exc] BUILD_LIST ) list for raised/reraised excs ("result")
3591-
[orig, exc, res] SWAP 2
3589+
[exc] L1: BUILD_LIST ) list for raised/reraised excs ("result")
3590+
[orig, res] COPY 2 ) make a copy of the original EG
35923591
35933592
[orig, res, exc] <evaluate E1>
35943593
[orig, res, exc, E1] CHECK_EG_MATCH
3595-
[orig, red, rest/exc, match?] COPY 1
3596-
[orig, red, rest/exc, match?, match?] POP_JUMP_IF_NOT_NONE H1
3597-
[orig, red, exc, None] POP_TOP
3598-
[orig, red, exc] JUMP L2
3594+
[orig, res, rest/exc, match?] COPY 1
3595+
[orig, res, rest/exc, match?, match?] POP_JUMP_IF_NOT_NONE H1
3596+
[orig, res, exc, None] POP_TOP
3597+
[orig, res, exc] JUMP L2
35993598
36003599
[orig, res, rest, match] H1: <assign to V1> (or POP if no V1)
36013600
@@ -3664,21 +3663,17 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
36643663
except = next_except;
36653664
NEW_JUMP_TARGET_LABEL(c, handle_match);
36663665
if (i == 0) {
3667-
/* Push the original EG into the stack */
3666+
/* create empty list for exceptions raised/reraise in the except* blocks */
36683667
/*
3669-
[exc] COPY 1
3670-
[orig, exc]
3668+
[orig] BUILD_LIST
36713669
*/
3672-
ADDOP_I(c, loc, COPY, 1);
3673-
3674-
/* create empty list for exceptions raised/reraise in the except* blocks */
3670+
/* Creat a copy of the original EG */
36753671
/*
3676-
[orig, exc] BUILD_LIST
3677-
[orig, exc, []] SWAP 2
3672+
[orig, []] COPY 2
36783673
[orig, [], exc]
36793674
*/
36803675
ADDOP_I(c, loc, BUILD_LIST, 0);
3681-
ADDOP_I(c, loc, SWAP, 2);
3676+
ADDOP_I(c, loc, COPY, 2);
36823677
}
36833678
if (handler->v.ExceptHandler.type) {
36843679
VISIT(c, expr, handler->v.ExceptHandler.type);

0 commit comments

Comments
 (0)
0