summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-20 01:26:25 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-20 01:26:25 +0100
commit53775026e75d6a1c2611eb71ccfa118d1d82bddb (patch)
tree3b6e098d029e6c0fbde7eed34da1662e95aeadba /py
parentfd6925b4b90761a535bd7b14be019b7870491b2f (diff)
parentefc36f0cea84931ac055979d52e261afc912c3dd (diff)
downloadmicropython-53775026e75d6a1c2611eb71ccfa118d1d82bddb.tar.gz
micropython-53775026e75d6a1c2611eb71ccfa118d1d82bddb.zip
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'py')
-rw-r--r--py/objarray.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/py/objarray.c b/py/objarray.c
index cf8b1ed4eb..b7a84ba4cf 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -139,14 +139,27 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
return MP_OBJ_NOT_SUPPORTED;
} else {
mp_obj_array_t *o = self_in;
- uint index = mp_get_index(o->base.type, o->len, index_in, false);
- if (value == MP_OBJ_SENTINEL) {
- // load
- return mp_binary_get_val_array(o->typecode, o->items, index);
+ if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
+ machine_uint_t start, stop;
+ if (!m_seq_get_fast_slice_indexes(o->len, index_in, &start, &stop)) {
+ assert(0);
+ }
+ mp_obj_array_t *res = array_new(o->typecode, stop - start);
+ int sz = mp_binary_get_size('@', o->typecode, NULL);
+ assert(sz > 0);
+ byte *p = o->items;
+ memcpy(res->items, p + start * sz, (stop - start) * sz);
+ return res;
} else {
- // store
- mp_binary_set_val_array(o->typecode, o->items, index, value);
- return mp_const_none;
+ uint index = mp_get_index(o->base.type, o->len, index_in, false);
+ if (value == MP_OBJ_SENTINEL) {
+ // load
+ return mp_binary_get_val_array(o->typecode, o->items, index);
+ } else {
+ // store
+ mp_binary_set_val_array(o->typecode, o->items, index, value);
+ return mp_const_none;
+ }
}
}
}