File tree 1 file changed +2
-23
lines changed 1 file changed +2
-23
lines changed Original file line number Diff line number Diff line change @@ -221,7 +221,6 @@ static int PushNotificationType_init(PushNotificationObject *self, PyObject *arg
221
221
return PyList_Type .tp_init ((PyObject * )self , args , kwds );
222
222
}
223
223
224
- /* Create a new instance of PushNotificationType with preallocated number of elements */
225
224
static PyObject * PushNotificationType_New (Py_ssize_t size ) {
226
225
/* Check for negative size */
227
226
if (size < 0 ) {
@@ -240,28 +239,8 @@ static PyObject* PushNotificationType_New(Py_ssize_t size) {
240
239
return NULL ;
241
240
}
242
241
243
- /* Cast to PyListObject to access its fields */
244
- PyListObject * op = (PyListObject * )obj ;
245
-
246
- /* Allocate memory for the list items if size > 0 */
247
- if (size > 0 ) {
248
- size_t nbytes = (size_t )size * sizeof (PyObject * );
249
- op -> ob_item = (PyObject * * )PyMem_Malloc (nbytes );
250
- if (op -> ob_item == NULL ) {
251
- Py_DECREF (obj );
252
- return PyErr_NoMemory ();
253
- }
254
- /* Initialize memory to zeros */
255
- memset (op -> ob_item , 0 , nbytes );
256
- }
257
-
258
- /* Set the size and allocated fields */
259
- #if PY_VERSION_HEX >= 0x03090000
260
- Py_SET_SIZE (op , size );
261
- #else
262
- Py_SIZE (op ) = size ;
263
- #endif
264
- op -> allocated = size ;
242
+ // Simple solution to preallocate the list that works for both CPython and PyPy
243
+ PyList_SetSlice (obj , PY_SSIZE_T_MAX , PY_SSIZE_T_MAX , PyList_New (size ));
265
244
266
245
return obj ;
267
246
}
You can’t perform that action at this time.
0 commit comments