Useing exists(file_status) inside exists(const path&, error_code&)
means we call status_known twice, because exists(file_status) calls it
internally. By inlining the exists(file_status) logic into the outer
function we avoid the redundant call.

        * include/bits/fs_ops.h (exists(const path&, error_code&))): Only
        check status_known once.
        * include/experimental/bits/fs_ops.h: Likewise.

Tested powerpc64le-linux, committed to trunk.

commit 7d0cc9127d8678e2b415f617ac07b74ac53fa8b9
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Jan 4 10:58:47 2018 +0000

    Avoid redundant calls to filesystem::status_known
    
            * include/bits/fs_ops.h (exists(const path&, error_code&))): Only
            check status_known once.
            * include/experimental/bits/fs_ops.h: Likewise.

diff --git a/libstdc++-v3/include/bits/fs_ops.h 
b/libstdc++-v3/include/bits/fs_ops.h
index 3c63adefca7..e61a1236bec 100644
--- a/libstdc++-v3/include/bits/fs_ops.h
+++ b/libstdc++-v3/include/bits/fs_ops.h
@@ -125,8 +125,11 @@ namespace filesystem
   {
     auto __s = status(__p, __ec);
     if (status_known(__s))
-      __ec.clear();
-    return exists(__s);
+      {
+       __ec.clear();
+       return __s.type() != file_type::not_found;
+      }
+    return false;
   }
 
   uintmax_t file_size(const path& __p);
diff --git a/libstdc++-v3/include/experimental/bits/fs_ops.h 
b/libstdc++-v3/include/experimental/bits/fs_ops.h
index e36291195bb..45192b1b34a 100644
--- a/libstdc++-v3/include/experimental/bits/fs_ops.h
+++ b/libstdc++-v3/include/experimental/bits/fs_ops.h
@@ -131,8 +131,11 @@ inline namespace v1
   {
     auto __s = status(__p, __ec);
     if (status_known(__s))
-      __ec.clear();
-    return exists(__s);
+      {
+       __ec.clear();
+       return __s.type() != file_type::not_found;
+      }
+    return false;
   }
 
   uintmax_t file_size(const path& __p);

Reply via email to