@@ -20,30 +20,45 @@ extern void _PyTuple_Fini(PyInterpreterState *);
20
20
21
21
/* other API */
22
22
23
- #ifndef WITH_FREELISTS
24
- // without freelists
25
- // for tuples only store empty tuple singleton
26
- # define PyTuple_MAXSAVESIZE 1
27
- # define PyTuple_MAXFREELIST 1
28
- #endif
23
+ // PyTuple_MAXSAVESIZE - largest tuple to save on free list
24
+ // PyTuple_MAXFREELIST - maximum number of tuples of each size to save
29
25
30
- /* Speed optimization to avoid frequent malloc/free of small tuples */
31
- #ifndef PyTuple_MAXSAVESIZE
32
- // Largest tuple to save on free list
33
- # define PyTuple_MAXSAVESIZE 20
34
- #endif
35
- #ifndef PyTuple_MAXFREELIST
36
- // Maximum number of tuples of each size to save
37
- # define PyTuple_MAXFREELIST 2000
26
+ #if defined(PyTuple_MAXSAVESIZE ) && PyTuple_MAXSAVESIZE <= 0
27
+ // A build indicated that tuple freelists should not be used.
28
+ # define PyTuple_NFREELISTS 0
29
+ # undef PyTuple_MAXSAVESIZE
30
+ # undef PyTuple_MAXFREELIST
31
+
32
+ #elif !defined(WITH_FREELISTS )
33
+ # define PyTuple_NFREELISTS 0
34
+ # undef PyTuple_MAXSAVESIZE
35
+ # undef PyTuple_MAXFREELIST
36
+
37
+ #else
38
+ // We are using a freelist for tuples.
39
+ # ifndef PyTuple_MAXSAVESIZE
40
+ # define PyTuple_MAXSAVESIZE 20
41
+ # endif
42
+ # define PyTuple_NFREELISTS PyTuple_MAXSAVESIZE
43
+ # ifndef PyTuple_MAXFREELIST
44
+ # define PyTuple_MAXFREELIST 2000
45
+ # endif
38
46
#endif
39
47
40
48
struct _Py_tuple_state {
41
- #if PyTuple_MAXSAVESIZE > 0
42
- /* Entries 1 up to PyTuple_MAXSAVESIZE are free lists,
43
- entry 0 is the empty tuple () of which at most one instance
44
- will be allocated. */
45
- PyTupleObject * free_list [PyTuple_MAXSAVESIZE ];
46
- int numfree [PyTuple_MAXSAVESIZE ];
49
+ #if PyTuple_NFREELISTS > 0
50
+ /* There is one freelist for each size from 1 to PyTuple_MAXSAVESIZE.
51
+ The empty tuple is handled separately.
52
+
53
+ Each tuple stored in the array is the head of the linked list
54
+ (and the next available tuple) for that size. The actual tuple
55
+ object is used as the linked list node, with its first item
56
+ (ob_item[0]) pointing to the next node (i.e. the previous head).
57
6AAF
+ Each linked list is initially NULL. */
58
+ PyTupleObject * free_list [PyTuple_NFREELISTS ];
59
+ int numfree [PyTuple_NFREELISTS ];
60
+ #else
61
+ char _unused ; // Empty structs are not allowed.
47
62
#endif
48
63
};
49
64
0 commit comments