diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-10 07:10:55 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-10 07:13:32 +0200 |
commit | ac0134d427677438ec07f76f9b28b3f514cebde7 (patch) | |
tree | 6d2b9c21d6cdb6ec43373473a38dac9562fd3830 /py/objtuple.c | |
parent | 624eff6a8a948c5ffa7c7d17fab69b3739f2e711 (diff) |
Factor out mp_seq_count_obj() and implement tuple.count().
Diffstat (limited to 'py/objtuple.c')
-rw-r--r-- | py/objtuple.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/py/objtuple.c b/py/objtuple.c index 581bfb629..7221db774 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -153,6 +153,13 @@ static mp_obj_t tuple_getiter(mp_obj_t o_in) { return mp_obj_new_tuple_iterator(o_in, 0); } +static mp_obj_t tuple_count(mp_obj_t self_in, mp_obj_t value) { + assert(MP_OBJ_IS_TYPE(self_in, &tuple_type)); + mp_obj_tuple_t *self = self_in; + return mp_seq_count_obj(self->items, self->len, value); +} +static MP_DEFINE_CONST_FUN_OBJ_2(tuple_count_obj, tuple_count); + static mp_obj_t tuple_index(uint n_args, const mp_obj_t *args) { assert(MP_OBJ_IS_TYPE(args[0], &tuple_type)); mp_obj_tuple_t *self = args[0]; @@ -161,6 +168,7 @@ static mp_obj_t tuple_index(uint n_args, const mp_obj_t *args) { static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tuple_index_obj, 2, 4, tuple_index); static const mp_method_t tuple_type_methods[] = { + { "count", &tuple_count_obj }, { "index", &tuple_index_obj }, { NULL, NULL }, // end-of-list sentinel }; |