From: Pádraig Brady
Date: Thu, 29 May 2014 15:44:50 +0000 (+0100) Subject: stat: avoid redundant stat() calls X-Git-Tag: v8.23~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39d1c9576a3f2e5e65c5fb06744aa7245d743bc0;p=thirdparty%2Fcoreutils.git stat: avoid redundant stat() calls * src/stat.c (find_bind_mount): NAME is invariant in the loop, so only stat(NAME) outside the loop. --- diff --git a/src/stat.c b/src/stat.c index 6f42b61bd3..0f67d22dfe 100644 --- a/src/stat.c +++ b/src/stat.c @@ -841,17 +841,19 @@ find_bind_mount (char const * name) tried_mount_list = true; } + struct stat name_stats; + if (stat (name, &name_stats) != 0) + return NULL; + struct mount_entry *me; for (me = mount_list; me; me = me->me_next) { if (me->me_dummy && me->me_devname[0] == '/' && STREQ (me->me_mountdir, name)) { - struct stat name_stats; struct stat dev_stats; - if (stat (name, &name_stats) == 0 - && stat (me->me_devname, &dev_stats) == 0 + if (stat (me->me_devname, &dev_stats) == 0 && SAME_INODE (name_stats, dev_stats)) { bind_mount = me->me_devname;