summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-03-19 15:19:26 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-03-19 15:21:38 -0400
commit5b63983e226ad12980a15704d3e2276d9321da24 (patch)
treec67d6b62c3888a7052332ada8e56f143e3a4471f
parent101aa287fd64b5f229c5dd759de353721bc2f04a (diff)
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.
-rw-r--r--sc/source/core/data/dpcache.cxx27
1 files changed, 25 insertions, 2 deletions
diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx
index 369c5b3b05ff..f13a4814067a 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 =