summaryrefslogtreecommitdiffstatshomepage
path: root/py/sequence.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-18 23:35:24 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-18 23:35:24 +0100
commit561f83c9cf62b6470637dfbd51471db63fe5c28d (patch)
tree3b411eff835bec291095c823655698ee43c8849e /py/sequence.c
parent38ae014e4258811d1612f9e140a35f8f9aa0ddb8 (diff)
parent0fc4775cd6e13360bfd622602b50de900dac6617 (diff)
downloadmicropython-561f83c9cf62b6470637dfbd51471db63fe5c28d.tar.gz
micropython-561f83c9cf62b6470637dfbd51471db63fe5c28d.zip
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'py/sequence.c')
-rw-r--r--py/sequence.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/py/sequence.c b/py/sequence.c
index 3a4d65d53b..f91bf43c74 100644
--- a/py/sequence.c
+++ b/py/sequence.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <stdbool.h>
#include <string.h>
@@ -108,31 +109,32 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t *
}
int len = len1 < len2 ? len1 : len2;
- bool eq_status = true; // empty lists are equal
- bool rel_status;
for (int i = 0; i < len; i++) {
- eq_status = mp_obj_equal(items1[i], items2[i]);
- if (op == MP_BINARY_OP_EQUAL && !eq_status) {
- return false;
+ // If current elements equal, can't decide anything - go on
+ if (mp_obj_equal(items1[i], items2[i])) {
+ continue;
}
- rel_status = (mp_binary_op(op, items1[i], items2[i]) == mp_const_true);
- if (!eq_status && !rel_status) {
+
+ // Othewise, if they are not equal, we can have final decision based on them
+ if (op == MP_BINARY_OP_EQUAL) {
+ // In particular, if we are checking for equality, here're the answer
return false;
}
+
+ // Otherwise, application of relation op gives the answer
+ return (mp_binary_op(op, items1[i], items2[i]) == mp_const_true);
}
// If we had tie in the last element...
- if (eq_status) {
- // ... and we have lists of different lengths...
- if (len1 != len2) {
- if (len1 < len2) {
- // ... then longer list length wins (we deal only with >)
- return false;
- }
- } else if (op == MP_BINARY_OP_MORE) {
- // Otherwise, if we have strict relation, equality means failure
+ // ... and we have lists of different lengths...
+ if (len1 != len2) {
+ if (len1 < len2) {
+ // ... then longer list length wins (we deal only with >)
return false;
}
+ } else if (op == MP_BINARY_OP_MORE) {
+ // Otherwise, if we have strict relation, sequence equality means failure
+ return false;
}
return true;