From 5e547969f8e310b6090db0853186c2c03fd1023b Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 9 Feb 2005 21:24:51 +0000 Subject: Have set conversion replace existing constant if not used elsewhere. --- Python/compile.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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); -- cgit v0.12