libc: Sorting is not needed when there are less than two elements

If there are less than two elements avoid executing the first
sorting loop. No functional change intended.

Reviewed by:	kib@
MFC after:	1 week
Sponsored by:	NVIDIA Networking
Differential Revision:	https://reviews.freebsd.org/D39691
This commit is contained in:
Hans Petter Selasky 2023-04-19 12:18:56 +02:00
parent 409731e7d7
commit ecb2ce3a51

View file

@ -114,7 +114,8 @@ local_qsort(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk)
int cmp_result;
int swap_cnt;
if (__predict_false(n == 0))
/* if there are less than 2 elements, then sorting is not needed */
if (__predict_false(n < 2))
return;
loop:
swap_cnt = 0;