40 #define LIST_MIN_ALLOC 4 51 for (
size_t i = 0; i < o->
len; i++) {
93 #if MICROPY_PY_SYS_GETSIZEOF 95 size_t sz =
sizeof(*self) +
sizeof(
mp_obj_t) * self->alloc;
145 return mp_obj_new_bool(res);
156 #if MICROPY_PY_BUILTINS_SLICE 160 if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) {
169 mp_seq_clear(self->items, self->len + len_adj, self->len,
sizeof(*self->items));
170 self->len += len_adj;
180 #if MICROPY_PY_BUILTINS_SLICE 183 if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) {
191 size_t index_val =
mp_get_index(self->base.type, self->len, index,
false);
192 return self->items[index_val];
194 #if MICROPY_PY_BUILTINS_SLICE 197 size_t value_len;
mp_obj_t *value_items;
200 if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) {
206 if (self->len + len_adj > self->alloc) {
209 self->items =
m_renew(
mp_obj_t, self->items, self->alloc, self->len + len_adj);
210 self->alloc =
self->len + len_adj;
213 slice_out.
start, slice_out.
stop, value_items, value_len, len_adj,
sizeof(*self->items));
216 slice_out.
start, slice_out.
stop, value_items, value_len,
sizeof(*self->items));
218 mp_seq_clear(self->items, self->len + len_adj, self->len,
sizeof(*self->items));
221 self->len += len_adj;
237 if (self->len >= self->alloc) {
238 self->items =
m_renew(
mp_obj_t, self->items, self->alloc, self->alloc * 2);
240 mp_seq_clear(self->items, self->len + 1, self->alloc,
sizeof(*self->items));
242 self->items[
self->len++] = arg;
252 if (self->len + arg->
len > self->alloc) {
255 self->alloc =
self->len + arg->
len + 4;
256 mp_seq_clear(self->items, self->len + arg->
len, self->alloc,
sizeof(*self->items));
260 self->len += arg->
len;
270 if (self->len == 0) {
276 memmove(self->items + index, self->items + index + 1, (self->len - index) *
sizeof(
mp_obj_t));
279 if (self->alloc >
LIST_MIN_ALLOC && self->alloc > 2 * self->len) {
280 self->items =
m_renew(
mp_obj_t, self->items, self->alloc, self->alloc/2);
288 while (head < tail) {
304 if (t - head < tail - h - 1) {
316 static const mp_arg_t allowed_args[] = {
346 mp_seq_clear(self->items, 0, self->alloc,
sizeof(*self->items));
379 if ((
size_t)index > self->len) {
385 for (
mp_int_t i = self->len-1; i > index; i--) {
386 self->items[i] =
self->items[i-1];
388 self->items[index] = obj;
407 for (
mp_int_t i = 0; i < len/2; i++) {
409 self->items[i] =
self->items[len-i-1];
410 self->items[len-i-1] = a;
446 .
name = MP_QSTR_list,
473 for (
size_t i = 0; i < n; i++) {
474 o->
items[i] = items[i];
483 *items =
self->items;
495 size_t i =
mp_get_index(self->base.type, self->len, index,
false);
496 self->items[i] = value;
512 if (self->cur <
list->len) {
STATIC const mp_rom_map_elem_t list_locals_dict_table[]
STATIC MP_DEFINE_CONST_FUN_OBJ_3(list_insert_obj, list_insert)
#define mp_seq_clear(start, len, alloc_len, item_sz)
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg)
STATIC void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, mp_obj_t binop_less_result)
NORETURN void mp_raise_NotImplementedError(const char *msg)
mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value)
STATIC mp_obj_t list_unary_op(mp_unary_op_t op, mp_obj_t self_in)
const mp_obj_type_t mp_type_list
#define MP_OBJ_IS_TYPE(o, t)
STATIC mp_obj_t list_index(size_t n_args, const mp_obj_t *args)
int mp_print_str(const mp_print_t *print, const char *str)
#define MP_OBJ_FROM_PTR(p)
void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals)
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw)
STATIC void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
STATIC mp_obj_t list_count(mp_obj_t self_in, mp_obj_t value)
mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items)
void mp_obj_list_init(mp_obj_list_t *o, size_t n)
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value)
STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in)
#define MP_OBJ_SMALL_INT_VALUE(o)
mp_obj_t(* mp_fun_1_t)(mp_obj_t)
STATIC mp_obj_t list_reverse(mp_obj_t self_in)
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items)
size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool is_slice)
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_index_obj, 2, 4, list_index)
#define MP_OBJ_NEW_SMALL_INT(small_int)
mp_obj_t mp_call_function_1(mp_obj_t fun, mp_obj_t arg)
const mp_obj_type_t mp_type_polymorph_iter
void mp_obj_list_set_len(mp_obj_t self_in, size_t len)
#define mp_check_self(pred)
bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, size_t len1, const mp_obj_t *items2, size_t len2)
mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
void * memmove(void *dst, const void *src, size_t n)
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
STATIC mp_obj_t list_extend_from_iter(mp_obj_t list, mp_obj_t iterable)
mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs)
STATIC mp_obj_list_t * list_new(size_t n)
const struct _mp_obj_none_t mp_const_none_obj
STATIC mp_obj_t list_it_iternext(mp_obj_t self_in)
void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times, void *dest)
#define mp_seq_replace_slice_no_grow(dest, dest_len, beg, end, slice, slice_len, item_sz)
STATIC mp_obj_t list_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf)
bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value)
const mp_obj_type_t mp_type_type
STATIC mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur, mp_obj_iter_buf_t *iter_buf)
#define m_renew(type, ptr, old_num, new_num)
const mp_obj_type_t mp_type_IndexError
STATIC mp_obj_t list_copy(mp_obj_t self_in)
STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
#define mp_seq_copy(dest, src, len, item_t)
STATIC mp_obj_t list_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, list_clear)
const mp_obj_type_t mp_type_slice
#define mp_seq_replace_slice_grow_inplace(dest, dest_len, beg, end, slice, slice_len, len_adj, item_sz)
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg)
STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args)
mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf)
STATIC MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table)
#define MP_OBJ_STOP_ITERATION
mp_obj_t mp_iternext(mp_obj_t o_in)
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, 1, mp_obj_list_sort)
mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, const mp_obj_t *args)
void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items)
mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes)
STATIC mp_obj_t list_clear(mp_obj_t self_in)
STATIC mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj)
STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs)
void * memcpy(void *dst, const void *src, size_t n)
struct _mp_obj_list_it_t mp_obj_list_it_t
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append)
#define mp_seq_cat(dest, src1, len1, src2, len2, item_t)