improve util.parse_range() performance
It is never going to actually matter, but using partition() instead of split() is twice as fast.
This commit is contained in:
@@ -35,14 +35,13 @@ def parse_range(rangespec):
|
|||||||
ranges = []
|
ranges = []
|
||||||
|
|
||||||
for group in rangespec.split(","):
|
for group in rangespec.split(","):
|
||||||
parts = group.split("-", maxsplit=1)
|
first, sep, last = group.partition("-")
|
||||||
try:
|
try:
|
||||||
if len(parts) == 1:
|
if not sep:
|
||||||
beg = int(parts[0])
|
beg = end = int(first)
|
||||||
end = beg
|
|
||||||
else:
|
else:
|
||||||
beg = int(parts[0]) if parts[0].strip() else 1
|
beg = int(first) if first.strip() else 1
|
||||||
end = int(parts[1]) if parts[1].strip() else sys.maxsize
|
end = int(last) if last.strip() else sys.maxsize
|
||||||
ranges.append((beg, end) if beg <= end else (end, beg))
|
ranges.append((beg, end) if beg <= end else (end, beg))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user