Skip to content

Conversation

@felipediel
Copy link
Collaborator

@felipediel felipediel commented Apr 1, 2021

Proposed changes

  • Rename calculate_crc16 to crc16
  • Apply PEP-8 naming conventions
  • Remove unnecessary c_ushort type casting
  • Remove unnecessary conversions
  • Remove unnecessary bitwise operations
  • Accept any sequence type
  • Expose polynomial and initial value as kwargs
  • Store the CRC-16 table for performance

Performance test

>>> import broadlink as blk
>>> from functools import partial
>>> from timeit import timeit
>>> b = bytearray(range(255))

# Before
>>> timeit(partial(blk.helpers.calculate_crc16, b))
826.9239850719969

# After
>>> timeit(partial(blk.helpers.crc16, b))
40.797150269994745

@felipediel felipediel merged commit 3777b3b into mjg59:dev Apr 1, 2021
felipediel added a commit to felipediel/python-broadlink that referenced this pull request Apr 26, 2021
* Rename calculate_crc16 to crc16

* Apply PEP-8 naming conventions

* Remove unnecessary import

* Accept any sequence type

* Remove unnecessary conversions

* Expose polynomial and initial value as kwargs

* Remove unnecessary bitwise operations

* Store the CRC-16 table for performance

* Add missing type hints

* Update docstring

* General improvements
felipediel added a commit to felipediel/python-broadlink that referenced this pull request Sep 12, 2021
* Rename calculate_crc16 to crc16

* Apply PEP-8 naming conventions

* Remove unnecessary import

* Accept any sequence type

* Remove unnecessary conversions

* Expose polynomial and initial value as kwargs

* Remove unnecessary bitwise operations

* Store the CRC-16 table for performance

* Add missing type hints

* Update docstring

* General improvements

Encapsulate crc16() to avoid global (mjg59#566)

Segregate CRC16.get_table() from CRC16.calculate() (mjg59#567)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant