[libc-commits] [libc] Add missing LIBC_INLINE to qsort_pivot.h (PR #126249)

Lukas Bergdoll via libc-commits libc-commits at lists.llvm.org
Fri Feb 7 06:47:21 PST 2025


https://github.com/Voultapher created https://github.com/llvm/llvm-project/pull/126249

Fixes #111495

>From 1805986a94e05c0ab6eeacd69c95192481a93c55 Mon Sep 17 00:00:00 2001
From: Lukas Bergdoll <lukas.bergdoll at gmail.com>
Date: Fri, 7 Feb 2025 15:42:38 +0100
Subject: [PATCH] Add missing LIBC_INLINE to qsort_pivot.h

---
 libc/src/stdlib/qsort_pivot.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libc/src/stdlib/qsort_pivot.h b/libc/src/stdlib/qsort_pivot.h
index b27e74663d901e9..f202ea4f43fa351 100644
--- a/libc/src/stdlib/qsort_pivot.h
+++ b/libc/src/stdlib/qsort_pivot.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_STDLIB_QSORT_PIVOT_H
 #define LLVM_LIBC_SRC_STDLIB_QSORT_PIVOT_H
 
-#include <stddef.h>  // For size_t
+#include <stddef.h> // For size_t
 
 namespace LIBC_NAMESPACE_DECL {
 namespace internal {
@@ -22,7 +22,7 @@ constexpr size_t PSEUDO_MEDIAN_REC_THRESHOLD = 64;
 // This chooses a pivot by sampling an adaptive amount of points, approximating
 // the quality of a median of sqrt(n) elements.
 template <typename A, typename F>
-size_t choose_pivot(const A &array, const F &is_less) {
+LIBC_INLINE size_t choose_pivot(const A &array, const F &is_less) {
   const size_t len = array.len();
 
   if (len < 8) {
@@ -47,8 +47,8 @@ size_t choose_pivot(const A &array, const F &is_less) {
 // recursion depth and overall sample from f(n) = 3*f(n/8) -> f(n) =
 // O(n^(log(3)/log(8))) ~= O(n^0.528) elements.
 template <typename A, typename F>
-size_t median3_rec(const A &array, size_t a, size_t b, size_t c, size_t n,
-                   const F &is_less) {
+LIBC_INLINE size_t median3_rec(const A &array, size_t a, size_t b, size_t c,
+                               size_t n, const F &is_less) {
   if (n * 8 >= PSEUDO_MEDIAN_REC_THRESHOLD) {
     const size_t n8 = n / 8;
     a = median3_rec(array, a, a + (n8 * 4), a + (n8 * 7), n8, is_less);
@@ -60,7 +60,8 @@ size_t median3_rec(const A &array, size_t a, size_t b, size_t c, size_t n,
 
 /// Calculates the median of 3 elements.
 template <typename A, typename F>
-size_t median3(const A &array, size_t a, size_t b, size_t c, const F &is_less) {
+LIBC_INLINE size_t median3(const A &array, size_t a, size_t b, size_t c,
+                           const F &is_less) {
   const void *a_ptr = array.get(a);
   const void *b_ptr = array.get(b);
   const void *c_ptr = array.get(c);



More information about the libc-commits mailing list