qsort improvements
Cristian Rodríguez
crrodriguez@opensuse.org
Sat Aug 28 16:10:18 GMT 2021
On Sat, Aug 28, 2021 at 7:19 AM Laurent Lyaudet via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> Hello,
>
> I developed a C sorting algorithms library (TSODLULS) that currently has a few
> dozens of algorithms and thousands of variants when choosing
> parameters (like threshold for switching to insertion sort, etc.).
> (I compile each variant on demand in custom tests
> to avoid having a bloated source file.)
> It is LGPL and I used code from glibc like qsort.c
>
> I found the following improvements to qsort.c :
> 1) minor improvement but maybe you will accept it
> if (total_elems == 0)
> /* Avoid lossage with unsigned arithmetic below. */
> return;
> could be replaced by
> if (total_elems < 2)
> /* Avoid lossage with unsigned arithmetic below. */
> return;
> 2) There is a "semantic bug" (the algorithm has no error on execution
Please post patches here, commiters can review and/or merge them.
> 3) I found a maybe overly complicated way of swapping variables that
> seems to performs faster.
There is quite a bit of overcomplicated code..ir is my basic,
semi-informed opinion it is there purely because in the (distant) past
compilers
didn't knew any better. Nowadays GCC and clang have improved night-and-day.
> There is no simple and portable way to have double char, quad char and
> octo char in C.
peraphs you shoould only be concerned about platforms supported by
GCC and CLANG, because glibc won't compile with anything else.
More information about the Libc-alpha
mailing list