diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-14 01:43:01 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-14 01:43:01 +0300 |
commit | 59e269cfec51b6a7933d6e847a38c84c04056675 (patch) | |
tree | d398b54d687d9cfce31d8ea5cdca2ba7dece354c /py/qstr.c | |
parent | 14de114ba811614ba6e058f6d864129f5c8b73bb (diff) | |
download | micropython-59e269cfec51b6a7933d6e847a38c84c04056675.tar.gz micropython-59e269cfec51b6a7933d6e847a38c84c04056675.zip |
qstr, objstr: Make sure that valid hash != 0, treat 0 as "not computed".
This feature was proposed with initial hashing RFC, and is prerequisite for
seamless static str object definition.
Diffstat (limited to 'py/qstr.c')
-rw-r--r-- | py/qstr.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -35,7 +35,12 @@ machine_uint_t qstr_compute_hash(const byte *data, uint len) { for (const byte *top = data + len; data < top; data++) { hash = ((hash << 5) + hash) ^ (*data); // hash * 33 ^ data } - return hash & 0xffff; + hash &= 0xffff; + // Make sure that valid hash is never zero, zero means "hash not computed" + if (hash == 0) { + hash++; + } + return hash; } typedef struct _qstr_pool_t { |