# HG changeset patch # User Franz Glasner # Date 1644353114 -3600 # Node ID 21d2589c96b9c1de12f15a360eb7f88c861ceae8 # Parent b96d3585e8ced173aad281bcc94ce627745689e8 Use madvise if available to sequentially read a file diff -r b96d3585e8ce -r 21d2589c96b9 shasum.py --- a/shasum.py Tue Feb 08 21:27:13 2022 +0100 +++ b/shasum.py Tue Feb 08 21:45:14 2022 +0100 @@ -481,6 +481,10 @@ # NOTE: On Windows mmapped files with length 0 are not supported. # So ensure to not call mmap.mmap() if the file size is 0. # + try: + madvise = mmap.mmap.madvise + except AttributeError: + madvise = None if filesize < MAP_CHUNK_SIZE: mapsize = filesize else: @@ -492,6 +496,8 @@ mapsize, access=mmap.ACCESS_READ, offset=mapoffset) + if madvise: + madvise(m, mmap.MADV_SEQUENTIAL) try: h.update(m) finally: