summaryrefslogtreecommitdiffstatshomepage
path: root/py/objstr.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-02 02:38:22 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-02 02:38:22 +0200
commit7364af2d8cd72467bbb3bf135b29fae47105b232 (patch)
tree7e57caabe5eb86a71f394f02858a6519ecf9e075 /py/objstr.c
parenta9459bc7233e92a6516c3fbc8a18a9d33966e244 (diff)
downloadmicropython-7364af2d8cd72467bbb3bf135b29fae47105b232.tar.gz
micropython-7364af2d8cd72467bbb3bf135b29fae47105b232.zip
Factor out m_seq_get_fast_slice_indexes() fucntions as sequence helper.
Takes slice object and sequence length and computes subsequence indexes for case of slice step=1.
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c22
1 files changed, 2 insertions, 20 deletions
diff --git a/py/objstr.c b/py/objstr.c
index 3f6aa483e2..92bd71f3de 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -115,26 +115,8 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
#if MICROPY_ENABLE_SLICE
} else if (MP_OBJ_IS_TYPE(rhs_in, &slice_type)) {
- machine_int_t start, stop, step;
- mp_obj_slice_get(rhs_in, &start, &stop, &step);
- assert(step == 1);
- if (start < 0) {
- start = lhs_len + start;
- if (start < 0) {
- start = 0;
- }
- } else if (start > lhs_len) {
- start = lhs_len;
- }
- if (stop <= 0) {
- stop = lhs_len + stop;
- // CPython returns empty string in such case
- if (stop < 0) {
- stop = start;
- }
- } else if (stop > lhs_len) {
- stop = lhs_len;
- }
+ machine_uint_t start, stop;
+ assert(m_seq_get_fast_slice_indexes(lhs_len, rhs_in, &start, &stop));
return mp_obj_new_str(lhs_data + start, stop - start, false);
#endif
} else {