Skip to content

Commit

Permalink
make unused_name() faster
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgio Gonnella committed May 3, 2017
1 parent 64fbc16 commit e71793f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gfapy/gfa.py
Expand Up @@ -31,7 +31,7 @@ def __init__(self, *args, vlevel = 1, version = None):
if not version in ['gfa1', 'gfa2', None]:
raise gfapy.VersionError("GFA version unknown ({})".format(version))
self._vlevel = vlevel
self._unused_name_cache = 1
self._max_int_name = 0
self._records = defaultdict(dict)
self._records["H"] = gfapy.line.Header(["H"], vlevel = vlevel)
self._records["H"].connect(self)
Expand Down
9 changes: 2 additions & 7 deletions gfapy/lines/collections.py
Expand Up @@ -240,13 +240,8 @@ def names(self):

def unused_name(self):
"""Compute a GFA identifier not yet in use in the Gfa object."""
names = self.names
name = str(self._unused_name_cache)
while name in names:
self._unused_name_cache += 1
name = str(self._unused_name_cache)
self._unused_name_cache += 1
return name
self._max_int_name += 1
return str(self._max_int_name)

@property
def external_names(self):
Expand Down
4 changes: 4 additions & 0 deletions gfapy/lines/creators.py
Expand Up @@ -59,6 +59,10 @@ def _register_line(self, gfa_line):
key = gfa_line.name
if gfapy.is_placeholder(key):
key = id(gfa_line)
elif key.isdigit():
keynum = int(key)
if keynum > self._max_int_name:
self._max_int_name = keynum
self._records[gfa_line.record_type][key] = gfa_line
elif storage_key == "external":
if gfa_line.external.line not in self._records[gfa_line.record_type]:
Expand Down

0 comments on commit e71793f

Please sign in to comment.