tgrep.py: rewrite _treepositions_no_leaves to be faster