bsearch: simplify and optimize
authorFangrui Song <i@maskray.me>
Sun, 22 Jul 2018 00:34:00 +0000 (17:34 -0700)
committerRich Felker <dalias@aerifal.cx>
Mon, 23 Jul 2018 19:14:29 +0000 (15:14 -0400)
commit3d8322c7ad659210a4c8770ef455ca729ce7f395
tree25de8d1283cf1945c34aa5ccf444c46846a846da
parentf2c6dbe2442027ed8fe0fa869918e41f495534d8
bsearch: simplify and optimize

maintainer's note: the key observation here is that the compared
element is the first slot of the second ceil(half) of the array, and
thus can be removed for further comparison when it does not match, so
that we descend into the second ceil(half)-1 rather than ceil(half)
elements. this change ensures that nel strictly decreases with each
iteration, so that the case of != but nel==1 does not need to be
special-cased anymore.
src/stdlib/bsearch.c