summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-09-17 15:10:27 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-09-18 00:40:33 -0400
commit1b9a8efb824b5fe6113a14279ea5a4c8070d260f (patch)
treea9defb3e39c99286be1544960c3fdf570e66da56 /sc
parent1e50a93d228fbd41dc1d75aec48df088302900f8 (diff)
Refactor fillTable (3-param variant) to skip trailing empty rows.
This speeds up the process considerably if the size of the trailing empty rows is huge. Change-Id: Ide91174b09472a20309b4f6e18d658cb8fbefa42
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/data/dpcache.cxx7
-rw-r--r--sc/source/core/data/dpcachetable.cxx50
2 files changed, 33 insertions, 24 deletions
diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx
index 75234afd8f8e..5a5ec57e2fbf 100644
--- a/sc/source/core/data/dpcache.cxx
+++ b/sc/source/core/data/dpcache.cxx
@@ -661,14 +661,14 @@ void ScDPCache::PostInit()
typedef mdds::flat_segment_tree<SCROW, bool>::const_reverse_iterator itr_type;
itr_type it = maEmptyRows.rbegin(), itEnd = maEmptyRows.rend();
OSL_ENSURE(it != itEnd, "corrupt flat_segment_tree instance!");
- mnDataSize = maFields[0].maItems.size();
+ mnDataSize = maFields[0].maData.size();
++it; // Skip the first position.
OSL_ENSURE(it != itEnd, "buggy version of flat_segment_tree is used.");
if (it->second)
{
SCROW nLastNonEmpty = it->first - 1;
- if (nLastNonEmpty < mnDataSize)
- mnDataSize = nLastNonEmpty;
+ if (nLastNonEmpty+1 < mnDataSize)
+ mnDataSize = nLastNonEmpty+1;
}
}
@@ -770,6 +770,7 @@ SCROW ScDPCache::GetRowCount() const
SCROW ScDPCache::GetDataSize() const
{
+ OSL_ENSURE(mnDataSize <= GetRowCount(), "Data size should never be larger than the row count.");
return mnDataSize >= 0 ? mnDataSize : 0;
}
diff --git a/sc/source/core/data/dpcachetable.cxx b/sc/source/core/data/dpcachetable.cxx
index f1a6417c9f93..08bc7764cc7d 100644
--- a/sc/source/core/data/dpcachetable.cxx
+++ b/sc/source/core/data/dpcachetable.cxx
@@ -70,7 +70,7 @@ bool ScDPCacheTable::RowFlag::isActive() const
}
ScDPCacheTable::RowFlag::RowFlag() :
- mbShowByFilter(true),
+ mbShowByFilter(false),
mbShowByPage(true)
{
}
@@ -146,20 +146,41 @@ sal_Int32 ScDPCacheTable::getColSize() const
void ScDPCacheTable::fillTable(
const ScQueryParam& rQuery, bool bIgnoreEmptyRows, bool bRepeatIfEmpty)
{
- const SCROW nRowCount = getRowSize();
+ SCROW nRowCount = getRowSize();
SCROW nDataSize = mpCache->GetDataSize();
- const SCCOL nColCount = (SCCOL) getColSize();
- if ( nRowCount <= 0 || nColCount <= 0)
+ SCCOL nColCount = getColSize();
+ if (nRowCount <= 0 || nColCount <= 0)
return;
maRowFlags.clear();
maRowFlags.reserve(nRowCount);
+ // Process the non-empty data rows.
+ for (SCROW nRow = 0; nRow < nDataSize; ++nRow)
+ {
+ maRowFlags.push_back(RowFlag());
+ if (!getCache()->ValidQuery(nRow, rQuery))
+ continue;
+
+ if (bIgnoreEmptyRows && getCache()->IsRowEmpty(nRow))
+ continue;
+
+ maRowFlags.back().mbShowByFilter = true;
+ }
+
+ // Process the trailing empty rows.
+ for (SCROW nRow = nDataSize; nRow < nRowCount; ++nRow)
+ {
+ maRowFlags.push_back(RowFlag());
+ if (!bIgnoreEmptyRows)
+ maRowFlags.back().mbShowByFilter = true;
+ }
+
// Initialize field entries container.
maFieldEntries.clear();
maFieldEntries.reserve(nColCount);
- // Data rows
+ // Build unique field entries.
for (SCCOL nCol = 0; nCol < nColCount; ++nCol)
{
maFieldEntries.push_back( vector<SCROW>() );
@@ -171,24 +192,11 @@ void ScDPCacheTable::fillTable(
for (SCROW nRow = 0; nRow < nRowCount; ++nRow)
{
- SCROW nIndex = getCache()->GetItemDataId(nCol, nRow, bRepeatIfEmpty);
- SCROW nOrder = getOrder(nCol, nIndex);
-
- if (nCol == 0)
- {
- maRowFlags.push_back(RowFlag());
- maRowFlags.back().mbShowByFilter = false;
- }
-
- if (!getCache()->ValidQuery(nRow, rQuery))
+ if (!maRowFlags[nRow].mbShowByFilter)
continue;
- if (bIgnoreEmptyRows && getCache()->IsRowEmpty(nRow))
- continue;
-
- if (nCol == 0)
- maRowFlags.back().mbShowByFilter = true;
-
+ SCROW nIndex = getCache()->GetItemDataId(nCol, nRow, bRepeatIfEmpty);
+ SCROW nOrder = getOrder(nCol, nIndex);
aAdded[nOrder] = nIndex;
}
for (SCROW nRow = 0; nRow < nMemCount; ++nRow)