From 05ea718dcdf0a1d848d0eb98236439f8f0be07cf Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 24 Nov 2023 17:03:23 -0600 Subject: [PATCH] feat: improve performance of gap parser (#37) --- src/bluetooth_data_tools/gap.pxd | 5 ++--- src/bluetooth_data_tools/gap.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/bluetooth_data_tools/gap.pxd b/src/bluetooth_data_tools/gap.pxd index 29bc7ec..ed16454 100644 --- a/src/bluetooth_data_tools/gap.pxd +++ b/src/bluetooth_data_tools/gap.pxd @@ -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, diff --git a/src/bluetooth_data_tools/gap.py b/src/bluetooth_data_tools/gap.py index c19ad43..e82132e 100644 --- a/src/bluetooth_data_tools/gap.py +++ b/src/bluetooth_data_tools/gap.py @@ -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