Skip to content

Commit ce64adf

Browse files
authored
🐛 Don't cache dict in bibdatabase (#348)
Attention: Multiple calls to get_entries_dict() now lead to multiple creations of the dict. For huge databases, one may thus want to avoid doing that.
1 parent 2d6c9ce commit ce64adf

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

bibtexparser/bibdatabase.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,15 @@ def entry_sort_key(entry, fields):
8686
result.append(str(entry.get(field, '')).lower()) # Sorting always as string
8787
return tuple(result)
8888

89-
def _make_entries_dict(self):
90-
for entry in self.entries:
91-
self._entries_dict[entry['ID']] = entry
92-
9389
def get_entry_dict(self):
94-
"""Return a dictionary of BibTeX entries.
95-
The dict key is the BibTeX entry key
90+
"""Return a dictionary of BibTeX entries, where dict key is the BibTeX entry key.
91+
92+
This method re-creates the dict every time it is called,
93+
hence subsequent calls should be avoided with large databases.
9694
"""
97-
# If the hash has never been made, make it
98-
if not self._entries_dict:
99-
self._make_entries_dict()
95+
self._entries_dict = dict()
96+
for entry in self.entries:
97+
self._entries_dict[entry['ID']] = entry
10098
return self._entries_dict
10199

102100
entries_dict = property(get_entry_dict)

0 commit comments

Comments
 (0)