Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions Objects/stringlib/split.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#error must include "stringlib/fastsearch.h" before including this module
#endif

#include "pycore_list.h" // _PyList_AppendTakeRef()

/* Overallocate the initial list to reduce the number of reallocs for small
split sizes. Eg, "A A A A A A A A A A".split() (10 elements) has three
resizes, to sizes 4, 8, then 16. Most observed string splits are for human
Expand All @@ -22,12 +24,8 @@
(right) - (left)); \
if (sub == NULL) \
goto onError; \
if (PyList_Append(list, sub)) { \
Py_DECREF(sub); \
goto onError; \
} \
else \
Py_DECREF(sub);
if (_PyList_AppendTakeRef((PyListObject *)list, sub)) \
goto onError;

#define SPLIT_ADD(data, left, right) { \
sub = STRINGLIB_NEW((data) + (left), \
Expand All @@ -37,12 +35,8 @@
if (count < MAX_PREALLOC) { \
PyList_SET_ITEM(list, count, sub); \
} else { \
if (PyList_Append(list, sub)) { \
Py_DECREF(sub); \
if (_PyList_AppendTakeRef((PyListObject *)list, sub)) \
goto onError; \
} \
else \
Py_DECREF(sub); \
} \
count++; }

Expand Down
Loading