summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-01-19 23:30:49 (GMT)
committerGitHub <noreply@github.com>2023-01-19 23:30:49 (GMT)
commit9ec9b203eaa219ed13ad9deb21740924bd22b10d (patch)
tree150505000af2ee0a398a49b0a564ebaa019caefe /Python/compile.c
parent6036c3e856f033bf13e929536e7bf127fdd921c9 (diff)
downloadcpython-9ec9b203eaa219ed13ad9deb21740924bd22b10d.zip
cpython-9ec9b203eaa219ed13ad9deb21740924bd22b10d.tar.gz
cpython-9ec9b203eaa219ed13ad9deb21740924bd22b10d.tar.bz2
gh-101169: reduce the implementation of except* by one bytecode instruction (#101170)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/Python/compile.c b/Python/compile.c
index f98892e..bfc6e34 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -3586,16 +3586,15 @@ compiler_try_except(struct compiler *c, stmt_ty s)
[] POP_BLOCK
[] JUMP L0
- [exc] L1: COPY 1 ) save copy of the original exception
- [orig, exc] BUILD_LIST ) list for raised/reraised excs ("result")
- [orig, exc, res] SWAP 2
+ [exc] L1: BUILD_LIST ) list for raised/reraised excs ("result")
+ [orig, res] COPY 2 ) make a copy of the original EG
[orig, res, exc] <evaluate E1>
[orig, res, exc, E1] CHECK_EG_MATCH
- [orig, red, rest/exc, match?] COPY 1
- [orig, red, rest/exc, match?, match?] POP_JUMP_IF_NOT_NONE H1
- [orig, red, exc, None] POP_TOP
- [orig, red, exc] JUMP L2
+ [orig, res, rest/exc, match?] COPY 1
+ [orig, res, rest/exc, match?, match?] POP_JUMP_IF_NOT_NONE H1
+ [orig, res, exc, None] POP_TOP
+ [orig, res, exc] JUMP L2
[orig, res, rest, match] H1: <assign to V1> (or POP if no V1)
@@ -3664,21 +3663,17 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
except = next_except;
NEW_JUMP_TARGET_LABEL(c, handle_match);
if (i == 0) {
- /* Push the original EG into the stack */
+ /* create empty list for exceptions raised/reraise in the except* blocks */
/*
- [exc] COPY 1
- [orig, exc]
+ [orig] BUILD_LIST
*/
- ADDOP_I(c, loc, COPY, 1);
-
- /* create empty list for exceptions raised/reraise in the except* blocks */
+ /* Creat a copy of the original EG */
/*
- [orig, exc] BUILD_LIST
- [orig, exc, []] SWAP 2
+ [orig, []] COPY 2
[orig, [], exc]
*/
ADDOP_I(c, loc, BUILD_LIST, 0);
- ADDOP_I(c, loc, SWAP, 2);
+ ADDOP_I(c, loc, COPY, 2);
}
if (handler->v.ExceptHandler.type) {
VISIT(c, expr, handler->v.ExceptHandler.type);