guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/02: daemon: Micro-optimize 'deletePath'.


From: guix-commits
Subject: 01/02: daemon: Micro-optimize 'deletePath'.
Date: Fri, 19 Nov 2021 17:08:58 -0500 (EST)

civodul pushed a commit to branch master
in repository guix.

commit 24224530d1f4a70808d003ba8dce849b77625b79
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Nov 19 14:53:25 2021 +0100

    daemon: Micro-optimize 'deletePath'.
    
    'remove' calls 'unlink' first and falls back to 'rmdir' upon EISDIR.
    This change gets rid of the 'unlink' call for every directory being
    removed.
    
    * nix/libutil/util.cc (_deletePath): Call 'unlink' or 'rmdir' depending
    on 'st.st_mode', rather than call 'remove'.
---
 nix/libutil/util.cc | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc
index 69f1c63..4d3780e 100644
--- a/nix/libutil/util.cc
+++ b/nix/libutil/util.cc
@@ -337,12 +337,15 @@ static void _deletePath(const Path & path, unsigned long 
long & bytesFreed, size
         for (auto & i : readDirectory(path))
             _deletePath(path + "/" + i.name, bytesFreed, linkThreshold);
     }
+
+    int ret;
+    ret = S_ISDIR(st.st_mode) ? rmdir(path.c_str()) : unlink(path.c_str());
+    if (ret == -1)
+        throw SysError(format("cannot unlink `%1%'") % path);
+
 #undef st_mode
 #undef st_size
 #undef st_nlink
-
-    if (remove(path.c_str()) == -1)
-        throw SysError(format("cannot unlink `%1%'") % path);
 }
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]