Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 1059:4eab07ef66e2
grep: speed up matching, and only return one match per line.
author | bos@serpentine.internal.keyresearch.com |
---|---|
date | Thu, 25 Aug 2005 17:13:48 -0700 |
parents | 402279974aea |
children | e453d2053b2e |
comparison
equal
deleted
inserted
replaced
1058:402279974aea | 1059:4eab07ef66e2 |
---|---|
804 if fn not in fcache: | 804 if fn not in fcache: |
805 fcache[fn] = repo.file(fn) | 805 fcache[fn] = repo.file(fn) |
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): |
819 self.line = line | 823 self.line = line |
820 self.linenum = linenum | 824 self.linenum = linenum |