diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2023-02-03 16:42:03 +1100 |
---|---|---|
committer | Jim Mussared <jim.mussared@gmail.com> | 2024-01-25 16:38:17 +1100 |
commit | 7ea503929a494a2622d933d3497b393ae14a1550 (patch) | |
tree | 60dceb87664e5679b6b7d39998ae7d167765f465 /py/makeqstrdata.py | |
parent | 307ecc5707e78c62b0b9fb1c0ba8dcb9c4cc5559 (diff) | |
download | micropython-7ea503929a494a2622d933d3497b393ae14a1550.tar.gz micropython-7ea503929a494a2622d933d3497b393ae14a1550.zip |
py/qstr: Add support for MICROPY_QSTR_BYTES_IN_HASH=0.
This disables using qstr hashes altogether, which saves RAM and flash
(two bytes per interned string on a typical build) as well as code size.
On PYBV11 this is worth over 3k flash.
qstr comparison will now be done just by length then data. This affects
qstr_find_strn although this has a negligible performance impact as, for a
given comparison, the length and first character will ~usually be
different anyway.
String hashing (e.g. builtin `hash()` and map.c) now need to compute the
hash dynamically, and for the map case this does come at a performance
cost.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/makeqstrdata.py')
-rw-r--r-- | py/makeqstrdata.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 2350fe04d2..3e5e7930a5 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -295,7 +295,8 @@ def compute_hash(qstr, bytes_hash): for b in qstr: hash = (hash * 33) ^ b # Make sure that valid hash is never zero, zero means "hash not computed" - return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1 + # if bytes_hash is zero, assume a 16-bit mask (to match qstr.c) + return (hash & ((1 << (8 * (bytes_hash or 2))) - 1)) or 1 def qstr_escape(qst): |