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

🐛 Don't cache dict in bibdatabase #348

Merged
merged 2 commits into from
Jan 3, 2023
Merged
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
16 changes: 7 additions & 9 deletions bibtexparser/bibdatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,15 @@ def entry_sort_key(entry, fields):
result.append(str(entry.get(field, '')).lower()) # Sorting always as string
return tuple(result)

def _make_entries_dict(self):
for entry in self.entries:
self._entries_dict[entry['ID']] = entry

def get_entry_dict(self):
"""Return a dictionary of BibTeX entries.
The dict key is the BibTeX entry key
"""Return a dictionary of BibTeX entries, where dict key is the BibTeX entry key.

This method re-creates the dict every time it is called,
hence subsequent calls should be avoided with large databases.
"""
# If the hash has never been made, make it
if not self._entries_dict:
self._make_entries_dict()
self._entries_dict = dict()
for entry in self.entries:
self._entries_dict[entry['ID']] = entry
return self._entries_dict

entries_dict = property(get_entry_dict)
Expand Down