revsetlang: use str.find() to scan expr in formatspec()
authorYuya Nishihara <yuya@tcha.org>
Sat, 01 Apr 2017 16:55:28 +0900
changeset 35558 dfc628611144
parent 35557 2df8d12f23bc
child 35559 a480551bd1b4
revsetlang: use str.find() to scan expr in formatspec() There should be no need to walk character one by one in Python.
mercurial/revsetlang.py
--- a/mercurial/revsetlang.py	Sat Apr 01 16:50:11 2017 +0900
+++ b/mercurial/revsetlang.py	Sat Apr 01 16:55:28 2017 +0900
@@ -624,9 +624,13 @@
     pos = 0
     arg = 0
     while pos < len(expr):
-        c = expr[pos]
-        if c == '%':
-            pos += 1
+        q = expr.find('%', pos)
+        if q < 0:
+            ret.append(expr[pos:])
+            break
+        ret.append(expr[pos:q])
+        pos = q + 1
+        if True:
             d = expr[pos]
             if d == '%':
                 ret.append(d)
@@ -642,8 +646,6 @@
             else:
                 raise error.Abort(_('unexpected revspec format character %s')
                                   % d)
-        else:
-            ret.append(c)
         pos += 1
 
     return ''.join(ret)