Skip to content

Commit 89b411f

Browse files
committed
Address code review
1 parent 5cd80db commit 89b411f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎Objects/listobject.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ ensure_shared_on_resize(PyListObject *self)
9393

9494
#define LIST_SMALL_ALLOCATED 32
9595

96+
Py_NO_INLINE static int py_list_resize(PyListObject *self, Py_ssize_t newsize);
97+
9698
/* Ensure ob_item has room for at least newsize elements, and set
9799
* ob_size to newsize. If newsize > ob_size on entry, the content
98100
* of the new slots at exit is undefined heap trash; it's the caller's
@@ -102,10 +104,9 @@ ensure_shared_on_resize(PyListObject *self)
102104
* Note that self->ob_item may change, and even if newsize is less
103105
* than ob_size on entry.
104106
*/
105-
static int
107+
static inline Py_ALWAYS_INLINE int
106108
list_resize(PyListObject *self, Py_ssize_t newsize)
107109
{
108-
size_t new_allocated, target_bytes;
109110
Py_ssize_t allocated = self->allocated;
110111

111112
/* Bypass realloc() when a previous overallocation is large enough
@@ -121,6 +122,14 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
121122
Py_SET_SIZE(self, newsize);
122123
return 0;
123124
}
125+
return py_list_resize(self, newsize);
126+
}
127+
128+
Py_NO_INLINE static int
129+
py_list_resize(PyListObject *self, Py_ssize_t newsize)
130+
{
131+
size_t new_allocated, target_bytes;
132+
Py_ssize_t allocated = self->allocated;
124133

125134
/* This over-allocates proportional to the list size, making room
126135
* for additional growth. The over-allocation is mild, but is

0 commit comments

Comments
 (0)