Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Include/symtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ typedef struct _symtable_entry {
int ste_col_offset; /* offset of first line of block */
int ste_opt_lineno; /* lineno of last exec or import * */
int ste_opt_col_offset; /* offset of last exec or import * */
int ste_tmpname; /* counter for listcomp temp vars */
struct symtable *ste_table;
} PySTEntryObject;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't use temporary variables in cases of list/dict/set comprehensions
25 changes: 0 additions & 25 deletions Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
ste->ste_varkeywords = 0;
ste->ste_opt_lineno = 0;
ste->ste_opt_col_offset = 0;
ste->ste_tmpname = 0;
ste->ste_lineno = lineno;
ste->ste_col_offset = col_offset;

Expand Down Expand Up @@ -1082,24 +1081,6 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag)
} \
}

static int
symtable_new_tmpname(struct symtable *st)
{
char tmpname[256];
identifier tmp;

PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
++st->st_cur->ste_tmpname);
tmp = PyUnicode_InternFromString(tmpname);
if (!tmp)
return 0;
if (!symtable_add_def(st, tmp, DEF_LOCAL))
return 0;
Py_DECREF(tmp);
return 1;
}


static int
symtable_record_directive(struct symtable *st, identifier name, stmt_ty s)
{
Expand Down Expand Up @@ -1723,7 +1704,6 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
expr_ty elt, expr_ty value)
{
int is_generator = (e->kind == GeneratorExp_kind);
int needs_tmp = !is_generator;
comprehension_ty outermost = ((comprehension_ty)
asdl_seq_GET(generators, 0));
/* Outermost iterator is evaluated in current scope */
Expand All @@ -1742,11 +1722,6 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
symtable_exit_block(st, (void *)e);
return 0;
}
/* Allocate temporary name if needed */
if (needs_tmp && !symtable_new_tmpname(st)) {
symtable_exit_block(st, (void *)e);
return 0;
}
VISIT(st, expr, outermost->target);
VISIT_SEQ(st, expr, outermost->ifs);
VISIT_SEQ_TAIL(st, comprehension, generators, 1);
Expand Down