From 3b187f482653da01f59a9f37344d20ad7fcf3447 Mon Sep 17 00:00:00 2001 From: FRIGN Date: Thu, 12 Mar 2015 13:29:12 +0100 Subject: [PATCH] Only call recurse() when path points to a directory in du(1) This improves performance by ~30%. --- du.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/du.c b/du.c index 0c46629..ef62166 100644 --- a/du.c +++ b/du.c @@ -47,7 +47,8 @@ du(const char *path, int depth, void *total) return; } - recurse(path, du, depth, &subtotal); + if (S_ISDIR(st.st_mode)) + recurse(path, du, depth, &subtotal); *((size_t *)total) += subtotal + nblks(st.st_blocks); if (!sflag && depth <= maxdepth && (S_ISDIR(st.st_mode) || aflag))