From 15f76771009d78fbe6f8f9715080436ad9d92a68 Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Thu, 7 Jul 2022 18:52:15 +0100 Subject: Check for directories with the mode stored in the mentry Saves one call to lstat(2) per file. On my system, this improves `time bin/metastore -d /usr >/dev/null` from: real 0m2.183s user 0m0.733s sys 0m1.435s to: real 0m1.846s user 0m0.663s sys 0m1.134s Average of 5 runs, on a warm cache, reducing runtime by roughly 15%. --- src/metaentry.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'src/metaentry.c') diff --git a/src/metaentry.c b/src/metaentry.c index 146fcf9..94167e7 100644 --- a/src/metaentry.c +++ b/src/metaentry.c @@ -351,7 +351,6 @@ normalize_path(const char *orig) static void mentries_recurse(const char *path, struct metahash *mhash, msettings *st) { - struct stat sbuf; struct metaentry *mentry; char tpath[PATH_MAX]; DIR *dir; @@ -360,19 +359,13 @@ mentries_recurse(const char *path, struct metahash *mhash, msettings *st) if (!path) return; - if (lstat(path, &sbuf)) { - msg(MSG_ERROR, "lstat failed for %s: %s\n", - path, strerror(errno)); - return; - } - mentry = mentry_create(path); if (!mentry) return; mentry_insert(mentry, mhash); - if (S_ISDIR(sbuf.st_mode)) { + if (S_ISDIR(mentry->mode)) { dir = opendir(path); if (!dir) { msg(MSG_ERROR, "opendir failed for %s: %s\n", -- cgit v1.2.1