|
22 | 22 |
|
23 | 23 | import enum |
24 | 24 | import logging |
25 | | -from functools import lru_cache |
26 | 25 | from struct import Struct |
27 | 26 | from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Tuple, Union |
28 | 27 |
|
|
54 | 53 | PACK_SHORT = Struct('>H').pack |
55 | 54 | PACK_LONG = Struct('>L').pack |
56 | 55 |
|
57 | | -BYTE_TABLE = [PACK_BYTE(i) for i in range(256)] |
58 | | - |
59 | | - |
60 | | -@lru_cache(maxsize=256) |
61 | | -def _cached_pack_short(value: int_) -> bytes_: |
62 | | - return PACK_SHORT(value) |
63 | | - |
64 | | - |
65 | | -CACHED_PACK_SHORT = _cached_pack_short |
| 56 | +BYTE_TABLE = tuple(PACK_BYTE(i) for i in range(256)) |
66 | 57 |
|
67 | 58 |
|
68 | 59 | class State(enum.Enum): |
@@ -224,15 +215,15 @@ def _write_byte(self, value: int_) -> None: |
224 | 215 |
|
225 | 216 | def _insert_short_at_start(self, value: int_) -> None: |
226 | 217 | """Inserts an unsigned short at the start of the packet""" |
227 | | - self.data.insert(0, CACHED_PACK_SHORT(value)) |
| 218 | + self.data.insert(0, PACK_SHORT(value)) |
228 | 219 |
|
229 | 220 | def _replace_short(self, index: int_, value: int_) -> None: |
230 | 221 | """Replaces an unsigned short in a certain position in the packet""" |
231 | | - self.data[index] = CACHED_PACK_SHORT(value) |
| 222 | + self.data[index] = PACK_SHORT(value) |
232 | 223 |
|
233 | 224 | def write_short(self, value: int_) -> None: |
234 | 225 | """Writes an unsigned short to the packet""" |
235 | | - self.data.append(CACHED_PACK_SHORT(value)) |
| 226 | + self.data.append(PACK_SHORT(value)) |
236 | 227 | self.size += 2 |
237 | 228 |
|
238 | 229 | def _write_int(self, value: Union[float, int]) -> None: |
|
0 commit comments