@@ -24,8 +24,9 @@ namespace internal {
2424// https://github.com/Voultapher/sort-research-rs/blob/main/writeup/lomcyc_partition/text.md.
2525// Simplified to avoid having to stack allocate.
2626template <typename A, typename F>
27- size_t partition_lomuto_branchless (const A &array, const void *pivot,
28- const F &is_less) {
27+ LIBC_INLINE size_t partition_lomuto_branchless (const A &array,
28+ const void *pivot,
29+ const F &is_less) {
2930 const size_t array_len = array.len ();
3031
3132 size_t left = 0 ;
@@ -49,8 +50,8 @@ size_t partition_lomuto_branchless(const A &array, const void *pivot,
4950// cyclic permutation is to have more efficient swapping, but we don't
5051// know the element size so this isn't applicable here either.
5152template <typename A, typename F>
52- size_t partition_hoare_branchy (const A &array, const void *pivot,
53- const F &is_less) {
53+ LIBC_INLINE size_t partition_hoare_branchy (const A &array, const void *pivot,
54+ const F &is_less) {
5455 const size_t array_len = array.len ();
5556
5657 size_t left = 0 ;
@@ -78,7 +79,8 @@ size_t partition_hoare_branchy(const A &array, const void *pivot,
7879}
7980
8081template <typename A, typename F>
81- size_t partition (const A &array, size_t pivot_index, const F &is_less) {
82+ LIBC_INLINE size_t partition (const A &array, size_t pivot_index,
83+ const F &is_less) {
8284 // Place the pivot at the beginning of the array.
8385 if (pivot_index != 0 ) {
8486 array.swap (0 , pivot_index);
@@ -104,8 +106,8 @@ size_t partition(const A &array, size_t pivot_index, const F &is_less) {
104106}
105107
106108template <typename A, typename F>
107- void quick_sort_impl (A &array, const void *ancestor_pivot, size_t limit ,
108- const F &is_less) {
109+ LIBC_INLINE void quick_sort_impl (A &array, const void *ancestor_pivot,
110+ size_t limit, const F &is_less) {
109111 while (true ) {
110112 const size_t array_len = array.len ();
111113 if (array_len <= 1 )
@@ -167,7 +169,8 @@ void quick_sort_impl(A &array, const void *ancestor_pivot, size_t limit,
167169
168170constexpr size_t ilog2 (size_t n) { return cpp::bit_width (n) - 1 ; }
169171
170- template <typename A, typename F> void quick_sort (A &array, const F &is_less) {
172+ template <typename A, typename F>
173+ LIBC_INLINE void quick_sort (A &array, const F &is_less) {
171174 const void *ancestor_pivot = nullptr ;
172175 // Limit the number of imbalanced partitions to `2 * floor(log2(len))`.
173176 // The binary OR by one is used to eliminate the zero-check in the logarithm.
0 commit comments