Skip to content
Myr

Avoid `hasattr` in hot loop in Brotli decoder (#906)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Vo · committed by GitHub · parent 4c01117 · Browse files · 1 file+5 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−3 removed

  • other:+5 added−3 removed

1 file+5 added−3 removed

modified:httpx/_decoders.py+5 added-3 removed
103 unmodified lines
104 brotli is not None105 ), "The 'brotlipy' or 'brotli' library must be installed to use 'BrotliDecoder'"106 self.decompressor = brotli.Decompressor()107 self.seen_data = False108 if hasattr(self.decompressor, "decompress"):109 self._decompress = self.decompressor.decompress110 else:111 self._decompress = self.decompressor.process # pragma: nocover112113 def decode(self, data: bytes) -> bytes:114 if not data:115 return b""116 self.seen_data = True117 try:114 if hasattr(self.decompressor, "decompress"):115 return self.decompressor.decompress(data)118 return self._decompress(data)116 return self.decompressor.process(data) # pragma: nocover119 except brotli.error as exc:120 raise DecodingError from exc121122 def flush(self) -> bytes:
170 unmodified lines