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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Lukas Bergdoll (Voultapher)

<details>
<summary>Changes</summary>

Fixes #<!-- -->111495

---
Full diff: https://github.com/llvm/llvm-project/pull/126249.diff


1 Files Affected:

- (modified) libc/src/stdlib/qsort_pivot.h (+6-5) 


``````````diff
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);

``````````

</details>


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


More information about the libc-commits mailing list