[PATCH 1/4] ls command: call stat() only when necessary

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

 



When calling ls in short mode we do not have to call stat()
for additional informations because we do not use them. This
speeds up ls on filesystems on which stat() is expensive
because the barebox filesystem support always has to iterate
over the directory tree.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 commands/ls.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/commands/ls.c b/commands/ls.c
index 1fdb244..f2d9903 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -73,12 +73,13 @@ int ls(const char *path, ulong flags)
 
 	while ((d = readdir(dir))) {
 		sprintf(tmp, "%s/%s", path, d->d_name);
-		if (lstat(tmp, &s))
-			goto out;
-		if (flags & LS_COLUMN)
+		if (flags & LS_COLUMN) {
 			string_list_add_sorted(&sl, d->d_name);
-		else
+		} else {
+			if (lstat(tmp, &s))
+				goto out;
 			ls_one(d->d_name, tmp, &s);
+		}
 	}
 
 	closedir(dir);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox


[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux