'Ensure the list is properly sized for the new size.'

def resize(self, new_size):

    def _payload_realloc(new_allocated):
        payload_type = context.get_data_type(types.ListPayload(self._ty))
        payload_size = context.get_abi_sizeof(payload_type)
        payload_size -= itemsize
        (allocsize, ovf) = cgutils.muladd_with_overflow(builder, new_allocated, ir.Constant(intp_t, itemsize), ir.Constant(intp_t, payload_size))
        with builder.if_then(ovf, likely=False):
            context.call_conv.return_user_exc(builder, MemoryError, ('cannot    resize    list',))
        ptr = context.nrt.meminfo_varsize_realloc(builder, self._list.meminfo, size=allocsize)
        cgutils.guard_memory_error(context, builder, ptr, 'cannot    resize    list')
        self._payload.allocated = new_allocated
    context = self._context
    builder = self._builder
    intp_t = new_size.type
    itemsize = get_itemsize(context, self._ty)
    allocated = self._payload.allocated
    one = ir.Constant(intp_t, 1)
    two = ir.Constant(intp_t, 2)
    eight = ir.Constant(intp_t, 8)
    is_too_small = builder.icmp_signed('<', allocated, new_size)
    is_too_large = builder.icmp_signed('>', builder.ashr(allocated, two), new_size)
    with builder.if_then(is_too_large, likely=False):
        _payload_realloc(new_size)
    with builder.if_then(is_too_small, likely=False):
        new_allocated = builder.add(eight, builder.add(new_size, builder.ashr(new_size, two)))
        _payload_realloc(new_allocated)
    self._payload.size = new_size
    self.set_dirty(True)
