summaryrefslogtreecommitdiff
path: root/py/objtuple.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-02-02 13:13:29 +0000
committerDamien George <damien.p.george@gmail.com>2014-02-02 13:13:29 +0000
commit09e1f43200ec28082456042a58d9f39f483f3ad0 (patch)
treea61fff4a0fbad891177d64bf311c9cb0882b4e1b /py/objtuple.c
parentcd82e02e84df5f9f2f3082d865beae25217af2a1 (diff)
parentea2509d92cbb222854ceb0b323b616b807dd221b (diff)
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'py/objtuple.c')
-rw-r--r--py/objtuple.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/py/objtuple.c b/py/objtuple.c
index 5f1744ea3..3e5041c9d 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -1,3 +1,4 @@
+#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
@@ -87,7 +88,17 @@ static mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
switch (op) {
case RT_BINARY_OP_SUBSCR:
{
- // tuple load
+#if MICROPY_ENABLE_SLICE
+ if (MP_OBJ_IS_TYPE(rhs, &slice_type)) {
+ machine_uint_t start, stop;
+ if (!m_seq_get_fast_slice_indexes(o->len, rhs, &start, &stop)) {
+ assert(0);
+ }
+ mp_obj_tuple_t *res = mp_obj_new_tuple(stop - start, NULL);
+ m_seq_copy(res->items, o->items + start, res->len, mp_obj_t);
+ return res;
+ }
+#endif
uint index = mp_get_index(o->base.type, o->len, rhs);
return o->items[index];
}