gh-150942: Speed up re.split result building (gh-155940)

corona10 <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/cbe3a7f06a38c7fdda2d53183294499e533a3a0c
commit: cbe3a7f06a38c7fdda2d53183294499e533a3a0c
branch: main
author: Sangmin Lee <[email protected]>
committer: corona10 <[email protected]>
date: 2026-08-17T07:26:30Z
summary:

gh-150942: Speed up re.split result building (gh-155940)

files:
M Modules/_sre/sre.c

diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c
index e742a25e4891fce..031e972aeba0312 100644
--- a/Modules/_sre/sre.c
+++ b/Modules/_sre/sre.c
@@ -1273,8 +1273,7 @@ _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
             );
         if (!item)
             goto error;
-        status = PyList_Append(list, item);
-        Py_DECREF(item);
+        status = _PyList_AppendTakeRef((PyListObject *)list, item);
         if (status < 0)
             goto error;
 
@@ -1283,8 +1282,7 @@ _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
             item = state_getslice(&state, i+1, string, 0);
             if (!item)
                 goto error;
-            status = PyList_Append(list, item);
-            Py_DECREF(item);
+            status = _PyList_AppendTakeRef((PyListObject *)list, item);
             if (status < 0)
                 goto error;
         }
@@ -1301,8 +1299,7 @@ _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
         );
     if (!item)
         goto error;
-    status = PyList_Append(list, item);
-    Py_DECREF(item);
+    status = _PyList_AppendTakeRef((PyListObject *)list, item);
     if (status < 0)
         goto error;
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.