mirror of
https://github.com/cuberite/libdeflate.git
synced 2025-09-10 04:41:45 -04:00
programs: use sequential file access hints
This commit is contained in:
parent
3c1077a4b3
commit
94145eb14e
@ -27,6 +27,8 @@ check_function() {
|
|||||||
check_function clock_gettime
|
check_function clock_gettime
|
||||||
check_function futimens
|
check_function futimens
|
||||||
check_function futimes
|
check_function futimes
|
||||||
|
check_function posix_fadvise
|
||||||
|
check_function posix_madvise
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "#endif /* _CONFIG_H */"
|
echo "#endif /* _CONFIG_H */"
|
||||||
|
@ -39,6 +39,16 @@
|
|||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef O_BINARY
|
||||||
|
# define O_BINARY 0
|
||||||
|
#endif
|
||||||
|
#ifndef O_NOFOLLOW
|
||||||
|
# define O_NOFOLLOW 0
|
||||||
|
#endif
|
||||||
|
#ifndef O_SEQUENTIAL
|
||||||
|
# define O_SEQUENTIAL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/* The invocation name of the program (filename component only) */
|
/* The invocation name of the program (filename component only) */
|
||||||
const tchar *program_invocation_name;
|
const tchar *program_invocation_name;
|
||||||
|
|
||||||
@ -173,13 +183,17 @@ xopen_for_read(const tchar *path, struct file_stream *strm)
|
|||||||
if (strm->name == NULL)
|
if (strm->name == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
strm->fd = topen(path, O_RDONLY | O_BINARY | O_NOFOLLOW);
|
strm->fd = topen(path, O_RDONLY | O_BINARY | O_NOFOLLOW | O_SEQUENTIAL);
|
||||||
if (strm->fd < 0) {
|
if (strm->fd < 0) {
|
||||||
msg_errno("Can't open %"TS" for reading", strm->name);
|
msg_errno("Can't open %"TS" for reading", strm->name);
|
||||||
free(strm->name);
|
free(strm->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_POSIX_FADVISE) && (O_SEQUENTIAL == 0)
|
||||||
|
posix_fadvise(strm->fd, 0, 0, POSIX_FADV_SEQUENTIAL);
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +281,7 @@ map_file_contents(struct file_stream *strm, u64 size)
|
|||||||
CloseHandle((HANDLE)strm->mmap_token);
|
CloseHandle((HANDLE)strm->mmap_token);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else /* _WIN32 */
|
||||||
strm->mmap_mem = mmap(NULL, size, PROT_READ, MAP_SHARED, strm->fd, 0);
|
strm->mmap_mem = mmap(NULL, size, PROT_READ, MAP_SHARED, strm->fd, 0);
|
||||||
if (strm->mmap_mem == MAP_FAILED) {
|
if (strm->mmap_mem == MAP_FAILED) {
|
||||||
strm->mmap_mem = NULL;
|
strm->mmap_mem = NULL;
|
||||||
@ -280,7 +294,12 @@ map_file_contents(struct file_stream *strm, u64 size)
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_POSIX_MADVISE
|
||||||
|
posix_madvise(strm->mmap_mem, size, POSIX_MADV_SEQUENTIAL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* !_WIN32 */
|
||||||
strm->mmap_size = size;
|
strm->mmap_size = size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,6 @@ extern int wmain(int argc, wchar_t **argv);
|
|||||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||||
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||||
# endif
|
# endif
|
||||||
# define O_NOFOLLOW 0
|
|
||||||
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
|
||||||
@ -111,7 +110,6 @@ extern int wmain(int argc, wchar_t **argv);
|
|||||||
# define tunlink unlink
|
# define tunlink unlink
|
||||||
# define tutimbuf utimbuf
|
# define tutimbuf utimbuf
|
||||||
# define tutime utime
|
# define tutime utime
|
||||||
# define O_BINARY 0
|
|
||||||
|
|
||||||
#endif /* !_WIN32 */
|
#endif /* !_WIN32 */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user