diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-05-13 17:55:08 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-05-13 17:55:08 +0200 |
commit | 8dd29da2c667b6c9ae7381096320b9e31d3a50e2 (patch) | |
tree | 49781a8618ac5622ea94b0a10156543e0a90e404 | |
parent | 4029e21b37a18bea86dd438d4a9138789ecdce6c (diff) |
ls: code shrink
function old new delta
sort_and_display_files - 427 +427
scan_and_display_dirs_recur 497 488 -9
ls_main 765 735 -30
display_files 422 - -422
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 427/-461) Total: -34 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/ls.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 907955077..e7b2e39e1 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -910,8 +910,15 @@ static void dnsort(struct dnode **dn, int size) { qsort(dn, size, sizeof(*dn), sortcmp); } + +static void sort_and_display_files(struct dnode **dn, unsigned nfiles) +{ + dnsort(dn, nfiles); + display_files(dn, nfiles); +} #else -#define dnsort(dn, size) ((void)0) +# define dnsort(dn, size) ((void)0) +# define sort_and_display_files(dn, nfiles) display_files(dn, nfiles) #endif /* Returns NULL-terminated malloced vector of pointers (or NULL) */ @@ -1022,8 +1029,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first) #endif if (nfiles > 0) { /* list all files at this level */ - dnsort(subdnp, nfiles); - display_files(subdnp, nfiles); + sort_and_display_files(subdnp, nfiles); if (ENABLE_FEATURE_LS_RECURSIVE && (G.all_fmt & DISP_RECURSIVE) @@ -1216,16 +1222,14 @@ int ls_main(int argc UNUSED_PARAM, char **argv) } if (G.all_fmt & DISP_NOLIST) { - dnsort(dnp, nfiles); - display_files(dnp, nfiles); + sort_and_display_files(dnp, nfiles); } else { dnd = splitdnarray(dnp, SPLIT_DIR); dnf = splitdnarray(dnp, SPLIT_FILE); dndirs = count_dirs(dnp, SPLIT_DIR); dnfiles = nfiles - dndirs; if (dnfiles > 0) { - dnsort(dnf, dnfiles); - display_files(dnf, dnfiles); + sort_and_display_files(dnf, dnfiles); if (ENABLE_FEATURE_CLEAN_UP) free(dnf); } |