summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-13 19:52:28 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-13 19:52:28 +0000
commit2ded68db77d92f4f277ae688c22ac0be32dc4f31 (patch)
treeedd62f1099b30daed97784a3a3b37e508761a4dc /py
parent5c7683955994b965270598559e979c581ddc1950 (diff)
downloadmicropython-2ded68db77d92f4f277ae688c22ac0be32dc4f31.tar.gz
micropython-2ded68db77d92f4f277ae688c22ac0be32dc4f31.zip
Cleaned up sorted() as per Damien's suggestions.
Diffstat (limited to 'py')
-rw-r--r--py/builtin.c9
-rw-r--r--py/obj.h1
2 files changed, 2 insertions, 8 deletions
diff --git a/py/builtin.c b/py/builtin.c
index f73d41b0d8..2d61cd603f 100644
--- a/py/builtin.c
+++ b/py/builtin.c
@@ -297,7 +297,6 @@ mp_obj_t mp_builtin_sum(int n_args, const mp_obj_t *args) {
return value;
}
-extern mp_obj_t list_sort(mp_obj_t args, mp_map_t *kwargs);
static mp_obj_t mp_builtin_sorted(mp_obj_t args, mp_map_t *kwargs) {
mp_obj_t *args_items = NULL;
uint args_len = 0;
@@ -309,13 +308,7 @@ static mp_obj_t mp_builtin_sorted(mp_obj_t args, mp_map_t *kwargs) {
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError,
"must use keyword argument for key function"));
}
- mp_obj_t iterable = rt_getiter(args_items[0]);
- mp_obj_t self = rt_build_list(0, NULL);
- mp_obj_t item;
- while ((item = rt_iternext(iterable)) != mp_const_stop_iteration) {
- rt_list_append(self, item);
- }
-
+ mp_obj_t self = list_type.make_new((mp_obj_t)&list_type, 1, args_items);
mp_obj_t new_args = rt_build_tuple(1, &self);
list_sort(new_args, kwargs);
diff --git a/py/obj.h b/py/obj.h
index 8a2cba62bb..d1db0dde0f 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -292,6 +292,7 @@ extern const mp_obj_type_t list_type;
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
void mp_obj_list_get(mp_obj_t self_in, uint *len, mp_obj_t **items);
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
+mp_obj_t list_sort(mp_obj_t args, struct _mp_map_t *kwargs);
// dict
extern const mp_obj_type_t dict_type;