Skip to content

Commit b9594d4

Browse files
committed
Perhaps slightly faster - skip unnecessary breaking up non-tuples
1 parent aca6593 commit b9594d4

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎stanza/models/common/doc.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,11 +1529,18 @@ def _init_deps(self, value):
15291529
value = value.split("|")
15301530
if all(isinstance(x, str) for x in value):
15311531
value = [x.split(":", maxsplit=1) for x in value]
1532+
word_id = self.id
1533+
add_edge = graph.add_edge
15321534
for parent, dep in value:
1533-
parent = tuple(map(int, parent.split(".", maxsplit=1)))
1534-
if len(parent) == 1:
1535-
parent = parent[0]
1536-
graph.add_edge(parent, self.id, dep)
1535+
# only an empty node has a . in its id, and those are rare, so the
1536+
# common case skips building a tuple just to unpack it again
1537+
if "." in parent:
1538+
parent = tuple(map(int, parent.split(".", maxsplit=1)))
1539+
if len(parent) == 1:
1540+
parent = parent[0]
1541+
else:
1542+
parent = int(parent)
1543+
add_edge(parent, word_id, dep)
15371544

15381545
@property
15391546
def manual_expansion(self):

0 commit comments

Comments
 (0)