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>
This commit is contained in:
parent
4029e21b37
commit
8dd29da2c6
@ -910,8 +910,15 @@ static void dnsort(struct dnode **dn, int size)
|
|||||||
{
|
{
|
||||||
qsort(dn, size, sizeof(*dn), sortcmp);
|
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
|
#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
|
#endif
|
||||||
|
|
||||||
/* Returns NULL-terminated malloced vector of pointers (or NULL) */
|
/* 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
|
#endif
|
||||||
if (nfiles > 0) {
|
if (nfiles > 0) {
|
||||||
/* list all files at this level */
|
/* list all files at this level */
|
||||||
dnsort(subdnp, nfiles);
|
sort_and_display_files(subdnp, nfiles);
|
||||||
display_files(subdnp, nfiles);
|
|
||||||
|
|
||||||
if (ENABLE_FEATURE_LS_RECURSIVE
|
if (ENABLE_FEATURE_LS_RECURSIVE
|
||||||
&& (G.all_fmt & DISP_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) {
|
if (G.all_fmt & DISP_NOLIST) {
|
||||||
dnsort(dnp, nfiles);
|
sort_and_display_files(dnp, nfiles);
|
||||||
display_files(dnp, nfiles);
|
|
||||||
} else {
|
} else {
|
||||||
dnd = splitdnarray(dnp, SPLIT_DIR);
|
dnd = splitdnarray(dnp, SPLIT_DIR);
|
||||||
dnf = splitdnarray(dnp, SPLIT_FILE);
|
dnf = splitdnarray(dnp, SPLIT_FILE);
|
||||||
dndirs = count_dirs(dnp, SPLIT_DIR);
|
dndirs = count_dirs(dnp, SPLIT_DIR);
|
||||||
dnfiles = nfiles - dndirs;
|
dnfiles = nfiles - dndirs;
|
||||||
if (dnfiles > 0) {
|
if (dnfiles > 0) {
|
||||||
dnsort(dnf, dnfiles);
|
sort_and_display_files(dnf, dnfiles);
|
||||||
display_files(dnf, dnfiles);
|
|
||||||
if (ENABLE_FEATURE_CLEAN_UP)
|
if (ENABLE_FEATURE_CLEAN_UP)
|
||||||
free(dnf);
|
free(dnf);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user