From 8ac090f759e265ff5346cd81b7629c0c93d77bff Mon Sep 17 00:00:00 2001 From: Timofey Ivankov Date: Tue, 9 Jun 2026 23:07:51 +0300 Subject: [PATCH 1/2] gh-150942: Speed up ElementTree attribute parsing --- .../Library/2026-06-09-23-04-44.gh-issue-150942.Iu583J.rst | 2 ++ Modules/_elementtree.c | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-06-09-23-04-44.gh-issue-150942.Iu583J.rst diff --git a/Misc/NEWS.d/next/Library/2026-06-09-23-04-44.gh-issue-150942.Iu583J.rst b/Misc/NEWS.d/next/Library/2026-06-09-23-04-44.gh-issue-150942.Iu583J.rst new file mode 100644 index 000000000000000..7376e73f41dcf79 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-09-23-04-44.gh-issue-150942.Iu583J.rst @@ -0,0 +1,2 @@ +Speed up :mod:`xml.etree.ElementTree` parsing of element attributes by using +reference-stealing dict insertion. diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 9e794be5c109ba5..70ed35cca19e800 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -3343,9 +3343,7 @@ expat_start_handler(void *op, const XML_Char *tag_in, Py_DECREF(tag); return; } - ok = PyDict_SetItem(attrib, key, value); - Py_DECREF(value); - Py_DECREF(key); + ok = _PyDict_SetItem_Take2((PyDictObject *)attrib, key, value); if (ok < 0) { Py_DECREF(attrib); Py_DECREF(tag); From 09b5284f7ff6d9e19e65b2dee996e54ae6a7b776 Mon Sep 17 00:00:00 2001 From: Timofey Ivankov Date: Tue, 9 Jun 2026 23:32:05 +0300 Subject: [PATCH 2/2] Remove news entry --- .../next/Library/2026-06-09-23-04-44.gh-issue-150942.Iu583J.rst | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2026-06-09-23-04-44.gh-issue-150942.Iu583J.rst diff --git a/Misc/NEWS.d/next/Library/2026-06-09-23-04-44.gh-issue-150942.Iu583J.rst b/Misc/NEWS.d/next/Library/2026-06-09-23-04-44.gh-issue-150942.Iu583J.rst deleted file mode 100644 index 7376e73f41dcf79..000000000000000 --- a/Misc/NEWS.d/next/Library/2026-06-09-23-04-44.gh-issue-150942.Iu583J.rst +++ /dev/null @@ -1,2 +0,0 @@ -Speed up :mod:`xml.etree.ElementTree` parsing of element attributes by using -reference-stealing dict insertion.