@@ -46,6 +46,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4646#include "pycore_codecs.h" // _PyCodec_Lookup()
4747#include "pycore_critical_section.h" // Py_*_CRITICAL_SECTION_SEQUENCE_FAST
4848#include "pycore_format.h" // F_LJUST
49+ #include "pycore_freelist.h" // _Py_FREELIST_FREE(), _Py_FREELIST_POP()
4950#include "pycore_initconfig.h" // _PyStatus_OK()
5051#include "pycore_interp.h" // PyInterpreterState.fs_codec
5152#include "pycore_long.h" // _PyLong_FormatWriter()
@@ -13436,9 +13437,13 @@ PyUnicodeWriter_Create(Py_ssize_t length)
1343613437 }
1343713438
1343813439 const size_t size = sizeof (_PyUnicodeWriter );
13439- PyUnicodeWriter * pub_writer = (PyUnicodeWriter * )PyMem_Malloc (size );
13440+ PyUnicodeWriter * pub_writer ;
13441+ pub_writer = _Py_FREELIST_POP_MEM (unicode_writers );
1344013442 if (pub_writer == NULL ) {
13441- return (PyUnicodeWriter * )PyErr_NoMemory ();
13443+ pub_writer = (PyUnicodeWriter * )PyMem_Malloc (size );
13444+ if (pub_writer == NULL ) {
13445+ return (PyUnicodeWriter * )PyErr_NoMemory ();
13446+ }
1344213447 }
1344313448 _PyUnicodeWriter * writer = (_PyUnicodeWriter * )pub_writer ;
1344413449
@@ -13459,7 +13464,7 @@ void PyUnicodeWriter_Discard(PyUnicodeWriter *writer)
1345913464 return ;
1346013465 }
1346113466 _PyUnicodeWriter_Dealloc ((_PyUnicodeWriter * )writer );
13462- PyMem_Free ( writer );
13467+ _Py_FREELIST_FREE ( unicode_writers , writer , PyMem_Free );
1346313468}
1346413469
1346513470
@@ -13881,7 +13886,7 @@ PyUnicodeWriter_Finish(PyUnicodeWriter *writer)
1388113886{
1388213887 PyObject * str = _PyUnicodeWriter_Finish ((_PyUnicodeWriter * )writer );
1388313888 assert (((_PyUnicodeWriter * )writer )-> buffer == NULL );
13884- PyMem_Free ( writer );
13889+ _Py_FREELIST_FREE ( unicode_writers , writer , PyMem_Free );
1388513890 return str ;
1388613891}
1388713892
0 commit comments