mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
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)
This commit is contained in:
parent
e75f59a578
commit
7af53be66f
6 changed files with 77 additions and 55 deletions
|
@ -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. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue