Skip to content

Commit 8d7c6dc

Browse files
authored
gh-150942: Optimize PicklerMemoProxy.copy() with _PyDict_SetItem_Take2 (gh-151608)
1 parent a8d74c0 commit 8d7c6dc

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

Modules/_pickle.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "pycore_bytesobject.h" // _PyBytesWriter
1313
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
1414
#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION()
15+
#include "pycore_dict.h" // _PyDict_SetItem_Take2()
1516
#include "pycore_long.h" // _PyLong_AsByteArray()
1617
#include "pycore_moduleobject.h" // _PyModule_GetState()
1718
#include "pycore_object.h" // _PyNone_Type
@@ -5147,9 +5148,7 @@ _pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self)
51475148
Py_DECREF(key);
51485149
goto error;
51495150
}
5150-
status = PyDict_SetItem(new_memo, key, value);
5151-
Py_DECREF(key);
5152-
Py_DECREF(value);
5151+
status = _PyDict_SetItem_Take2((PyDictObject *)new_memo, key, value);
51535152
if (status < 0)
51545153
goto error;
51555154
}

0 commit comments

Comments
 (0)