Skip to content
Snippets Groups Projects
Commit 0fc4775c authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

sequence: Further simplify sequence comparison.

parent 83eba5de
No related branches found
No related tags found
No related merge requests found
...@@ -109,11 +109,9 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t * ...@@ -109,11 +109,9 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t *
} }
int len = len1 < len2 ? len1 : len2; int len = len1 < len2 ? len1 : len2;
bool eq_status = true; // empty lists are equal
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
eq_status = mp_obj_equal(items1[i], items2[i]);
// If current elements equal, can't decide anything - go on // If current elements equal, can't decide anything - go on
if (eq_status) { if (mp_obj_equal(items1[i], items2[i])) {
continue; continue;
} }
...@@ -127,9 +125,7 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t * ...@@ -127,9 +125,7 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t *
return (mp_binary_op(op, items1[i], items2[i]) == mp_const_true); return (mp_binary_op(op, items1[i], items2[i]) == mp_const_true);
} }
assert(eq_status);
// If we had tie in the last element... // If we had tie in the last element...
if (eq_status) {
// ... and we have lists of different lengths... // ... and we have lists of different lengths...
if (len1 != len2) { if (len1 != len2) {
if (len1 < len2) { if (len1 < len2) {
...@@ -137,10 +133,9 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t * ...@@ -137,10 +133,9 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t *
return false; return false;
} }
} else if (op == MP_BINARY_OP_MORE) { } else if (op == MP_BINARY_OP_MORE) {
// Otherwise, if we have strict relation, equality means failure // Otherwise, if we have strict relation, sequence equality means failure
return false; return false;
} }
}
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment