* Patch from Mattias Gaertner to improve quicksort memory use (Bug 22119)

git-svn-id: trunk@21386 -
This commit is contained in:
michael 2012-05-24 19:18:44 +00:00
parent 21b94f675f
commit 032528115f

View File

@ -318,10 +318,22 @@ begin
J := J - 1;
end;
until I > J;
if L < J then
QuickSort(FList, L, J, Compare);
L := I;
until I >= R;
// sort the smaller range recursively
// sort the bigger range via the loop
// Reasons: memory usage is O(log(n)) instead of O(n) and loop is faster than recursion
if J - L < R - I then
begin
if L < J then
QuickSort(FList, L, J, Compare);
L := I;
end
else
begin
if I < R then
QuickSort(FList, I, R, Compare);
R := J;
end;
until L >= R;
end;
procedure TFPList.Sort(Compare: TListSortCompare);