Skip to content

Commit

Permalink
Move lru_cache definitions to __init__ (#17)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Miauwkeru committed Feb 20, 2024
1 parent 15f3c77 commit 006637e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dissect/vmfs/vmfs.py
Expand Up @@ -155,6 +155,8 @@ def __init__(self, volume=None, vh=None, fdc=None, fbb=None, sbc=None, pbc=None,
self.fh.seek(fdc_base * self.block_size)
self.resources.open(ResourceType.FD, fileobj=BytesIO(self.fh.read(self.block_size)))

self.file_descriptor = lru_cache(4096)(self.file_descriptor)

# Open the root directory
self.root = self.file_descriptor(c_vmfs.ROOT_DIR_DESC_ADDR, "/")

Expand Down Expand Up @@ -250,7 +252,6 @@ def get(self, path, node=None):

return node

@lru_cache(maxsize=4096)
def file_descriptor(self, address, name=None, filetype=None):
if address_type(address) != ResourceType.FD:
raise TypeError(f"Invalid block type: {address_fmt(self, address)}")
Expand Down

0 comments on commit 006637e

Please sign in to comment.