]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Use std::rotate, rather than reversing three times
authorFrank Reininghaus <frank78ac@googlemail.com>
Tue, 15 Jan 2013 17:44:00 +0000 (18:44 +0100)
committerFrank Reininghaus <frank78ac@googlemail.com>
Tue, 15 Jan 2013 17:44:42 +0000 (18:44 +0100)
We need less code now, and moreover, the STL implementation of rotate
should be more efficient than three reverse() calls.

src/kitemviews/private/kfileitemmodelsortalgorithm.cpp
src/kitemviews/private/kfileitemmodelsortalgorithm.h

index ab650efea1e66451309f542081ede7c83b31ae36..a09d0cd80cd4afd953a375721421d544196b3051 100644 (file)
@@ -22,6 +22,8 @@
 #include <QThread>
 #include <QtCore>
 
+#include <algorithm>
+
 void KFileItemModelSortAlgorithm::sort(KFileItemModel* model,
                                        QList<KFileItemModel::ItemData*>::iterator begin,
                                        QList<KFileItemModel::ItemData*>::iterator end)
@@ -115,9 +117,7 @@ void KFileItemModelSortAlgorithm::merge(KFileItemModel* model,
         firstCut = upperBound(model, begin, pivot, *secondCut);
     }
 
-    reverse(firstCut, pivot);
-    reverse(pivot, secondCut);
-    reverse(firstCut, secondCut);
+    std::rotate(firstCut, pivot, secondCut);
 
     const QList<KFileItemModel::ItemData*>::iterator newPivot = firstCut + len2Half;
     merge(model, begin, firstCut, newPivot);
@@ -176,15 +176,3 @@ KFileItemModelSortAlgorithm::upperBound(KFileItemModel* model,
     }
     return begin;
 }
-
-void KFileItemModelSortAlgorithm::reverse(QList<KFileItemModel::ItemData*>::iterator begin,
-                                          QList<KFileItemModel::ItemData*>::iterator end)
-{
-    // The implementation is based on qReverse() from qalgorithms.h
-    // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-
-    --end;
-    while (begin < end) {
-        qSwap(*begin++, *end--);
-    }
-}
index 07e5d4a814d02031cb1667fecaf48e42bddea1df..b86d490aae9cb08d4cd122c2e8aca8e77d88fd43 100644 (file)
@@ -69,9 +69,6 @@ private:
                            QList<KFileItemModel::ItemData*>::iterator begin,
                            QList<KFileItemModel::ItemData*>::iterator end,
                            const KFileItemModel::ItemData* value);
-
-    static void reverse(QList<KFileItemModel::ItemData*>::iterator begin,
-                        QList<KFileItemModel::ItemData*>::iterator end);
 };
 
 #endif