From 1a0f3820a8b34c976d9a2842f50914a38b511749 Mon Sep 17 00:00:00 2001 From: Andrey Nazarov Date: Fri, 3 Aug 2012 21:41:38 +0400 Subject: Try to avoid calling stat() when listing files. --- src/unix/system.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/unix/system.c') diff --git a/src/unix/system.c b/src/unix/system.c index 33e8243..b51be6c 100644 --- a/src/unix/system.c +++ b/src/unix/system.c @@ -780,11 +780,6 @@ MISC =============================================================================== */ -static void *copy_info(const char *name, const struct stat *st) -{ - return FS_CopyInfo(name, st->st_size, st->st_ctime, st->st_mtime); -} - /* ================= Sys_ListFiles_r @@ -826,7 +821,16 @@ void Sys_ListFiles_r(const char *path, continue; } - if (stat(fullpath, &st) == -1) { + st.st_mode = 0; + +#ifdef _DIRENT_HAVE_D_TYPE + // try to avoid stat() if possible + if (!(flags & FS_SEARCH_EXTRAINFO)) { + st.st_mode = DTTOIF(ent->d_type); + } +#endif + + if (st.st_mode == 0 && stat(fullpath, &st) == -1) { continue; } @@ -884,7 +888,10 @@ void Sys_ListFiles_r(const char *path, // copy info off if (flags & FS_SEARCH_EXTRAINFO) { - info = copy_info(name, &st); + info = FS_CopyInfo(name, + st.st_size, + st.st_ctime, + st.st_mtime); } else { info = FS_CopyString(name); } -- cgit v1.2.3