summaryrefslogtreecommitdiff
path: root/usr/src/cmd/ls
diff options
context:
space:
mode:
authorBill Pijewski <wdp@joyent.com>2012-06-19 13:33:18 -0400
committerRichard Lowe <richlowe@richlowe.net>2012-06-19 13:34:31 -0400
commit91bbe3fd1ef800870651f14573985dbdcf56937f (patch)
treea812f87bc2b125645e41fcb784b8db446fcba9c4 /usr/src/cmd/ls
parent06711e0cbc5503c70ec7dc43e2ddc6a2e6a5fe8b (diff)
downloadillumos-joyent-91bbe3fd1ef800870651f14573985dbdcf56937f.tar.gz
2894 ls(1) -1U can go much faster
Reviewed by: Dan McDonald <danmcd@nexenta.com> Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Richard Elling <richard.elling@gmail.com> Reviewed by: Richard Lowe <richlowe@richlowe.net> Reviewed by: Robert Mustacchi <rm@joyent.com> Approved by: Richard Lowe <richlowe@richlowe.net>
Diffstat (limited to 'usr/src/cmd/ls')
-rw-r--r--usr/src/cmd/ls/ls.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/usr/src/cmd/ls/ls.c b/usr/src/cmd/ls/ls.c
index 048afb3ec2..94fc114b01 100644
--- a/usr/src/cmd/ls/ls.c
+++ b/usr/src/cmd/ls/ls.c
@@ -21,6 +21,7 @@
/*
* Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/
/*
@@ -309,6 +310,7 @@ static mode_t flags;
static int err = 0; /* Contains return code */
static int colorflg;
static int file_typeflg;
+static int noflist = 0;
static uid_t lastuid = (uid_t)-1;
static gid_t lastgid = (gid_t)-1;
@@ -998,6 +1000,15 @@ main(int argc, char *argv[])
#endif
}
+ /*
+ * When certain options (-f, or -U and -1, and not -l, etc.) are
+ * specified, don't cache each dirent as it's read. This 'noflist'
+ * option is set when there's no need to cache those dirents; instead,
+ * print them out as they're read.
+ */
+ if ((Uflg || fflg) && !Cflg && !lflg && !iflg && statreq == 0)
+ noflist = 1;
+
if (num_cols < 20 || num_cols > 1000)
/* assume it is an error */
num_cols = 80;
@@ -1156,7 +1167,7 @@ pdirectory(char *name, int title, int lp, int cdetect, struct ditem *myinfo)
nfiles = lp;
rddir(name, myinfo);
- if (nomocore)
+ if (nomocore || noflist)
return;
if (fflg == 0 && Uflg == 0)
qsort(&flist[lp], (unsigned)(nfiles - lp),
@@ -1250,6 +1261,11 @@ pentry(struct lbuf *ap)
char *cp;
char *str;
+ if (noflist) {
+ (void) printf("%s\n", ap->ln.lname);
+ return;
+ }
+
p = ap;
column();
if (iflg)
@@ -1572,6 +1588,15 @@ rddir(char *dir, struct ditem *myinfo)
for (j = 0; dentry->d_name[j] != '\0'; j++)
ep->ln.lname[j] = dentry->d_name[j];
ep->ln.lname[j] = '\0';
+
+ /*
+ * Since this entry doesn't need to be sorted
+ * or further processed, print it right away.
+ */
+ if (noflist) {
+ pem(&ep, &ep + 1, 0);
+ nfiles--;
+ }
}
}
if (errno) {
@@ -1784,6 +1809,14 @@ gstat(char *file, int argfl, struct ditem *myparent)
rep = flist[nfiles++];
}
+ /*
+ * When noflist is set, none of the extra information about the dirent
+ * will be printed, so omit initialization of this lbuf as well as the
+ * stat(2) call.
+ */
+ if (!argfl && noflist)
+ return (rep);
+
/* Initialize */
rep->lflags = (mode_t)0;