Skip to content

Commit 10a3fae

Browse files
committed
even faster
1 parent 2b2421a commit 10a3fae

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/hpack/hpack.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,12 @@ def _to_bytes(string):
147147
"""
148148
Convert string to bytes.
149149
"""
150-
if isinstance(string, bytes):
150+
t = type(string)
151+
if t is bytes:
151152
return string
152-
153-
# Not doing an `isinstance(string, basestring)` check here
154-
# as the cost of it is the same as just running `str()` on
155-
# an object that is already a string
156-
return str(string).encode("utf-8")
153+
if t is not str:
154+
string = str(string)
155+
return string.encode("utf-8")
157156

158157

159158
class Encoder:

0 commit comments

Comments
 (0)