changeset 35558:dfc628611144

revsetlang: use str.find() to scan expr in formatspec() There should be no need to walk character one by one in Python.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 01 Apr 2017 16:55:28 +0900
parents 2df8d12f23bc
children a480551bd1b4
files mercurial/revsetlang.py
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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)