Skip to content
Snippets Groups Projects
Commit 6b0fc9b73d6a authored by Paul Ganssle's avatar Paul Ganssle
Browse files

Performance improvements in resolve_from_stridxs

parent 171626906013
No related branches found
No related tags found
No related merge requests found
...@@ -458,8 +458,8 @@ ...@@ -458,8 +458,8 @@
raise ValueError('Year is already set') raise ValueError('Year is already set')
self.ystridx = len(self) - 1 self.ystridx = len(self) - 1
def _resolve_from_stridxs(self): def _resolve_from_stridxs(self, strids):
""" """
Try to resolve the identities of year/month/day elements using Try to resolve the identities of year/month/day elements using
ystridx, mstridx, and dstridx, if enough of these are specified. ystridx, mstridx, and dstridx, if enough of these are specified.
""" """
...@@ -462,10 +462,7 @@ ...@@ -462,10 +462,7 @@
""" """
Try to resolve the identities of year/month/day elements using Try to resolve the identities of year/month/day elements using
ystridx, mstridx, and dstridx, if enough of these are specified. ystridx, mstridx, and dstridx, if enough of these are specified.
""" """
strids = {'y': self.ystridx, 'm': self.mstridx, 'd': self.dstridx}
strids = {key: strids[key] for key in strids if strids[key] is not None}
if len(self) == 3 and len(strids) == 2: if len(self) == 3 and len(strids) == 2:
# we can back out the remaining stridx value # we can back out the remaining stridx value
missing = [x for x in range(3) if x not in strids.values()] missing = [x for x in range(3) if x not in strids.values()]
...@@ -476,11 +473,10 @@ ...@@ -476,11 +473,10 @@
strids[key] = val strids[key] = val
assert len(self) == len(strids) # otherwise this should not be called assert len(self) == len(strids) # otherwise this should not be called
out = {'y': None, 'm': None, 'd': None} out = {key: self[strids[key]] for key in strids}
out.update({key: self[strids[key]] for key in strids}) return (out.get('y'), out.get('m'), out.get('d'))
return (out['y'], out['m'], out['d'])
def resolve_ymd(self, yearfirst, dayfirst): def resolve_ymd(self, yearfirst, dayfirst):
len_ymd = len(self) len_ymd = len(self)
year, month, day = (None, None, None) year, month, day = (None, None, None)
...@@ -482,9 +478,12 @@ ...@@ -482,9 +478,12 @@
def resolve_ymd(self, yearfirst, dayfirst): def resolve_ymd(self, yearfirst, dayfirst):
len_ymd = len(self) len_ymd = len(self)
year, month, day = (None, None, None) year, month, day = (None, None, None)
strids = {'y': self.ystridx, 'm': self.mstridx, 'd': self.dstridx} strids = (('y', self.ystridx),
strids = {key: strids[key] for key in strids if strids[key] is not None} ('m', self.mstridx),
('d', self.dstridx))
strids = {key: val for key, val in strids if val is not None}
if (len(self) == len(strids) > 0 or if (len(self) == len(strids) > 0 or
(len(self) == 3 and len(strids) == 2)): (len(self) == 3 and len(strids) == 2)):
...@@ -489,6 +488,6 @@ ...@@ -489,6 +488,6 @@
if (len(self) == len(strids) > 0 or if (len(self) == len(strids) > 0 or
(len(self) == 3 and len(strids) == 2)): (len(self) == 3 and len(strids) == 2)):
return self._resolve_from_stridxs() return self._resolve_from_stridxs(strids)
mstridx = self.mstridx mstridx = self.mstridx
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment