summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-12-18 21:24:09 +0000
committerRaymond Hettinger <python@rcn.com>2007-12-18 21:24:09 +0000
commitfd7ed407d79b797e20d0a6fe69e18f9ba9354979 (patch)
tree3dc9abccf69e49db5c98aa0805dcbaab50fc90c3 /Python/compile.c
parent3c887b2802e1b44b7e33cd14329541d0d22769d7 (diff)
downloadcpython-git-fd7ed407d79b797e20d0a6fe69e18f9ba9354979.tar.gz
Give meaning to the oparg for BUILD_MAP: estimated size of the dictionary.
Allows dictionaries to be pre-sized (upto 255 elements) saving time lost to re-sizes with their attendant mallocs and re-insertions. Has zero effect on small dictionaries (5 elements or fewer), a slight benefit for dicts upto 22 elements (because they had to resize once anyway), and more benefit for dicts upto 255 elements (saving multiple resizes during the build-up and reducing the number of collisions on the first insertions). Beyond 255 elements, there is no addional benefit.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 3b0c53fb19..36ad8a48e0 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2922,11 +2922,9 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
case IfExp_kind:
return compiler_ifexp(c, e);
case Dict_kind:
- /* XXX get rid of arg? */
- ADDOP_I(c, BUILD_MAP, 0);
n = asdl_seq_LEN(e->v.Dict.values);
- /* We must arrange things just right for STORE_SUBSCR.
- It wants the stack to look like (value) (dict) (key) */
+ ADDOP_I(c, BUILD_MAP, (n>255 ? 255 : n));
+ n = asdl_seq_LEN(e->v.Dict.values);
for (i = 0; i < n; i++) {
VISIT(c, expr,
(expr_ty)asdl_seq_GET(e->v.Dict.values, i));