diff --git a/src/qgsattributetable.cpp b/src/qgsattributetable.cpp index c876bc36d75..70158e788cd 100644 --- a/src/qgsattributetable.cpp +++ b/src/qgsattributetable.cpp @@ -237,6 +237,10 @@ void QgsAttributeTable::qsort(int lower, int upper, int col, bool ascending, boo QString v; if(upper>lower) { + //chose a random element (this avoids n^2 worst case) + int element=double(rand())/RAND_MAX*(upper-lower)+lower; + + swapRows(element,upper); v=text(upper,col); i=lower-1; j=upper;