feat: Optimize int/byte conversions and add test suite #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit significantly improves the performance and memory efficiency of integer-to-byte conversion utilities.
Key optimizations include:
memoryview.cast()andint.to_bytes()operations.array.arrayand memory views to eliminate intermediate memory copies, especially indump_bar0and when creating byte arrays from integer lists.tests/test_ints_helpers.py) to verify correctness and prevent future regressions.tests/test_ints_performance.py) that validates and benchmarks the gains over the previous implementation.BREAKING CHANGE:
This commit introduces backward-incompatible API changes to improve performance and clarity.
NvSwitch.dump_bar0()now returns a read-onlymemoryviewinstead of abytearray.utils.bytearray_from_ints()function has been removed and replaced byutils.bytearray_view_from_ints(), which returns amemoryview.NiceStruct.to_int_array()method has been renamed toto_int_list(), indicating it returns a int list.NiceStruct.from_int_array()method has been renamed tofrom_ints(), indicating it accepts any iterables of int.