The branch main has been updated by hselasky:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=ecb2ce3a51e9b09a57cd42262fc798ae089c0758

commit ecb2ce3a51e9b09a57cd42262fc798ae089c0758
Author:     Hans Petter Selasky <hsela...@freebsd.org>
AuthorDate: 2023-04-19 10:18:56 +0000
Commit:     Hans Petter Selasky <hsela...@freebsd.org>
CommitDate: 2023-04-19 15:17:33 +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@
    MFC after:      1 week
    Sponsored by:   NVIDIA Networking
    Differential Revision:  https://reviews.freebsd.org/D39691
---
 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 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;

Reply via email to