Comments
Patch
@@ -16,6 +16,8 @@ import encoding
import obsolete as obsmod
import pathutil
import repoview
+import sys
+import util
def _revancestors(repo, revs, followfirst):
"""Like revlog.ancestors(), but supports followfirst."""
@@ -2194,6 +2196,33 @@ def funcsused(tree):
funcs.add(tree[1][1])
return funcs
+def _optimize_and(iterate, check):
+ """Return the given sets in the optimal order for iterating and checking
+ containment. The iterate set is the first return arg, the check set is the
+ second.
+ """
+ if util.safehasattr(iterate, '__length_hint__'):
+ ilen = iterate.__length_hint__()
+ elif util.safehasattr(iterate, '__len__'):
+ ilen = len(iterate)
+ else:
+ ilen = sys.maxint
+
+ if util.safehasattr(check, '__length_hint__'):
+ clen = check.__length_hint__()
+ elif util.safehasattr(check, '__len__'):
+ clen = len(check)
+ else:
+ clen = sys.maxint
+
+ # Don't reorder if the `check` is a set. Many revsets assume the result will
+ # be a smart class, and if we reorder such that there is a set on the left
+ # of a X & Y expression, the result is a set, which breaks things.
+ if ilen > clen and not isinstance(check, set):
+ return check, iterate
+ else:
+ return iterate, check
+
class baseset(list):
"""Basic data structure that represents a revset and contains the basic
operation that it should be able to perform.