bytes: Implement comparison and other binary operations.

Should support everything supported by strings.
This commit is contained in:
Paul Sokolovsky
2014-05-10 04:26:10 +03:00
parent 070c78af5d
commit 7b0f9a7d9b
3 changed files with 65 additions and 9 deletions

View File

@@ -83,6 +83,10 @@ bool m_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, machine_ui
// Special-case comparison function for sequences of bytes
// Don't pass MP_BINARY_OP_NOT_EQUAL here
bool mp_seq_cmp_bytes(int op, const byte *data1, uint len1, const byte *data2, uint len2) {
if (op == MP_BINARY_OP_EQUAL && len1 != len2) {
return false;
}
// Let's deal only with > & >=
if (op == MP_BINARY_OP_LESS || op == MP_BINARY_OP_LESS_EQUAL) {
SWAP(const byte*, data1, data2);