Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revset.py @ 32819:3e6f9bff7e3f
revset: filter first/last members by __and__ operation
This replaces 'if y in subset' with '& subset'. first(null) and last(wdir())
are fixed thanks to fullreposet.__and__.
This also revealed that first() and last() don't follow the order of the
input set. 'ls & subset' is valid only if the ordering requirement is 'define'
or 'any'.
No performance regression observed:
revset #0: limit(0:9999, 100, 9000)
0) 0.001164
1) 0.001135
revset #2: 9000 & limit(0:9999, 100, 9000)
0) 0.001224
1) 0.001181
revset #3: last(0:9999, 100)
0) 0.000237
1) 0.000199
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 10 Jun 2017 19:41:42 +0900 |
parents | b36ec65ea583 |
children | 348b491c0934 |
line wrap: on
line diff
--- a/mercurial/revset.py Sat Jun 10 18:35:11 2017 +0900 +++ b/mercurial/revset.py Sat Jun 10 19:41:42 2017 +0900 @@ -1179,10 +1179,9 @@ y = next(it, None) if y is None: break - elif y in subset: - result.append(y) - return baseset(result, datarepr=('<limit n=%d, offset=%d, %r, %r>', - lim, ofs, subset, os)) + result.append(y) + ls = baseset(result, datarepr=('<limit n=%d, offset=%d, %r>', lim, ofs, os)) + return ls & subset @predicate('last(set, [n])', safe=True) def last(repo, subset, x): @@ -1204,10 +1203,10 @@ y = next(it, None) if y is None: break - elif y in subset: - result.append(y) - return baseset(result[::-1], datarepr=('<last n=%d, %r, %r>', - lim, subset, os)) + result.append(y) + ls = baseset(result, datarepr=('<last n=%d, %r>', lim, os)) + ls.reverse() + return ls & subset @predicate('max(set)', safe=True) def maxrev(repo, subset, x):