diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2008-03-07 14:13:28 +0000 |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2008-03-07 14:13:28 +0000 |
commit | 7af53be66f8c074902e0e7e7c452a280538582bc (patch) | |
tree | c2d5933745c44a5099ceadb4f81bc7aa82dfe1c1 /Python/compile.c | |
parent | e75f59a578a4538451c1d96610a6d183ba8f2e81 (diff) | |
download | cpython-git-7af53be66f8c074902e0e7e7c452a280538582bc.tar.gz |
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/Python/compile.c b/Python/compile.c index d81fef3002..43b7569e62 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2842,7 +2842,7 @@ compiler_with(struct compiler *c, stmt_ty s) { static identifier enter_attr, exit_attr; basicblock *block, *finally; - identifier tmpexit, tmpvalue = NULL; + identifier tmpvalue = NULL; assert(s->kind == With_kind); @@ -2862,12 +2862,6 @@ compiler_with(struct compiler *c, stmt_ty s) if (!block || !finally) return 0; - /* Create a temporary variable to hold context.__exit__ */ - tmpexit = compiler_new_tmpname(c); - if (tmpexit == NULL) - return 0; - PyArena_AddPyObject(c->c_arena, tmpexit); - if (s->v.With.optional_vars) { /* Create a temporary variable to hold context.__enter__(). We need to do this rather than preserving it on the stack @@ -2887,11 +2881,10 @@ compiler_with(struct compiler *c, stmt_ty s) /* Evaluate EXPR */ VISIT(c, expr, s->v.With.context_expr); - /* Squirrel away context.__exit__ */ + /* Squirrel away context.__exit__ by stuffing it under context */ ADDOP(c, DUP_TOP); ADDOP_O(c, LOAD_ATTR, exit_attr, names); - if (!compiler_nameop(c, tmpexit, Store)) - return 0; + ADDOP(c, ROT_TWO); /* Call context.__enter__() */ ADDOP_O(c, LOAD_ATTR, enter_attr, names); @@ -2935,10 +2928,9 @@ compiler_with(struct compiler *c, stmt_ty s) if (!compiler_push_fblock(c, FINALLY_END, finally)) return 0; - /* Finally block starts; push tmpexit and issue our magic opcode. */ - if (!compiler_nameop(c, tmpexit, Load) || - !compiler_nameop(c, tmpexit, Del)) - return 0; + /* Finally block starts; context.__exit__ is on the stack under + the exception or return information. Just issue our magic + opcode. */ ADDOP(c, WITH_CLEANUP); /* Finally block ends. */ |