sc/source/core/data/dpcache.cxx |   27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

New commits:
commit 5b63983e226ad12980a15704d3e2276d9321da24
Author: Kohei Yoshida <kohei.yosh...@gmail.com>
Date:   Mon Mar 19 15:19:26 2012 -0400

    Record sort order during the first sort by the value, and use it the 2nd 
time.
    
    This avoids comparison of raw values (ScDPItemData) during the 2nd sort.
    Comparison of raw values can be expensive especially when the item sets 
mostly
    consist of string values.

diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx
index 369c5b3..f13a481 100644
--- a/sc/source/core/data/dpcache.cxx
+++ b/sc/source/core/data/dpcache.cxx
@@ -247,8 +247,9 @@ struct Bucket
     ScDPItemData maValue;
     SCROW mnOrderIndex;
     SCROW mnDataIndex;
+    SCROW mnValueSortIndex;
     Bucket(const ScDPItemData& rValue, SCROW nOrder, SCROW nData) :
-        maValue(rValue), mnOrderIndex(nOrder), mnDataIndex(nData) {}
+        maValue(rValue), mnOrderIndex(nOrder), mnDataIndex(nData), 
mnValueSortIndex(0) {}
 };
 
 struct LessByValue : std::binary_function<Bucket, Bucket, bool>
@@ -259,6 +260,14 @@ struct LessByValue : std::binary_function<Bucket, Bucket, 
bool>
     }
 };
 
+struct LessByValueSortIndex : std::binary_function<Bucket, Bucket, bool>
+{
+    bool operator() (const Bucket& left, const Bucket& right) const
+    {
+        return left.mnValueSortIndex < right.mnValueSortIndex;
+    }
+};
+
 struct LessByDataIndex : std::binary_function<Bucket, Bucket, bool>
 {
     bool operator() (const Bucket& left, const Bucket& right) const
@@ -297,6 +306,17 @@ public:
     }
 };
 
+class TagValueSortOrder : std::unary_function<Bucket, void>
+{
+    SCROW mnCurIndex;
+public:
+    TagValueSortOrder() : mnCurIndex(0) {}
+    void operator() (Bucket& v)
+    {
+        v.mnValueSortIndex = mnCurIndex++;
+    }
+};
+
 void processBuckets(std::vector<Bucket>& aBuckets, ScDPCache::Field& rField)
 {
     if (aBuckets.empty())
@@ -305,6 +325,9 @@ void processBuckets(std::vector<Bucket>& aBuckets, 
ScDPCache::Field& rField)
     // Sort by the value.
     std::sort(aBuckets.begin(), aBuckets.end(), LessByValue());
 
+    // Remember this sort order.
+    std::for_each(aBuckets.begin(), aBuckets.end(), TagValueSortOrder());
+
     {
         // Set order index such that unique values have identical index value.
         SCROW nCurIndex = 0;
@@ -329,7 +352,7 @@ void processBuckets(std::vector<Bucket>& aBuckets, 
ScDPCache::Field& rField)
     std::for_each(aBuckets.begin(), aBuckets.end(), 
PushBackOrderIndex(rField.maData));
 
     // Sort by the value again.
-    std::sort(aBuckets.begin(), aBuckets.end(), LessByValue());
+    std::sort(aBuckets.begin(), aBuckets.end(), LessByValueSortIndex());
 
     // Unique by value.
     std::vector<Bucket>::iterator itUniqueEnd =
_______________________________________________
Libreoffice-commits mailing list
Libreoffice-commits@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to