--- /dev/null
+Speed up :func:`re.findall`, :func:`re.sub` and :func:`re.subn` by appending
+result items to the output list without an extra reference-count round-trip
+(using the internal reference-stealing list append helper).
#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION
#include "pycore_dict.h" // _PyDict_Next()
#include "pycore_long.h" // _PyLong_GetZero()
+#include "pycore_list.h" // _PyList_AppendTakeRef()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_tuple.h" // _PyTuple_FromPairSteal
#include "pycore_unicodeobject.h" // _PyUnicode_Copy
break;
}
- status = PyList_Append(list, item);
- Py_DECREF(item);
+ status = _PyList_AppendTakeRef((PyListObject *)list, item);
if (status < 0)
goto error;
string, i, b);
if (!item)
goto error;
- status = PyList_Append(list, item);
- Py_DECREF(item);
+ status = _PyList_AppendTakeRef((PyListObject *)list, item);
if (status < 0)
goto error;
/* add to list */
if (item != Py_None) {
- status = PyList_Append(list, item);
- Py_DECREF(item);
+ status = _PyList_AppendTakeRef((PyListObject *)list, item);
if (status < 0)
goto error;
}
string, i, state.endpos);
if (!item)
goto error;
- status = PyList_Append(list, item);
- Py_DECREF(item);
+ status = _PyList_AppendTakeRef((PyListObject *)list, item);
if (status < 0)
goto error;
}