aboutsummaryrefslogtreecommitdiff
path: root/dateutil/parser
diff options
context:
space:
mode:
authorPaul Ganssle <paul@ganssle.io>2018-05-07 12:01:17 -0400
committerPaul Ganssle <paul@ganssle.io>2018-05-07 12:44:28 -0400
commit16561fc99361979e88cccbd135393b06b1af7e90 (patch)
treef10f88f2b5bd2323fdee94b9fe21bebd4ccc9b9e /dateutil/parser
parent3364cdb0abcf6be4ce15ef3b2db68b35711229f5 (diff)
downloaddateutil-16561fc99361979e88cccbd135393b06b1af7e90.tar.gz
Performance improvements in resolve_from_stridxs
Diffstat (limited to 'dateutil/parser')
-rw-r--r--dateutil/parser/_parser.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/dateutil/parser/_parser.py b/dateutil/parser/_parser.py
index 04bc539..9d2bb79 100644
--- a/dateutil/parser/_parser.py
+++ b/dateutil/parser/_parser.py
@@ -458,14 +458,11 @@ class _ymd(list):
raise ValueError('Year is already set')
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
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:
# we can back out the remaining stridx value
missing = [x for x in range(3) if x not in strids.values()]
@@ -476,19 +473,21 @@ class _ymd(list):
strids[key] = val
assert len(self) == len(strids) # otherwise this should not be called
- out = {'y': None, 'm': None, 'd': None}
- out.update({key: self[strids[key]] for key in strids})
- return (out['y'], out['m'], out['d'])
+ out = {key: self[strids[key]] for key in strids}
+ return (out.get('y'), out.get('m'), out.get('d'))
def resolve_ymd(self, yearfirst, dayfirst):
len_ymd = len(self)
year, month, day = (None, None, None)
- strids = {'y': self.ystridx, 'm': self.mstridx, 'd': self.dstridx}
- strids = {key: strids[key] for key in strids if strids[key] is not None}
+ strids = (('y', self.ystridx),
+ ('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
(len(self) == 3 and len(strids) == 2)):
- return self._resolve_from_stridxs()
+ return self._resolve_from_stridxs(strids)
mstridx = self.mstridx