##// END OF EJS Templates
grep: speed up matching, and only return one match per line.
bos@serpentine.internal.keyresearch.com -
r1059:4eab07ef default
parent child Browse files
Show More
@@ -806,13 +806,17 b' def grep(ui, repo, pattern = None, *pats'
806 return fcache[fn]
806 return fcache[fn]
807
807
808 def matchlines(body):
808 def matchlines(body):
809 # massively inefficient. rewrite.
809 begin = 0
810 for match in regexp.finditer(body):
810 linenum = 0
811 start, end = match.span()
811 while True:
812 lnum = body.count('\n', 0, start) + 1
812 match = regexp.search(body, begin)
813 lstart = body.rfind('\n', 0, start) + 1
813 if not match: break
814 lend = body.find('\n', end)
814 mstart, mend = match.span()
815 yield lnum, start - lstart, end - lstart, body[lstart:lend]
815 linenum += body.count('\n', begin, mstart) + 1
816 lstart = body.rfind('\n', begin, mstart) + 1 or begin
817 lend = body.find('\n', mend)
818 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
819 begin = lend + 1
816
820
817 class linestate:
821 class linestate:
818 def __init__(self, line, linenum, colstart, colend):
822 def __init__(self, line, linenum, colstart, colend):
General Comments 0
You need to be logged in to leave comments. Login now