Mercurial > hgrepos > Python > apps > py-cutils
changeset 60:21d2589c96b9
Use madvise if available to sequentially read a file
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 08 Feb 2022 21:45:14 +0100 |
| parents | b96d3585e8ce |
| children | c9f9401abc0c |
| files | shasum.py |
| diffstat | 1 files changed, 6 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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:
