Twelve And A Half Percent

CPython grows a list inside list_resize. The relevant lines are:

/* Bypass realloc() when a previous overallocation is large enough
   to accommodate the newsize. ... */
if (allocated >= newsize && newsize >= (allocated >> 1)) {
    Py_SET_SIZE(self, newsize);
    return 0;
}
/* The growth pattern is:  0, 4, 8, 16, 24, 32, 40, 52, 64, 76, ... */
new_allocated = ((size_t)newsize + (newsize >> 3) + 6) & ~(size_t)3;

Start from a = [] and call a.append(x) twenty times. On which of those twenty appends does the buffer actually get reallocated?

A

Every append, because list_resize is called each time

B

Appends 1, 5, 9 and 17

C

Appends 1, 2, 4, 8 and 16

D

Appends 1, 4, 8 and 16