|
27 | 27 | #include "shared-bindings/displayio/Group.h"
|
28 | 28 |
|
29 | 29 | #include "py/runtime.h"
|
| 30 | +#include "py/objlist.h" |
30 | 31 | #include "shared-bindings/displayio/TileGrid.h"
|
31 | 32 |
|
32 | 33 | #if CIRCUITPY_VECTORIO
|
33 | 34 | #include "shared-bindings/vectorio/VectorShape.h"
|
34 | 35 | #endif
|
35 | 36 |
|
36 |
| -#include <string.h> |
37 |
| -#define LIST_MIN_ALLOC 4 |
38 |
| - |
39 |
| -STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) { |
40 |
| - mp_check_self(MP_OBJ_IS_TYPE(args[0], &mp_type_list)); |
41 |
| - mp_obj_list_t *self = mp_instance_cast_to_native_base(args[0], &mp_type_list); |
42 |
| - if (self->len == 0) { |
43 |
| - mp_raise_IndexError_varg(translate("pop from empty %q"), MP_QSTR_list); |
44 |
| - } |
45 |
| - size_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false); |
46 |
| - mp_obj_t ret = self->items[index]; |
47 |
| - self->len -= 1; |
48 |
| - memmove(self->items + index, self->items + index + 1, (self->len - index) * sizeof(mp_obj_t)); |
49 |
| - // Clear stale pointer from slot which just got freed to prevent GC issues |
50 |
| - self->items[self->len] = MP_OBJ_NULL; |
51 |
| - if (self->alloc > LIST_MIN_ALLOC && self->alloc > 2 * self->len) { |
52 |
| - self->items = m_renew(mp_obj_t, self->items, self->alloc, self->alloc/2); |
53 |
| - self->alloc /= 2; |
54 |
| - } |
55 |
| - return ret; |
56 |
| -} |
57 | 37 |
|
58 | 38 | void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y) {
|
59 | 39 | mp_obj_list_t *members = mp_obj_new_list(0, NULL);
|
@@ -343,8 +323,7 @@ void common_hal_displayio_group_insert(displayio_group_t* self, size_t index, mp
|
343 | 323 |
|
344 | 324 | mp_obj_t common_hal_displayio_group_pop(displayio_group_t* self, size_t index) {
|
345 | 325 | _remove_layer(self, index);
|
346 |
| - mp_obj_t args[] = {self->members, MP_OBJ_NEW_SMALL_INT(index)}; |
347 |
| - return list_pop(2, args); |
| 326 | + return mp_obj_list_pop(self->members, index); |
348 | 327 | }
|
349 | 328 |
|
350 | 329 | mp_int_t common_hal_displayio_group_index(displayio_group_t* self, mp_obj_t layer) {
|
|
0 commit comments