summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2012-08-03 21:41:38 +0400
committerAndrey Nazarov <skuller@skuller.net>2012-08-03 21:41:38 +0400
commit1a0f3820a8b34c976d9a2842f50914a38b511749 (patch)
treebfef76b3978d730771ed54d1ee38776f82afb52c
parent92101f85480cdf6cffabaf9f68048d37c8c97e55 (diff)
Try to avoid calling stat() when listing files.
-rw-r--r--src/unix/system.c21
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);
}