diff mercurial/revsetlang.py @ 35056:b0790bebfcf8

revset: move weight information to predicate Previously revset weight is hardcoded and cannot be modified. This patch moves it to predicate so newly registered revsets could define their weight to properly give static optimization some hint. Differential Revision: https://phab.mercurial-scm.org/D657
author Jun Wu <quark@fb.com>
date Fri, 01 Sep 2017 19:42:09 -0700 (2017-09-02)
parents 53fb09c73ba8
children dd911f95cbda
line wrap: on
line diff
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -49,6 +49,8 @@
 
 keywords = {'and', 'or', 'not'}
 
+symbols = {}
+
 _quoteletters = {'"', "'"}
 _simpleopletters = set(pycompat.iterbytestr("()[]#:=,-|&+!~^%"))
 
@@ -441,21 +443,7 @@
     elif op == 'func':
         f = getsymbol(x[1])
         wa, ta = _optimize(x[2])
-        if f in ('author', 'branch', 'closed', 'date', 'desc', 'file', 'grep',
-                 'keyword', 'outgoing', 'user', 'destination'):
-            w = 10 # slow
-        elif f in ('modifies', 'adds', 'removes'):
-            w = 30 # slower
-        elif f == "contains":
-            w = 100 # very slow
-        elif f == "ancestor":
-            w = 0.5
-        elif f in ('reverse', 'limit', 'first', 'wdir', '_intlist'):
-            w = 0
-        elif f == "sort":
-            w = 10 # assume most sorts look at changelog
-        else:
-            w = 1
+        w = getattr(symbols.get(f), '_weight', 1)
         return w + wa, (op, x[1], ta)
     raise ValueError('invalid operator %r' % op)