mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 18:53:21 +01:00
improve text.extract_iter() performance
by roughly 40% through - inlining code - pre-calculating reused values - entering a try-except block only once
This commit is contained in:
parent
e25ebc4bff
commit
8f249f1d54
@ -135,12 +135,18 @@ def extract_all(txt, rules, pos=0, values=None):
|
|||||||
|
|
||||||
|
|
||||||
def extract_iter(txt, begin, end, pos=0):
|
def extract_iter(txt, begin, end, pos=0):
|
||||||
"""Yield all values obtained by repeated calls to text.extract"""
|
"""Yield values that would be returned by repeated calls of extract()"""
|
||||||
while True:
|
index = txt.index
|
||||||
value, pos = extract(txt, begin, end, pos)
|
lbeg = len(begin)
|
||||||
if value is None:
|
lend = len(end)
|
||||||
return
|
try:
|
||||||
yield value
|
while True:
|
||||||
|
first = index(begin, pos) + lbeg
|
||||||
|
last = index(end, first)
|
||||||
|
pos = last + lend
|
||||||
|
yield txt[first:last]
|
||||||
|
except (ValueError, TypeError, AttributeError):
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def parse_bytes(value, default=0, suffixes="bkmgtp"):
|
def parse_bytes(value, default=0, suffixes="bkmgtp"):
|
||||||
|
Loading…
Reference in New Issue
Block a user