summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2008-03-07 14:13:28 +0000
committerNick Coghlan <ncoghlan@gmail.com>2008-03-07 14:13:28 +0000
commitd9cc685a7ba7e6f8f75de99e1c25e4c982abe5c0 (patch)
treef7ee24cc7404717646097a0316c571c7898375a7 /Python/compile.c
parent000f926094f5cea2db1902b4a2971bb0c6592873 (diff)
downloadcpython-d9cc685a7ba7e6f8f75de99e1c25e4c982abe5c0.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.c20
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. */