From 347baf7ac504338ed747759c373e5a7bae290c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 5 Feb 2018 22:01:58 +0100 Subject: [PATCH] improve util.parse_range() performance It is never going to actually matter, but using partition() instead of split() is twice as fast. --- gallery_dl/util.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 1d9c9c66..0e42b7f5 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -35,14 +35,13 @@ def parse_range(rangespec): ranges = [] for group in rangespec.split(","): - parts = group.split("-", maxsplit=1) + first, sep, last = group.partition("-") try: - if len(parts) == 1: - beg = int(parts[0]) - end = beg + if not sep: + beg = end = int(first) else: - beg = int(parts[0]) if parts[0].strip() else 1 - end = int(parts[1]) if parts[1].strip() else sys.maxsize + beg = int(first) if first.strip() else 1 + end = int(last) if last.strip() else sys.maxsize ranges.append((beg, end) if beg <= end else (end, beg)) except ValueError: pass