Skip to content

Commit bcaa7f5

Browse files
global-integration-rollercopybara-github
authored andcommitted
[roll] Roll fuchsia [superproject] 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: 476ad95a78dc437944348645e6c7a1ec034c126b Original-Revision: 410803b30e75b289afdc7f9f3b24cb451b7891ed Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1134072 Original-Revision: 2b65d09a95fa4b7d9d0fd4f8cd35a0394b78173b Change-Id: I83057b48ae9bfa7b1f96cbc03adb865301a3f9cb
1 parent 9c17f57 commit bcaa7f5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stem

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
githooks="integration/git-hooks"
1212
remote="https://fuchsia.googlesource.com/fuchsia"
1313
gerrithost="https://fuchsia-review.googlesource.com"
14-
revision="02f3c4243502d55c0e48033c80df6f8cfb9cce59"/>
14+
revision="2b65d09a95fa4b7d9d0fd4f8cd35a0394b78173b"/>
1515
</projects>
1616
<hooks>
1717
<hook name="install-environment"

0 commit comments

Comments
 (0)