Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move lru_cache definitions to __init__ #18

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dissect/cim/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class Index:
def __init__(self, cim, fh, mapping):
self.store = Store(cim, fh, mapping)

self._lookup = lru_cache(1024)(self._lookup)

def lookup(self, key):
return self._lookup(str(key), self.store.root_page)

@lru_cache(1024)
def _lookup(self, key, page):
matches = []

Expand Down Expand Up @@ -94,6 +95,8 @@ def __init__(self, store, fh, logical_num, page_num):

self.count = self.page.record_count

self.key = lru_cache(256)(self.key)

def _string_part(self, idx):
offset = self.page.string_table[idx]
return self.data[offset : self.data.find(b"\x00", offset)].decode("utf8")
Expand All @@ -108,7 +111,6 @@ def string(self, idx):

return "/".join(parts)

@lru_cache(256)
def key(self, idx):
str_idx = self.page.keys[idx]
key_idx = self.string(str_idx)
Expand Down
3 changes: 2 additions & 1 deletion dissect/cim/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def __init__(self, cim, fh):

self._reverse_map = {}

self.get_entry = lru_cache(256)(self.get_entry)

def __getitem__(self, k):
if not isinstance(k, int):
raise ValueError("Invalid type")
Expand All @@ -31,7 +33,6 @@ def _generate_reverse_map(self):

self._reverse_map[pnum] = i

@lru_cache(256)
def get_entry(self, logical_num):
if logical_num > self.mapping.mapping_entry_count:
raise IndexError(logical_num)
Expand Down
Loading