@@ -31,12 +31,12 @@ get_list_freelist(void)
31
31
}
32
32
#endif
33
33
34
+ #ifdef Py_GIL_DISABLED
34
35
static size_t
35
36
list_good_size (Py_ssize_t size )
36
37
{
37
38
// 4, 8, 16, 24, 32, 40, 48, 64, 80, ...
38
39
// NOTE: we add one here so that the rounding accounts for the "allocated"
39
- // field in _PyListArray.
40
40
size_t reqsize = (size_t )size + 1 ;
41
41
if (reqsize <= 4 ) {
42
42
reqsize = 4 ;
@@ -67,6 +67,7 @@ list_allocate_items(size_t capacity)
67
67
PyObject * * items = PyMem_Malloc (capacity * sizeof (PyObject * ));
68
68
return items ;
69
69
}
70
+ #endif
70
71
71
72
static PyListObject *
72
73
list_new (Py_ssize_t size )
@@ -699,7 +700,7 @@ list_repeat(PyObject *aa, Py_ssize_t n)
699
700
}
700
701
701
702
static void
702
- list_clear (PyListObject * a )
703
+ list_clear_impl (PyListObject * a , bool is_resize )
703
704
{
704
705
PyObject * * items = a -> ob_item ;
705
706
if (items == NULL ) {
@@ -716,16 +717,31 @@ list_clear(PyListObject *a)
716
717
Py_XDECREF (items [i ]);
717
718
}
718
719
// TODO: Use QSBR technique, if the list is shared between threads,
719
- PyMem_Free (items );
720
-
720
+ #ifdef Py_GIL_DISABLED
721
+ bool use_qsbr = is_resize && _PyObject_GC_IS_SHARED (a );
722
+ #else
723
+ bool use_qsbr = false;
724
+ #endif
725
+ if (use_qsbr ) {
726
+ _PyMem_FreeDelayed (items );
727
+ }
728
+ else {
729
+ PyMem_Free (items );
730
+ }
721
731
// Note that there is no guarantee that the list is actually empty
722
732
// at this point, because XDECREF may have populated it indirectly again!
723
733
}
724
734
735
+ static void
736
+ list_clear (PyListObject * a )
737
+ {
738
+ list_clear_impl (a , true);
739
+ }
740
+
725
741
static int
726
742
list_clear_slot (PyObject * self )
727
743
{
728
- list_clear ((PyListObject * )self );
744
+ list_clear_impl ((PyListObject * )self , false );
729
745
return 0 ;
730
746
}
731
747
0 commit comments