Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 747596a

Browse files
committed
When a recycled frame has more local+stack slots than needed,
give the extra slots to the stack rather than than forgetting about them (this reduces the number of reallocs done).
1 parent 463e55a commit 747596a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Objects/frameobject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ newframeobject(back, code, globals, locals)
172172
if (f == NULL)
173173
return (PyFrameObject *)err_nomem();
174174
}
175+
else
176+
extras = f->f_nlocals + f->f_stacksize;
175177
f->ob_type = &Frametype;
176178
NEWREF(f);
177179
}
@@ -203,11 +205,11 @@ newframeobject(back, code, globals, locals)
203205
f->f_trace = NULL;
204206

205207
f->f_lasti = 0;
206-
f->f_lineno = -1;
208+
f->f_lineno = code->co_firstlineno;
207209
f->f_restricted = (builtins != getbuiltindict());
208210
f->f_iblock = 0;
209211
f->f_nlocals = code->co_nlocals;
210-
f->f_stacksize = code->co_stacksize;
212+
f->f_stacksize = extras - code->co_nlocals;
211213

212214
while (--extras >= 0)
213215
f->f_localsplus[extras] = NULL;

0 commit comments

Comments
 (0)