git: 49012db42f3d - stable/13 - libc: Sorting is not needed when there are less than two elements
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 30 Apr 2023 06:58:20 UTC
The branch stable/13 has been updated by hselasky:
URL: https://cgit.FreeBSD.org/src/commit/?id=49012db42f3d0bf29958e1248d1c45312815be05
commit 49012db42f3d0bf29958e1248d1c45312815be05
Author: Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2023-04-19 10:18:56 +0000
Commit: Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2023-04-30 06:56:20 +0000
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@
Sponsored by: NVIDIA Networking
Differential Revision: https://reviews.freebsd.org/D39691
(cherry picked from commit ecb2ce3a51e9b09a57cd42262fc798ae089c0758)
---
lib/libc/stdlib/qsort.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/libc/stdlib/qsort.c b/lib/libc/stdlib/qsort.c
index 015c648d633a..410118c5cd70 100644
--- a/lib/libc/stdlib/qsort.c
+++ b/lib/libc/stdlib/qsort.c
@@ -108,7 +108,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;