newlib-cygwin/newlib/libc/search
Hakan Lindqvist 3ce38df8d1 Reduce qsort stack consumption
Classical function call recursion wastes a lot of stack space.
Each recursion level requires a full stack frame comprising all
local variables and additional space as dictated by the
processor calling convention.

This implementation instead stores the variables that are unique
for each recursion level in a parameter stack array, and uses
iteration to emulate recursion. Function call recursion is not
used until the array is full.

To ensure the stack consumption isn't worsened by this design, the
size of the parameter stack array is chosen to be similar to the
stack frame excluding the array. Each function call recursion level
can handle 8 iterative recursion levels.

Stack consumption will worsen when sorting tiny arrays that do not
need recursion (of 6 elements or less). It will be about equal for
up to 15 elements, and be an improvement for larger arrays. The best
case improvement is a stack size reduction down to about one quarter
of the stack consumption before the change.

A design where the parameter stack array is large enough for the
worst case recursion level was rejected because it would worsen
the stack consumption when sorting arrays smaller than about 1500
elements. The worst case is 31 levels on a 32-bit system.

A design with a dynamic parameter array size was rejected because
of limitations in some compilers.
2018-03-16 10:21:23 +01:00
..
Makefile.am Move duplicated documentation rules to Makefile.shared 2015-11-02 18:02:39 -05:00
Makefile.in makedoc: make errors visible 2017-12-07 11:54:11 +00:00
bsd_qsort_r.c * libc/include/stdlib.h (__bsd_qsort_r): Declare. 2014-12-05 16:21:04 +00:00
bsearch.c ansification: remove _EXFNPTR, _EXPARM 2018-01-17 11:47:27 -06:00
db_local.h * libm/math/ef_sqrt.c: Delete unused variable sign. 2010-03-05 08:55:16 +00:00
extern.h
hash.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
hash.h 2008-07-02 Jeff Johnston <jjohnstn@redhat.com> 2008-07-02 18:38:45 +00:00
hash_bigkey.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
hash_buf.c * libc/stdlib/btowc.c (btowc): Cast to avoid compiler warning. 2012-08-10 15:21:57 +00:00
hash_func.c 2008-11-24 Jeff Johnston <jjohnstn@redhat.com> 2008-11-24 21:16:06 +00:00
hash_log2.c
hash_page.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
hcreate.3
hcreate.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
hcreate_r.c 2012-07-17 Ralf Corsépius <ralf.corsepius@rtems.org> 2012-07-17 16:56:45 +00:00
page.h
qsort.c Reduce qsort stack consumption 2018-03-16 10:21:23 +01:00
qsort_r.c search: remove TRAD_SYNOPSIS 2017-12-01 03:41:51 -06:00
tdelete.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
tdestroy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
tfind.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
tsearch.3
tsearch.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
twalk.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00