From 7945e6107b964bae6467d3275feffa2924d01b28 Mon Sep 17 00:00:00 2001 From: Omkar Kabde Date: Sat, 6 Jun 2026 07:22:37 +0530 Subject: [PATCH 1/2] gh-150942: Speed up csv.reader row building --- .../Library/2026-06-05-12-00-00.gh-issue-150942.Hkdh87.rst | 3 +++ Modules/_csv.c | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-06-05-12-00-00.gh-issue-150942.Hkdh87.rst diff --git a/Misc/NEWS.d/next/Library/2026-06-05-12-00-00.gh-issue-150942.Hkdh87.rst b/Misc/NEWS.d/next/Library/2026-06-05-12-00-00.gh-issue-150942.Hkdh87.rst new file mode 100644 index 000000000000000..fbbd16900200ca5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-05-12-00-00.gh-issue-150942.Hkdh87.rst @@ -0,0 +1,3 @@ +Speed up :func:`csv.reader` by appending parsed fields to the output row +without an extra reference-count round-trip (using the internal +reference-stealing list append helper). diff --git a/Modules/_csv.c b/Modules/_csv.c index a7fcc78e058f058..118c96be7911e4c 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -14,6 +14,7 @@ module instead. #endif #include "Python.h" +#include "pycore_list.h" // _PyList_AppendTakeRef() #include "pycore_pyatomic_ft_wrappers.h" #include // offsetof() @@ -685,11 +686,9 @@ parse_save_field(ReaderObj *self) } self->field_len = 0; } - if (PyList_Append(self->fields, field) < 0) { - Py_DECREF(field); + if (_PyList_AppendTakeRef((PyListObject *)self->fields, field) < 0) { return -1; } - Py_DECREF(field); return 0; } From ed09daca6aab6d8909ff2e2d92f92d14c3537fb4 Mon Sep 17 00:00:00 2001 From: Omkar Kabde Date: Sat, 6 Jun 2026 12:30:32 +0530 Subject: [PATCH 2/2] add patch contributor name --- .../next/Library/2026-06-05-12-00-00.gh-issue-150942.Hkdh87.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-06-05-12-00-00.gh-issue-150942.Hkdh87.rst b/Misc/NEWS.d/next/Library/2026-06-05-12-00-00.gh-issue-150942.Hkdh87.rst index fbbd16900200ca5..dd27f6f2616f16b 100644 --- a/Misc/NEWS.d/next/Library/2026-06-05-12-00-00.gh-issue-150942.Hkdh87.rst +++ b/Misc/NEWS.d/next/Library/2026-06-05-12-00-00.gh-issue-150942.Hkdh87.rst @@ -1,3 +1,3 @@ Speed up :func:`csv.reader` by appending parsed fields to the output row without an extra reference-count round-trip (using the internal -reference-stealing list append helper). +reference-stealing list append helper). Patch by Omkar Kabde.