Skip to content

Commit 3d5bb47

Browse files
committed
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.
1 parent 617e064 commit 3d5bb47

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Lib/gzip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def _read_gzip_header(fp):
421421
Returns last mtime if header was present or None otherwise.
422422
'''
423423
magic = fp.read(2)
424-
if magic == b'':
424+
if not magic:
425425
return None
426426

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

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

0 commit comments

Comments
 (0)