diff options
author | Hans Petter Selasky <hselasky@FreeBSD.org> | 2023-04-19 10:18:56 +0000 |
---|---|---|
committer | Hans Petter Selasky <hselasky@FreeBSD.org> | 2023-04-19 15:17:33 +0000 |
commit | ecb2ce3a51e9b09a57cd42262fc798ae089c0758 (patch) | |
tree | 7b75245c353b399f95d4dcb32ea6c990c3ca3a38 | |
parent | 409731e7d71358cda3d23d903607614c29680038 (diff) | |
download | src-ecb2ce3a51e9b09a57cd42262fc798ae089c0758.tar.gz src-ecb2ce3a51e9b09a57cd42262fc798ae089c0758.zip |
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
-rw-r--r-- | lib/libc/stdlib/qsort.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/libc/stdlib/qsort.c b/lib/libc/stdlib/qsort.c index 425edd562420..0d65cd119ea6 100644 --- a/lib/libc/stdlib/qsort.c +++ b/lib/libc/stdlib/qsort.c @@ -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; |