[libc-commits] [libc] [libc] Bound the worst-case stack usage in qsort(). (PR #110849)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Thu Oct 3 08:49:43 PDT 2024
================
@@ -59,17 +59,32 @@ static size_t partition(const Array &array) {
}
}
-LIBC_INLINE void quick_sort(const Array &array) {
- const size_t array_size = array.size();
- if (array_size <= 1)
- return;
- size_t split_index = partition(array);
- if (array_size <= 2) {
- // The partition operation sorts the two element array.
- return;
+LIBC_INLINE void quick_sort(Array array) {
+ while (true) {
+ const size_t array_size = array.size();
+ if (array_size <= 1)
+ return;
+ size_t split_index = partition(array);
+ if (array_size <= 2)
----------------
nickdesaulniers wrote:
```suggestion
if (array_size == 2)
```
https://github.com/llvm/llvm-project/pull/110849
More information about the libc-commits
mailing list