Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor performance tweaks to _read_gzip_header
Call the bool method and cache the result for faster truth checking.
Do not test for empty bytes but use "not magic" instead for faster truth checking.
  • Loading branch information
rhpvorderman committed Nov 24, 2021
commit 3d5bb4726fd4122233849d2f47e00f97b6aff2ea
4 changes: 2 additions & 2 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def _read_gzip_header(fp):
Returns last mtime if header was present or None otherwise.
'''
magic = fp.read(2)
if magic == b'':
if not magic:
return None

if magic != b'\037\213':
Expand All @@ -432,7 +432,7 @@ def _read_gzip_header(fp):
raise BadGzipFile('Unknown compression method')

# FHCRC will be checked often. So save the result of the check.
fhcrc = flag & FHCRC
fhcrc = bool(flag & FHCRC)
# Only create and append to a list of header parts when FHCRC is set.
# In the most common use cases FHCRC is not set. So we optimize for those
# cases.
Expand Down