diff options
author | Andrey Nazarov <skuller@skuller.net> | 2012-08-03 21:41:38 +0400 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2012-08-03 21:41:38 +0400 |
commit | 1a0f3820a8b34c976d9a2842f50914a38b511749 (patch) | |
tree | bfef76b3978d730771ed54d1ee38776f82afb52c | |
parent | 92101f85480cdf6cffabaf9f68048d37c8c97e55 (diff) |
Try to avoid calling stat() when listing files.
-rw-r--r-- | src/unix/system.c | 21 |
1 files changed, 14 insertions, 7 deletions
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); } |