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

Skip to content

Commit 5e54796

Browse files
committed
Have set conversion replace existing constant if not used elsewhere.
1 parent 4d81ac9 commit 5e54796

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Python/compile.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,13 @@ try_set_conversion(unsigned char *codestr, PyObject *consts)
570570
return 0;
571571
}
572572

573-
/* Append new constant onto consts list.*/
573+
/* Append new constant onto consts list or replace existing constant
574+
if there are no other references to it.*/
575+
if (constant->ob_refcnt == 1) {
576+
PyList_SET_ITEM(consts, arg, newconst);
577+
Py_DECREF(constant);
578+
return 1;
579+
}
574580
len_consts = PyList_GET_SIZE(consts);
575581
if (PyList_Append(consts, newconst)) {
576582
Py_DECREF(newconst);

0 commit comments

Comments
 (0)