[PATCH 1 of 4] revset: remove redundant checks for parsed tree of alias

Yuya Nishihara yuya at tcha.org
Wed Mar 30 11:38:18 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1456730589 -32400
#      Mon Feb 29 16:23:09 2016 +0900
# Node ID 5074171ac66d513f1e4597927308920ffc654be2
# Parent  befc310bcc8a9df1051d4a800dce95d9b1c9b914
revset: remove redundant checks for parsed tree of alias

If tree is a tuple, it must have at least one element. Also the length of node
tuple is guaranteed by the syntax elements. (e.g. 'func' must have 3 items.)

This change will help inlining these trivial functions in future patches.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -340,7 +340,7 @@ def getargsdict(x, funcname, keys):
 def isvalidsymbol(tree):
     """Examine whether specified ``tree`` is valid ``symbol`` or not
     """
-    return tree[0] == 'symbol' and len(tree) > 1
+    return tree[0] == 'symbol'
 
 def getsymbol(tree):
     """Get symbol name from valid ``symbol`` in ``tree``
@@ -352,7 +352,7 @@ def getsymbol(tree):
 def isvalidfunc(tree):
     """Examine whether specified ``tree`` is valid ``func`` or not
     """
-    return tree[0] == 'func' and len(tree) > 1 and isvalidsymbol(tree[1])
+    return tree[0] == 'func' and isvalidsymbol(tree[1])
 
 def getfuncname(tree):
     """Get function name from valid ``func`` in ``tree``
@@ -366,10 +366,7 @@ def getfuncargs(tree):
 
     This assumes that ``tree`` is already examined by ``isvalidfunc``.
     """
-    if len(tree) > 2:
-        return getlist(tree[2])
-    else:
-        return []
+    return getlist(tree[2])
 
 def getset(repo, subset, x):
     if not x:
@@ -2438,14 +2435,14 @@ def _getalias(aliases, tree):
     """If tree looks like an unexpanded alias, return it. Return None
     otherwise.
     """
-    if isinstance(tree, tuple) and tree:
-        if tree[0] == 'symbol' and len(tree) == 2:
+    if isinstance(tree, tuple):
+        if tree[0] == 'symbol':
             name = tree[1]
             alias = aliases.get(name)
             if alias and alias.args is None and alias.tree == tree:
                 return alias
-        if tree[0] == 'func' and len(tree) > 1:
-            if tree[1][0] == 'symbol' and len(tree[1]) == 2:
+        if tree[0] == 'func':
+            if tree[1][0] == 'symbol':
                 name = tree[1][1]
                 alias = aliases.get(name)
                 if alias and alias.args is not None and alias.tree == tree[:2]:
@@ -2456,7 +2453,7 @@ def _expandargs(tree, args):
     """Replace _aliasarg instances with the substitution value of the
     same name in args, recursively.
     """
-    if not tree or not isinstance(tree, tuple):
+    if not isinstance(tree, tuple):
         return tree
     if tree[0] == '_aliasarg':
         sym = tree[1]


More information about the Mercurial-devel mailing list