We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4a86e1d commit bf9f44dCopy full SHA for bf9f44d
1 file changed
tdl/__init__.py
@@ -116,12 +116,18 @@ def _format_char(char):
116
_utf32_codec = {'little': 'utf-32le', 'big': 'utf-32le'}[_sys.byteorder]
117
118
def _format_str(string):
119
- if isinstance(string, str):
120
- array = _array.array('I')
+ """Attempt fast string handing by decoding directly into an array."""
+ if isinstance(string, _STRTYPES):
121
if _IS_PYTHON3:
122
+ array = _array.array('I')
123
array.frombytes(string.encode(_utf32_codec))
- else:
124
- array.fromstring(string.encode(_utf32_codec))
+ else: # Python 2
125
+ if isinstance(string, unicode):
126
+ array = _array.array(b'I')
127
+ array.fromstring(string.encode(_utf32_codec))
128
+ else:
129
+ array = _array.array(b'B')
130
+ array.fromstring(string)
131
return array
132
return string
133
0 commit comments