Factor out mp_seq_count_obj() and implement tuple.count().

This commit is contained in:
Paul Sokolovsky
2014-02-10 07:10:55 +02:00
parent 624eff6a8a
commit ac0134d427
5 changed files with 27 additions and 8 deletions

View File

@@ -260,14 +260,7 @@ static mp_obj_t list_copy(mp_obj_t self_in) {
static mp_obj_t list_count(mp_obj_t self_in, mp_obj_t value) {
assert(MP_OBJ_IS_TYPE(self_in, &list_type));
mp_obj_list_t *self = self_in;
int count = 0;
for (int i = 0; i < self->len; i++) {
if (mp_obj_equal(self->items[i], value)) {
count++;
}
}
return mp_obj_new_int(count);
return mp_seq_count_obj(self->items, self->len, value);
}
static mp_obj_t list_index(uint n_args, const mp_obj_t *args) {