Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing LIBC_INLINE to qsort_pivot.h #126249

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Voultapher
Copy link
Contributor

Fixes #111495

@llvmbot llvmbot added the libc label Feb 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 7, 2025

@llvm/pr-subscribers-libc

Author: Lukas Bergdoll (Voultapher)

Changes

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

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@statham-arm statham-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too, and I agree this completes #111495.

Copy link
Collaborator

@statham-arm statham-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(er, actually press the LGTM button this time, ahem)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Further improvements to quicksort implementation of qsort
4 participants