MP_QSTR_SEARCH_THRESHOLD doesn't provide improvement with sorted hashes.
Remove MP_QSTR_SEARCH_THRESHOLD and simlify the binary search.
Sequential search is still needed in case of hash collisions, or
unsorted pools.
Signed-off-by: Amir Gonnen <amirgonnen@gmail.com>
This fixes a corner case where both hash and lengths of two qstrs are
equal. In such case, if the binary search lower bound is the second
instance of the same hash, the search will miss the first instance.
To overcome this, when lower bound hash equals the requested hash, we move
the lower bound backwards to cover all previous hashes which are also equal
to the requested hash.
Also removed length comparison since it's no longer needed.
Related: https://github.com/lvgl/lv_binding_micropython/issues/224
Signed-off-by: Amir Gonnen <amirgonnen@gmail.com>
In case cmp == 0 there could be a hash collision. To save program size
Instead of checking for hash collisions, simply revert to linear search
which also compares strings.
Instead of sorting by string, sort qstrs by (hash, len).
This allows faster binary serach on qstr_find_strn, since it's faster
to compare hashes than strings.
A few strings needed to be moved to special string pool (QDEF0)
because their qstr is assumed to be small (8 bit) on py/scope.c
Use Qstr class instead of tuple, where properties are calculated only when
accessed.
This is needed as preparation to using hash as the sort key instead the
qstr string. It also makes the code more readable when referring to a qstr
in py/makeqstrdata.py and tools/mpy-tool.py (for example, refer to q.order
instead of q[0], or q.qstr instead of q[2])
Signed-off-by: Amir Gonnen <amirgonnen@gmail.com>
Today qstr implementation scans strings sequntially.
In cases there are many strings this can become very inefficient.
This change improves qstr search performance by using binary search in
sorted qstr pools, when possible.
This change introduces an option to create a sorted string pool, which
is then searched by a binary search instead of sequential search.
qstr pool can be either "sorted" or "unsorted", whereas the unsorted is
searched sequentally as today.
Native modules (MP_ROM_QSTR) and frozen modules generate sorted pools.
Currently runtime strings are unsorted.
The constant string pools is split into two and a new pool is introduced,
"special_const_pool". This is required because the first sequence of
strings already requires special ordering therefore created unsorted,
while the rest of the constants are generated sorted.
qstr_find_strn searches strings in each pool. If the pool is sorted and
larger than a threshold, it will be search using binary search instead
of sequential search, significantly improving performance.
Bug fix for esp32 SoftI2C
This is a bug fix release. The changes are:
- extmod/machine_i2c: only use WRITE1 option if transfer supports it
This fixes the machine.SoftI2C.readfrom_mem() method on esp32, so it
writes the address to read from.
When MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 is enabled the port's hardware
I2C transfer functions should support the MP_MACHINE_I2C_FLAG_WRITE1
option, but software I2C will not. So add a flag to the I2C protocol
struct so each individual protocol can indicate whether it supports this
option or not.
Fixes issue #8765.
Signed-off-by: Damien George <damien@micropython.org>
Catch calls to legacy:
MP_REGISTER_MODULE(name, module, enable)
Emit a friendly error suggesting they be rewritten to:
MP_REGISTER_MODULE(name, module).
Signed-off-by: Phil Howard <phil@pimoroni.com>
* The mbedtls config file path is hard-coded to the config file in
the stm32 port. Any port using this cmake fragment is not actually
using its own config file.
For v2 cards that are standard capacity the read/write/erase commands take
byte address values. Use the result of CMD58 to distinguish SDSC from
SDHC/SDXC.
Signed-off-by: Damien George <damien@micropython.org>
For CSD v1.0 the computed size is in bytes, so convert it to number of
512-byte blocks, and then ioctl(4) will return the correct value.
Also implement ioctl(5) to return the block size, which is always 512.
Signed-off-by: Damien George <damien@micropython.org>