Skip to content

Commit

Permalink
2894 ls(1) -1U can go much faster
Browse files Browse the repository at this point in the history
Reviewed by: Dan McDonald <[email protected]>
Reviewed by: Jerry Jelinek <[email protected]>
Reviewed by: Richard Elling <[email protected]>
Reviewed by: Richard Lowe <[email protected]>
Reviewed by: Robert Mustacchi <[email protected]>
Approved by: Richard Lowe <[email protected]>
  • Loading branch information
Bill Pijewski authored and richlowe committed Jun 19, 2012
1 parent 06711e0 commit 91bbe3f
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion usr/src/cmd/ls/ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

/*
* Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/

/*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 91bbe3f

Please sign in to comment.