Re: [dev] [sbase] [PATCH] ls: add option to reverse the sort order

From: Rob <robpilling_AT_gmail.com>
Date: Sat, 5 Oct 2013 10:49:16 +0100

On Fri, Oct 04, 2013 at 05:45:56PM +0400, Alexander S. wrote:
> 2013/10/4 Raphaël Proust <raphlalou_AT_gmail.com>:
> If we want to retain this patch, I'd suggest reversing array after
> sorting, not multiplying by `sortorder' in comparison functions. This
> avoids code duplication.

I disagree - rather than adding a sort call and changing the program's
runtime complexity, can't we just reduce the amount of lines _and_
duplication like this:

_AT_@ -89,9 +93,9 @@ entcmp(const void *va, const void *vb)
        const Entry *a = va, *b = vb;

- if(tflag)
- return sortorder * (b->mtime - a->mtime);
- else
- return sortorder * strcmp(a->name, b->name);
+ return sortorder * (tflag ? b->mtime - a->mtime : strcmp(a->name, b->name));
 }

 void


With line wrapping as appropriate.

Thanks,
Rob
Received on Sat Oct 05 2013 - 11:49:16 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 05 2013 - 12:00:09 CEST