From 11e4a58fe03c8988c4001dad0dc0c875b5da69b6 Mon Sep 17 00:00:00 2001 From: Punisheroot <44579963+Punisheroot@users.noreply.github.com> Date: Wed, 29 Jul 2026 10:45:03 +0200 Subject: [PATCH] gh-150942: Speed up pyexpat attribute parsing --- Modules/pyexpat.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index f9e7e057f7e0f7b..77fbcd327a40dce 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -5,6 +5,7 @@ #include "Python.h" #include "pycore_ceval.h" // _Py_EnterRecursiveCall() #include "pycore_codecs.h" // _PyCodec_LookupTextEncoding() +#include "pycore_dict.h" // _PyDict_SetItem_Take2() #include "pycore_import.h" // _PyImport_SetModule() #include "pycore_pyhash.h" // _Py_HashSecret #include "pycore_traceback.h" // _PyTraceback_Add() @@ -469,17 +470,11 @@ my_StartElementHandler(void *userData, PyList_SET_ITEM(container, i, n); PyList_SET_ITEM(container, i+1, v); } - else if (PyDict_SetItem(container, n, v)) { + else if (_PyDict_SetItem_Take2((PyDictObject *)container, n, v)) { flag_error(self); - Py_DECREF(n); - Py_DECREF(v); Py_DECREF(container); return; } - else { - Py_DECREF(n); - Py_DECREF(v); - } } args = string_intern(self, name); if (args == NULL) {