Skip to content

Commit 3404db8

Browse files
committed
Address code review
1 parent dd855fd commit 3404db8

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎Objects/listobject.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ 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);
96+
static int py_list_resize(PyListObject *self, Py_ssize_t newsize);
9797

9898
/* Ensure ob_item has room for at least newsize elements, and set
9999
* ob_size to newsize. If newsize > ob_size on entry, the content
@@ -103,6 +103,10 @@ Py_NO_INLINE static int py_list_resize(PyListObject *self, Py_ssize_t newsize);
103103
* Failure is impossible if newsize <= self.allocated on entry.
104104
* Note that self->ob_item may change, and even if newsize is less
105105
* than ob_size on entry.
106+
*
107+
* list_resize() only handles the fast path that does not need realloc().
108+
* Always inlining this function makes the fast path a few instructions
109+
* in each caller instead of a function call.
106110
*/
107111
static inline Py_ALWAYS_INLINE int
108112
list_resize(PyListObject *self, Py_ssize_t newsize)
@@ -112,7 +116,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
112116
/* Bypass realloc() when a previous overallocation is large enough
113117
to accommodate the newsize. If the newsize falls lower than half
114118
the allocated size, then proceed with the realloc() to shrink the list.
115-
gh-158602: do not shrink a small list, the realloc() cost is bigger
119+
gh-158592: do not shrink a small list, the realloc() cost is bigger
116120
than the memory we get back.
117121
*/
118122
if (allocated >= newsize
@@ -125,7 +129,8 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
125129
return py_list_resize(self, newsize);
126130
}
127131

128-
Py_NO_INLINE static int
132+
/* Slow path of list_resize(): allocate or reallocate ob_item. */
133+
static int
129134
py_list_resize(PyListObject *self, Py_ssize_t newsize)
130135
{
131136
size_t new_allocated, target_bytes;

0 commit comments

Comments
 (0)