Skip to content

Commit 607f5e4

Browse files
authored
Merge branch 'main' into koan/symmetric-parse-bytes-cache
2 parents fad1ad8 + 967cc9f commit 607f5e4

5 files changed

Lines changed: 9 additions & 13 deletions

File tree

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
project = "bluetooth-data-tools"
88
copyright = "2023, J. Nick Koston"
99
author = "J. Nick Koston"
10-
release = "1.29.15"
10+
release = "1.29.16"
1111

1212
# General configuration
1313
extensions = [

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[project]
66
name = "bluetooth-data-tools"
7-
version = "1.29.15"
7+
version = "1.29.16"
88
license = "Apache-2.0"
99
description = "Tools for converting bluetooth data and packets"
1010
authors = [{ name = "J. Nick Koston", email = "nick@koston.org" }]

src/bluetooth_data_tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
short_address,
2222
)
2323

24-
__version__ = "1.29.15"
24+
__version__ = "1.29.16"
2525

2626

2727
__all__ = [

src/bluetooth_data_tools/gap.pxd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ cdef dict _EMPTY_MANUFACTURER_DATA
77
cdef dict _EMPTY_SERVICE_DATA
88
cdef list _EMPTY_SERVICE_UUIDS
99

10-
cdef object from_bytes
11-
cdef object from_bytes_little
12-
1310
cdef object _cached_uint16_int_as_uuid
1411
cdef object _cached_uint32_int_as_uuid
1512
cdef object _cached_uint128_bytes_as_uuid

src/bluetooth_data_tools/gap.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from collections.abc import Iterable
55
from enum import IntEnum
6-
from functools import lru_cache, partial
6+
from functools import lru_cache
77
from typing import TYPE_CHECKING
88

99
BLE_UUID = "0000-1000-8000-00805f9b34fb"
@@ -75,9 +75,6 @@ class BLEGAPType(IntEnum):
7575
TYPE_MANUFACTURER_SPECIFIC_DATA = 0xFF
7676

7777

78-
from_bytes = int.from_bytes
79-
from_bytes_little = partial(from_bytes, byteorder="little")
80-
8178
# Signed-fold constants for the one-byte TX Power Level decode.
8279
# A uint8 value at or above _INT8_SIGN_THRESHOLD is negative when interpreted
8380
# as int8, and recovers its signed value via subtraction of _INT8_RANGE.
@@ -113,9 +110,11 @@ class BLEGAPType(IntEnum):
113110

114111
@lru_cache(maxsize=256)
115112
def _uint128_bytes_as_uuid(uint128_bytes: bytes_) -> str:
116-
"""Convert an integer to a UUID str."""
117-
int_value = from_bytes_little(uint128_bytes)
118-
hex = f"{int_value:032x}"
113+
"""Convert 16 little-endian bytes to a canonical UUID str."""
114+
# bytes.hex() is a single C call; reversing the 16-byte slice yields the
115+
# big-endian hex form directly, skipping the int.from_bytes + format-spec
116+
# round-trip used previously (~40% faster on the cache-miss path).
117+
hex = uint128_bytes[::-1].hex()
119118
return f"{hex[:8]}-{hex[8:12]}-{hex[12:16]}-{hex[16:20]}-{hex[20:]}"
120119

121120

0 commit comments

Comments
 (0)