Skip to content

Commit 9c17f57

Browse files
Simon Tathamcopybara-github
authored andcommitted
[roll] Roll llvm-project/libc [libc] Bound the worst-case stack usage in qsort(). (#110849)
Previously, the Quicksort implementation was written in the obvious way: after each partitioning step, it explicitly recursed twice to sort the two sublists. Now it compares the two sublists' sizes, and recurses only to sort the smaller one. To handle the larger list it loops back round to the top of the function, so as to handle it within the existing stack frame. This means that every recursive call is handling a list at most half that of its caller. So the maximum recursive call depth is O(lg N). Otherwise, in Quicksort's bad cases where each partition step peels off a small constant number of array elements, the stack usage could grow linearly with the array being sorted, i.e. it might be Θ(N). I tested this code by manually constructing a List Of Doom that causes this particular quicksort implementation to hit its worst case, and confirming that it recursed very deeply in the old code and doesn't in the new code. But I haven't added that list to the test suite, because the List Of Doom has to be constructed in a way based on every detail of the quicksort algorithm (pivot choice and partitioning strategy), so it would silently stop being a useful regression test as soon as any detail changed. GitOrigin-RevId: 212b7409b819892ff13f1bdcbb15a8d83a9d1898 Original-Revision: 410803b30e75b289afdc7f9f3b24cb451b7891ed Change-Id: I81dcfb5028c0ddfee607a9ca32907f7edada34d7
1 parent a55651d commit 9c17f57

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

third_party/flower

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@
372372
gitsubmoduleof="fuchsia"
373373
path="third_party/llvm-libc/src"
374374
remote="https://llvm.googlesource.com/llvm-project/libc"
375-
revision="6e0d79c0e8a7d9709958ba475218e64cd2eda9ec"/>
375+
revision="410803b30e75b289afdc7f9f3b24cb451b7891ed"/>
376376
<project name="third_party/lz4"
377377
gitsubmoduleof="fuchsia"
378378
path="third_party/lz4"

0 commit comments

Comments
 (0)