File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,14 +62,14 @@ impl fmt::Debug for PyDict {
6262 }
6363}
6464
65- // spell-checker:ignore MAXFREELIST
66- const PYDICT_MAXFREELIST : usize = 80 ;
67-
6865thread_local ! {
6966 static DICT_FREELIST : Cell <Vec <* mut PyObject >> = const { Cell :: new( Vec :: new( ) ) } ;
7067}
7168
7269impl PyPayload for PyDict {
70+ // spell-checker:ignore MAXFREELIST
71+ /// PyDict_MAXFREELIST
72+ const MAX_FREELIST : usize = 80 ;
7373 const HAS_FREELIST : bool = true ;
7474
7575 #[ inline]
@@ -81,7 +81,7 @@ impl PyPayload for PyDict {
8181 unsafe fn freelist_push ( obj : * mut PyObject ) -> bool {
8282 DICT_FREELIST . with ( |fl| {
8383 let mut list = fl. take ( ) ;
84- let stored = if list. len ( ) < PYDICT_MAXFREELIST {
84+ let stored = if list. len ( ) < Self :: MAX_FREELIST {
8585 list. push ( obj) ;
8686 true
8787 } else {
Original file line number Diff line number Diff line change @@ -34,14 +34,14 @@ impl PyFloat {
3434 }
3535}
3636
37- // spell-checker:ignore MAXFREELIST
38- const PYFLOAT_MAXFREELIST : usize = 100 ;
39-
4037thread_local ! {
4138 static FLOAT_FREELIST : Cell <Vec <* mut PyObject >> = const { Cell :: new( Vec :: new( ) ) } ;
4239}
4340
4441impl PyPayload for PyFloat {
42+ // spell-checker:ignore MAXFREELIST
43+ /// PyFloat_MAXFREELIST
44+ const MAX_FREELIST : usize = 100 ;
4545 const HAS_FREELIST : bool = true ;
4646
4747 #[ inline]
@@ -53,7 +53,7 @@ impl PyPayload for PyFloat {
5353 unsafe fn freelist_push ( obj : * mut PyObject ) -> bool {
5454 FLOAT_FREELIST . with ( |fl| {
5555 let mut list = fl. take ( ) ;
56- let stored = if list. len ( ) < PYFLOAT_MAXFREELIST {
56+ let stored = if list. len ( ) < Self :: MAX_FREELIST {
5757 list. push ( obj) ;
5858 true
5959 } else {
Original file line number Diff line number Diff line change @@ -74,14 +74,14 @@ unsafe impl Traverse for PyList {
7474 }
7575}
7676
77- // spell-checker:ignore MAXFREELIST
78- const PYLIST_MAXFREELIST : usize = 80 ;
79-
8077thread_local ! {
8178 static LIST_FREELIST : Cell <Vec <* mut PyObject >> = const { Cell :: new( Vec :: new( ) ) } ;
8279}
8380
8481impl PyPayload for PyList {
82+ // spell-checker:ignore MAXFREELIST
83+ /// PyList_MAXFREELIST
84+ const MAX_FREELIST : usize = 80 ;
8585 const HAS_FREELIST : bool = true ;
8686
8787 #[ inline]
@@ -93,7 +93,7 @@ impl PyPayload for PyList {
9393 unsafe fn freelist_push ( obj : * mut PyObject ) -> bool {
9494 LIST_FREELIST . with ( |fl| {
9595 let mut list = fl. take ( ) ;
96- let stored = if list. len ( ) < PYLIST_MAXFREELIST {
96+ let stored = if list. len ( ) < Self :: MAX_FREELIST {
9797 list. push ( obj) ;
9898 true
9999 } else {
Original file line number Diff line number Diff line change @@ -25,15 +25,14 @@ pub struct PySlice {
2525 pub step : Option < PyObjectRef > ,
2626}
2727
28- // spell-checker:ignore MAXFREELIST
29- // PySlice_MAXFREELIST = 1
30- const PYSLICE_MAXFREELIST : usize = 1 ;
31-
3228thread_local ! {
3329 static SLICE_FREELIST : Cell <Vec <* mut PyObject >> = const { Cell :: new( Vec :: new( ) ) } ;
3430}
3531
3632impl PyPayload for PySlice {
33+ // spell-checker:ignore MAXFREELIST
34+ /// PySlice_MAXFREELIST
35+ const MAX_FREELIST : usize = 1 ;
3736 const HAS_FREELIST : bool = true ;
3837
3938 #[ inline]
@@ -45,7 +44,7 @@ impl PyPayload for PySlice {
4544 unsafe fn freelist_push ( obj : * mut PyObject ) -> bool {
4645 SLICE_FREELIST . with ( |fl| {
4746 let mut list = fl. take ( ) ;
48- let stored = if list. len ( ) < PYSLICE_MAXFREELIST {
47+ let stored = if list. len ( ) < Self :: MAX_FREELIST {
4948 list. push ( obj) ;
5049 true
5150 } else {
Original file line number Diff line number Diff line change @@ -52,6 +52,9 @@ pub trait PyPayload: MaybeTraverse + PyThreadingConstraint + Sized + 'static {
5252 /// race conditions when the object is reused.
5353 const HAS_FREELIST : bool = false ;
5454
55+ /// Maximum number of objects to keep in the freelist.
56+ const MAX_FREELIST : usize = 0 ;
57+
5558 /// Try to push a dead object onto this type's freelist for reuse.
5659 /// Returns true if the object was stored (caller must NOT free the memory).
5760 ///
You can’t perform that action at this time.
0 commit comments