From 13527123a100f4cd8620473ae8da4cb727279866 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 11 Nov 2016 04:31:18 -0800 Subject: [PATCH] Issue #28665: Harmonize STORE_DEREF with STORE_FAST and LOAD_DEREF giving a 40% speedup. --- Misc/NEWS | 2 ++ Python/ceval.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index cb244f3a352..24810f05600 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,8 @@ Core and Builtins - Issue #19398: Extra slash no longer added to sys.path components in case of empty compile-time PYTHONPATH components. +- Issue #28665: Improve speed of the STORE_DEREF opcode by 40%. + - Issue #28583: PyDict_SetDefault didn't combine split table when needed. Patch by Xiang Zhang. diff --git a/Python/ceval.c b/Python/ceval.c index b2c90cc3b48..6bdc9983e3f 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2462,8 +2462,9 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) TARGET(STORE_DEREF) { PyObject *v = POP(); PyObject *cell = freevars[oparg]; - PyCell_Set(cell, v); - Py_DECREF(v); + PyObject *oldobj = PyCell_GET(cell); + PyCell_SET(cell, v); + Py_XDECREF(oldobj); DISPATCH(); }