Skip to content

Commit b936dfc

Browse files
committed
speed improvement
cache the merged set of all name part constants
1 parent 096a603 commit b936dfc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

nameparser/config/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,13 @@ def __init__(self,
152152
self.conjunctions = SetManager(conjunctions)
153153
self.capitalization_exceptions = TupleManager(capitalization_exceptions)
154154
self.regexes = TupleManager(regexes)
155+
self._pst = None
155156

156157
@property
157158
def suffixes_prefixes_titles(self):
158-
return self.prefixes | self.suffixes | self.titles
159+
if not self._pst:
160+
self._pst = self.prefixes | self.suffixes | self.titles
161+
return self._pst
159162

160163
def __repr__(self):
161164
return "<Constants() instance>"

nameparser/parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,9 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0):
550550
# loop through the pieces backwards, starting at the end of the list.
551551
# Join conjunctions to the pieces on either side of them.
552552

553-
if len(conj) == 1 and \
554-
len(list(filter(self.is_rootname, pieces))) + additional_parts_count < 4:
553+
rootname_pieces = [p for p in pieces if self.is_rootname(p)]
554+
total_length= len(rootname_pieces) + additional_parts_count
555+
if len(conj) == 1 and total_length < 4:
555556
# if there are only 3 total parts (minus known titles, suffixes and prefixes)
556557
# and this conjunction is a single letter, prefer treating it as an initial
557558
# rather than a conjunction.

0 commit comments

Comments
 (0)