The two isinstance checks can be combined to a single call that uses a
tuple of types to check against.
When 8c9d5b4 was prototyped, it originally used a single call but it
was falsely micro-optimized to use two separate calls due to the single
call being slower.
The performance overhead was likely due to the tuple of types being
created on each iteration of the loop. Using a module variable with the
proper types avoids this overhead.
$ python3 -m timeit -s "x = 42; T = (int, str)" "isinstance(x, T)"
20000000 loops, best of 5: 13.9 nsec per loop
$ python3 -m timeit -s "x = 42" "isinstance(x, int) or isinstance(x, str)"
20000000 loops, best of 5: 14.6 nsec per loop
$ python3 -m timeit -s "x = 42" "isinstance(x, (int, str))"
10000000 loops, best of 5: 30 nsec per loop
Fixes: 8c9d5b4 ("bindings: python: make config iteration consistent")
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20261020003728.13669-4-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Previously, Chip.request_lines and LineRequest.reconfigure_lines
iterated over a config object but did so in subtly different ways.
Create a generator that iterates over a config object and returns line +
settings pairs. Update the aforementioned functions to use the generator
to consolidate and condense code.
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251009130516.3729433-2-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>