diff options
author | Damien George <damien.p.george@gmail.com> | 2016-01-13 15:47:56 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-01-13 15:47:56 +0000 |
commit | 22d85ec5be77e7ee6b703221d51113f7f21a995b (patch) | |
tree | 52741900f09b57b78c568188b3d7f38f0200eaf0 /py/objlist.c | |
parent | 8bb4931fec1d3661487e126ff541479948d50d2e (diff) | |
download | micropython-22d85ec5be77e7ee6b703221d51113f7f21a995b.tar.gz micropython-22d85ec5be77e7ee6b703221d51113f7f21a995b.zip |
py: Use new code pattern for parsing kw args with mp_arg_parse_all.
Makes code easier to read and more maintainable.
Diffstat (limited to 'py/objlist.c')
-rw-r--r-- | py/objlist.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/py/objlist.c b/py/objlist.c index 62928af064..df6b1bc99a 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -318,16 +318,19 @@ mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ }; // parse args - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + struct { + mp_arg_val_t key, reverse; + } args; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, + MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args); assert(MP_OBJ_IS_TYPE(pos_args[0], &mp_type_list)); mp_obj_list_t *self = MP_OBJ_TO_PTR(pos_args[0]); if (self->len > 1) { mp_quicksort(self->items, self->items + self->len - 1, - args[0].u_obj == mp_const_none ? MP_OBJ_NULL : args[0].u_obj, - args[1].u_bool ? mp_const_false : mp_const_true); + args.key.u_obj == mp_const_none ? MP_OBJ_NULL : args.key.u_obj, + args.reverse.u_bool ? mp_const_false : mp_const_true); } return mp_const_none; |