Skip to content

Commit

Permalink
Avoid hasattr in hot loop in brotli decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
auscompgeek committed Apr 19, 2020
1 parent 1f0825b commit 63730ad
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/urllib3/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ class BrotliDecoder(object):
# are for 'brotlipy' and bottom branches for 'Brotli'
def __init__(self):
self._obj = brotli.Decompressor()

def decompress(self, data):
if hasattr(self._obj, "decompress"):
return self._obj.decompress(data)
return self._obj.process(data)

self.decompress = self._obj.decompress
else:
self.decompress = self._obj.process

def flush(self):
if hasattr(self._obj, "flush"):
return self._obj.flush()
Expand Down

0 comments on commit 63730ad

Please sign in to comment.