Skip to content

Commit

Permalink
feat: improve performance of gap parser (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 24, 2023
1 parent 0a2df27 commit 05ea718
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/bluetooth_data_tools/gap.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ cpdef parse_advertisement_data_tuple(cython.tuple data)
@cython.locals(
gap_data=cython.bytes,
gap_value=cython.bytes,
gap_view="const unsigned char [:]",
gap_type_num=cython.uint,
gap_type_num="unsigned char",
total_length=cython.uint,
length=cython.uint,
length="unsigned char",
offset=cython.uint,
start=cython.uint,
end=cython.uint,
Expand Down
5 changes: 2 additions & 3 deletions src/bluetooth_data_tools/gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,18 @@ def _uncached_parse_advertisement_data(
tx_power: int | None = None

for gap_data in data:
gap_view = gap_data
offset = 0
total_length = len(gap_data)
while offset < total_length:
try:
length = gap_view[offset]
length = gap_data[offset]
if not length:
if offset + 2 < total_length:
# Maybe zero padding
offset += 1
continue
break
gap_type_num = gap_view[offset + 1]
gap_type_num = gap_data[offset + 1]
if not gap_type_num:
break
start = offset + 2
Expand Down

0 comments on commit 05ea718

Please sign in to comment.