Skip to content

Commit 8c1462b

Browse files
committed
py/objlist: Make three list helper functions inline.
This can be done now these functions are declared in `py/objlist.h`, where the `mp_obj_list_t` struct is defined. This changes code size by -24 bytes on bare-arm, and by -56 bytes on stm32. Signed-off-by: Damien George <damien@micropython.org>
1 parent 1199015 commit 8c1462b

2 files changed

Lines changed: 19 additions & 22 deletions

File tree

py/objlist.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -489,25 +489,6 @@ mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items) {
489489
return MP_OBJ_FROM_PTR(o);
490490
}
491491

492-
void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items) {
493-
mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
494-
*len = self->len;
495-
*items = self->items;
496-
}
497-
498-
void mp_obj_list_set_len(mp_obj_t self_in, size_t len) {
499-
// trust that the caller knows what it's doing
500-
// TODO realloc if len got much smaller than alloc
501-
mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
502-
self->len = len;
503-
}
504-
505-
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
506-
mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
507-
size_t i = mp_get_index(self->base.type, self->len, index, false);
508-
self->items[i] = value;
509-
}
510-
511492
/******************************************************************************/
512493
/* list iterator */
513494

py/objlist.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,24 @@ mp_obj_t mp_obj_list_make_new(const mp_obj_type_t *type_in, size_t n_args, size_
4040
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
4141
mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
4242
mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value);
43-
void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
44-
void mp_obj_list_set_len(mp_obj_t self_in, size_t len);
45-
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
43+
44+
static inline void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items) {
45+
mp_obj_list_t *self = (mp_obj_list_t *)MP_OBJ_TO_PTR(self_in);
46+
*len = self->len;
47+
*items = self->items;
48+
}
49+
50+
static inline void mp_obj_list_set_len(mp_obj_t self_in, size_t len) {
51+
// trust that the caller knows what it's doing
52+
// TODO realloc if len got much smaller than alloc
53+
mp_obj_list_t *self = (mp_obj_list_t *)MP_OBJ_TO_PTR(self_in);
54+
self->len = len;
55+
}
56+
57+
static inline void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
58+
mp_obj_list_t *self = (mp_obj_list_t *)MP_OBJ_TO_PTR(self_in);
59+
size_t i = mp_get_index(self->base.type, self->len, index, false);
60+
self->items[i] = value;
61+
}
4662

4763
#endif // MICROPY_INCLUDED_PY_OBJLIST_H

0 commit comments

Comments
 (0)