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/qstr.h | |
| parent | 307ecc5707e78c62b0b9fb1c0ba8dcb9c4cc5559 (diff) | |
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/qstr.h')
| -rw-r--r-- | py/qstr.h | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -60,7 +60,9 @@ enum { typedef size_t qstr; typedef uint16_t qstr_short_t; -#if MICROPY_QSTR_BYTES_IN_HASH == 1 +#if MICROPY_QSTR_BYTES_IN_HASH == 0 +// No qstr_hash_t type needed. +#elif MICROPY_QSTR_BYTES_IN_HASH == 1 typedef uint8_t qstr_hash_t; #elif MICROPY_QSTR_BYTES_IN_HASH == 2 typedef uint16_t qstr_hash_t; @@ -82,7 +84,9 @@ typedef struct _qstr_pool_t { size_t is_sorted : 1; size_t alloc; size_t len; + #if MICROPY_QSTR_BYTES_IN_HASH qstr_hash_t *hashes; + #endif qstr_len_t *lengths; const char *qstrs[]; } qstr_pool_t; @@ -92,6 +96,7 @@ typedef struct _qstr_pool_t { void qstr_init(void); size_t qstr_compute_hash(const byte *data, size_t len); + qstr qstr_find_strn(const char *str, size_t str_len); // returns MP_QSTRnull if not found qstr qstr_from_str(const char *str); |
