Skip to content

Commit cbe3a7f

Browse files
authored
gh-150942: Speed up re.split result building (gh-155940)
1 parent c3df37c commit cbe3a7f

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

Modules/_sre/sre.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,7 @@ _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
12731273
);
12741274
if (!item)
12751275
goto error;
1276-
status = PyList_Append(list, item);
1277-
Py_DECREF(item);
1276+
status = _PyList_AppendTakeRef((PyListObject *)list, item);
12781277
if (status < 0)
12791278
goto error;
12801279

@@ -1283,8 +1282,7 @@ _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
12831282
item = state_getslice(&state, i+1, string, 0);
12841283
if (!item)
12851284
goto error;
1286-
status = PyList_Append(list, item);
1287-
Py_DECREF(item);
1285+
status = _PyList_AppendTakeRef((PyListObject *)list, item);
12881286
if (status < 0)
12891287
goto error;
12901288
}
@@ -1301,8 +1299,7 @@ _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
13011299
);
13021300
if (!item)
13031301
goto error;
1304-
status = PyList_Append(list, item);
1305-
Py_DECREF(item);
1302+
status = _PyList_AppendTakeRef((PyListObject *)list, item);
13061303
if (status < 0)
13071304
goto error;
13081305

0 commit comments

Comments
 (0)