comparison mercurial/pycompat.py @ 31425:63a39d647888

py3: make py3 compat.iterbytestr simpler and faster With Python 3.4.3, timit says 11.9 usec-> 6.44 usec. With Python 3.6.0, timeit says 14.1 usec -> 9.55 usec.
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 15 Mar 2017 09:32:18 -0700
parents 4acc49335a6e
children b70407bd84d5
comparison
equal deleted inserted replaced
31424:4acc49335a6e 31425:63a39d647888
76 76
77 bytechr = struct.Struct('>B').pack 77 bytechr = struct.Struct('>B').pack
78 78
79 def iterbytestr(s): 79 def iterbytestr(s):
80 """Iterate bytes as if it were a str object of Python 2""" 80 """Iterate bytes as if it were a str object of Python 2"""
81 return iter(s[i:i + 1] for i in range(len(s))) 81 return map(bytechr, s)
82 82
83 def sysstr(s): 83 def sysstr(s):
84 """Return a keyword str to be passed to Python functions such as 84 """Return a keyword str to be passed to Python functions such as
85 getattr() and str.encode() 85 getattr() and str.encode()
86 86