Skip to content

Commit a2bfdd6

Browse files
committed
gh-150942: Improve performance of csv reader by using _PyList_AppendTakeRef
1 parent 7fb315b commit a2bfdd6

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve performance of ``csv`` reader by using ``_PyList_AppendTakeRef`` internally.

Modules/_csv.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module instead.
1515

1616
#include "Python.h"
1717
#include "pycore_pyatomic_ft_wrappers.h"
18+
#include "pycore_list.h"
1819

1920
#include <stddef.h> // offsetof()
2021
#include <stdbool.h>
@@ -685,11 +686,9 @@ parse_save_field(ReaderObj *self)
685686
}
686687
self->field_len = 0;
687688
}
688-
if (PyList_Append(self->fields, field) < 0) {
689-
Py_DECREF(field);
689+
if (_PyList_AppendTakeRef((PyListObject *)self->fields, field) < 0) {
690690
return -1;
691691
}
692-
Py_DECREF(field);
693692
return 0;
694693
}
695694

0 commit comments

Comments
 (0)