]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
stat: avoid redundant stat() calls
authorPádraig Brady <P@draigBrady.com>
Thu, 29 May 2014 15:44:50 +0000 (16:44 +0100)
committerPádraig Brady <P@draigBrady.com>
Sun, 1 Jun 2014 11:14:24 +0000 (12:14 +0100)
* src/stat.c (find_bind_mount): NAME is invariant in the loop,
so only stat(NAME) outside the loop.

src/stat.c

index 6f42b61bd33ea0de77533b54966c17d363203a1d..0f67d22dfee8c2c3bd84c210d6355a8fcb8ef86b 100644 (file)
@@ -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;