summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-02-09 21:24:51 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-02-09 21:24:51 (GMT)
commit5e547969f8e310b6090db0853186c2c03fd1023b (patch)
tree7e9f2009900044b6069847c1ae5914c72c5f4746 /Python/compile.c
parent4d81ac9ca80c301315d692a43e11afd5b9d1b871 (diff)
downloadcpython-5e547969f8e310b6090db0853186c2c03fd1023b.zip
cpython-5e547969f8e310b6090db0853186c2c03fd1023b.tar.gz
cpython-5e547969f8e310b6090db0853186c2c03fd1023b.tar.bz2
Have set conversion replace existing constant if not used elsewhere.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index dd58aa6..f90f82c 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -570,7 +570,13 @@ try_set_conversion(unsigned char *codestr, PyObject *consts)
return 0;
}
- /* Append new constant onto consts list.*/
+ /* Append new constant onto consts list or replace existing constant
+ if there are no other references to it.*/
+ if (constant->ob_refcnt == 1) {
+ PyList_SET_ITEM(consts, arg, newconst);
+ Py_DECREF(constant);
+ return 1;
+ }
len_consts = PyList_GET_SIZE(consts);
if (PyList_Append(consts, newconst)) {
Py_DECREF(newconst);