46 "string": (0, "string", None, None, None), |
46 "string": (0, "string", None, None, None), |
47 "end": (0, None, None, None, None), |
47 "end": (0, None, None, None, None), |
48 } |
48 } |
49 |
49 |
50 keywords = {'and', 'or', 'not'} |
50 keywords = {'and', 'or', 'not'} |
|
51 |
|
52 symbols = {} |
51 |
53 |
52 _quoteletters = {'"', "'"} |
54 _quoteletters = {'"', "'"} |
53 _simpleopletters = set(pycompat.iterbytestr("()[]#:=,-|&+!~^%")) |
55 _simpleopletters = set(pycompat.iterbytestr("()[]#:=,-|&+!~^%")) |
54 |
56 |
55 # default set of valid characters for the initial letter of symbols |
57 # default set of valid characters for the initial letter of symbols |
439 w, t = _optimize(x[2]) |
441 w, t = _optimize(x[2]) |
440 return w, (op, x[1], t) |
442 return w, (op, x[1], t) |
441 elif op == 'func': |
443 elif op == 'func': |
442 f = getsymbol(x[1]) |
444 f = getsymbol(x[1]) |
443 wa, ta = _optimize(x[2]) |
445 wa, ta = _optimize(x[2]) |
444 if f in ('author', 'branch', 'closed', 'date', 'desc', 'file', 'grep', |
446 w = getattr(symbols.get(f), '_weight', 1) |
445 'keyword', 'outgoing', 'user', 'destination'): |
|
446 w = 10 # slow |
|
447 elif f in ('modifies', 'adds', 'removes'): |
|
448 w = 30 # slower |
|
449 elif f == "contains": |
|
450 w = 100 # very slow |
|
451 elif f == "ancestor": |
|
452 w = 0.5 |
|
453 elif f in ('reverse', 'limit', 'first', 'wdir', '_intlist'): |
|
454 w = 0 |
|
455 elif f == "sort": |
|
456 w = 10 # assume most sorts look at changelog |
|
457 else: |
|
458 w = 1 |
|
459 return w + wa, (op, x[1], ta) |
447 return w + wa, (op, x[1], ta) |
460 raise ValueError('invalid operator %r' % op) |
448 raise ValueError('invalid operator %r' % op) |
461 |
449 |
462 def optimize(tree): |
450 def optimize(tree): |
463 """Optimize evaluatable tree |
451 """Optimize evaluatable tree |