Skip to content

Commit 4f08029

Browse files
authored
Move lru_cache definitions to __init__ (#9)
Using the lru_cache decorators on class methods, the ones that have a reference to `self`, will also cache self. So we move it to the __init__ of the class (DIS-2913)
1 parent a9522fa commit 4f08029

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

dissect/executable/elf/elf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,14 @@ def dump_table(self) -> tuple[int, bytearray]:
318318

319319

320320
class StringTable(Section):
321+
def __init__(self, fh: BinaryIO, idx: Optional[int] = None, c_elf: cstruct = c_elf_64):
322+
super().__init__(fh, idx, c_elf)
323+
324+
self._get_string = lru_cache(256)(self._get_string)
325+
321326
def __getitem__(self, offset: int) -> str:
322327
return self._get_string(offset)
323328

324-
@lru_cache
325329
def _get_string(self, index: int) -> str:
326330
if index > len(self.contents) or index == SHN.UNDEF:
327331
return None

0 commit comments

Comments
 (0)