From b2735927060a866ff863370a20f00f3a5e73ef38 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 22 Apr 2016 06:21:33 -0700 Subject: Optimization in path-private-to-me-p. * share/txr/stdlib/path-test.tl (path-private-to-me-p): Use mlet to initialize the g variable lazily, so that getgrgid is only called when g is used. getgrid is a fairly heavy-weight function, and it's only used to resolve the case when a file is writable to the group owner (is the user the only member of that group?) --- share/txr/stdlib/path-test.tl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/share/txr/stdlib/path-test.tl b/share/txr/stdlib/path-test.tl index bc71cc4c..851ac61b 100644 --- a/share/txr/stdlib/path-test.tl +++ b/share/txr/stdlib/path-test.tl @@ -100,14 +100,14 @@ (defun path-private-to-me-p (path) (sys:path-test (s stat path) (let ((m s.mode) - (euid (geteuid)) - (g (getgrgid s.gid))) - (and (eql euid s.uid) - (zerop (logand m s-iwoth)) - (or (zerop (logand m s-iwgrp)) - (null g.mem) - (and (not (rest g.mem)) - (equal (getpwuid euid).name (first g.mem)))))))) + (euid (geteuid))) + (mlet ((g (getgrgid s.gid))) + (and (eql euid s.uid) + (zerop (logand m s-iwoth)) + (or (zerop (logand m s-iwgrp)) + (null g.mem) + (and (not (rest g.mem)) + (equal (getpwuid euid).name (first g.mem))))))))) (defmacro sys:path-examine ((var statfun path) . body) ^[sys:do-path-test ,statfun ,path -- cgit v1.2.3