Skip to content

Commit

Permalink
Speed up pp files counter using the d_type field of dirent structs
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-arch committed Mar 28, 2024
1 parent 4d1ee2a commit 37ebf33
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,6 @@ dir_info(const char *dir, int *status, struct dir_info_t *info)
return;
}

struct stat a;
DIR *p;

if ((p = opendir(dir)) == NULL) {
Expand All @@ -1729,6 +1728,19 @@ dir_info(const char *dir, int *status, struct dir_info_t *info)
if (SELFORPARENT(ent->d_name))
continue;

#if defined(_DIRENT_HAVE_D_TYPE)
if (ent->d_type == DT_DIR) {
info->dirs++;
char buf[PATH_MAX + 1];
snprintf(buf, sizeof(buf), "%s/%s", dir, ent->d_name);
dir_info(buf, status, info);
} else if (ent->d_type == DT_LNK) {
info->links++;
} else {
info->files++;
}
#else
struct stat a;
char buf[PATH_MAX + 1];
snprintf(buf, sizeof(buf), "%s/%s", dir, ent->d_name);

Expand All @@ -1748,6 +1760,7 @@ dir_info(const char *dir, int *status, struct dir_info_t *info)
} else {
info->files++;
}
#endif /* _DIRENT_HAVE_D_TYPE */
}

closedir(p);
Expand Down

0 comments on commit 37ebf33

Please sign in to comment.