diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2015-11-01 14:39:13 +0100 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2015-11-01 14:39:13 +0100 |
commit | 9c7dc7fbecf015b087e1626335190e8a456f5da9 (patch) | |
tree | 93c681df8a062458c1ad5a39d5afdd8e4c6009b5 /lr.c | |
parent | 78d87be0b2fd7a69cbf5a40611e44670029cd383 (diff) | |
download | lr-9c7dc7fbecf015b087e1626335190e8a456f5da9.tar.gz lr-9c7dc7fbecf015b087e1626335190e8a456f5da9.tar.xz lr-9c7dc7fbecf015b087e1626335190e8a456f5da9.zip |
analyze format to save expensive lookups
Diffstat (limited to 'lr.c')
-rw-r--r-- | lr.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/lr.c b/lr.c index 762d622..510f8cc 100644 --- a/lr.c +++ b/lr.c @@ -92,6 +92,9 @@ struct idmap { char *name; }; +static int need_group; +static int need_user; +static int need_fstype; static off_t maxsize; static nlink_t maxlinks; static int uwid, gwid, fwid; @@ -996,6 +999,25 @@ print_noprefix(struct fileinfo *fi) } void +analyze_format() +{ + char *s; + for (s = format; *s; s++) { + if (*s == '\\') { + s++; + continue; + } + if (*s != '%') + continue; + switch (*++s) { + case 'g': need_group++; break; + case 'u': need_user++; break; + case 'Y': need_fstype++; break; + } + } +} + +void print_format(struct fileinfo *fi) { char *s; @@ -1155,11 +1177,13 @@ callback(const char *fpath, const struct stat *sb, int depth, int entries, off_t maxlinks = fi->sb.st_nlink; if (fi->sb.st_size > maxsize) maxsize = fi->sb.st_size; - if (lflag) { - /* prefetch user/group name for correct column widths. */ + /* prefetch user/group/fs name for correct column widths. */ + if (need_user) username(fi->sb.st_uid); + if (need_group) groupname(fi->sb.st_gid); - } + if (need_fstype) + fstype(fi->sb.st_dev); return 0; } @@ -1300,6 +1324,8 @@ main(int argc, char *argv[]) exit(2); } + analyze_format(); + if (optind == argc) { sflag++; traverse("."); |