Mercurial > illumos > illumos-gate
changeset 13734:41fe4dd8e23d
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>
author | Bill Pijewski <wdp@joyent.com> |
---|---|
date | Tue, 19 Jun 2012 13:33:18 -0400 |
parents | d48dc87999aa |
children | 1c48a05ba37d |
files | usr/src/cmd/ls/ls.c |
diffstat | 1 files changed, 34 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/ls/ls.c Mon Jun 18 21:48:02 2012 -0400 +++ b/usr/src/cmd/ls/ls.c Tue Jun 19 13:33:18 2012 -0400 @@ -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 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 @@ #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 @@ 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 @@ char *cp; char *str; + if (noflist) { + (void) printf("%s\n", ap->ln.lname); + return; + } + p = ap; column(); if (iflg) @@ -1572,6 +1588,15 @@ 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 @@ 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;