[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
Wed Oct 2 10:30:03 PDT 2024
================
@@ -59,17 +59,33 @@ 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) {
+ // The partition operation sorts the two element array.
+ return;
+ }
----------------
nickdesaulniers wrote:
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements
https://github.com/llvm/llvm-project/pull/110849
More information about the libc-commits
mailing list