summaryrefslogtreecommitdiff
path: root/sc/source/core/data
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-11-28 00:29:59 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-11-28 00:32:44 +0100
commit839eccc8ae5aa5dde055f84471246f2a3ef04929 (patch)
tree566d0aa7e9c7036c012826d33b05aaaf7b09d9da /sc/source/core/data
parent12aa3151ab993fff1ae312ae7b1d5bbcfc379b07 (diff)
iterating through all cells is not a good idea, fdo#71934
Change-Id: I370f641f0fffed8835a32c577c2f2e841ba419aa
Diffstat (limited to 'sc/source/core/data')
-rw-r--r--sc/source/core/data/column2.cxx33
-rw-r--r--sc/source/core/data/document.cxx12
-rw-r--r--sc/source/core/data/table2.cxx10
3 files changed, 52 insertions, 3 deletions
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 24cd6155865e..8759c513210c 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1262,9 +1262,13 @@ class NoteEntryCollector
std::vector<sc::NoteEntry>& mrNotes;
SCTAB mnTab;
SCCOL mnCol;
+ SCROW mnStartRow;
+ SCROW mnEndRow;
public:
- NoteEntryCollector( std::vector<sc::NoteEntry>& rNotes, SCTAB nTab, SCCOL nCol ) :
- mrNotes(rNotes), mnTab(nTab), mnCol(nCol) {}
+ NoteEntryCollector( std::vector<sc::NoteEntry>& rNotes, SCTAB nTab, SCCOL nCol,
+ SCROW nStartRow = 0, SCROW nEndRow = MAXROW) :
+ mrNotes(rNotes), mnTab(nTab), mnCol(nCol),
+ mnStartRow(nStartRow), mnEndRow(nEndRow) {}
void operator() (const sc::CellNoteStoreType::value_type& node) const
{
@@ -1275,7 +1279,14 @@ public:
sc::cellnote_block::const_iterator it = sc::cellnote_block::begin(*node.data);
sc::cellnote_block::const_iterator itEnd = sc::cellnote_block::end(*node.data);
size_t nOffset = 0;
- for (; it != itEnd; ++it, ++nOffset)
+ if(nTopRow < size_t(mnStartRow))
+ {
+ std::advance(it, mnStartRow - nTopRow);
+ nOffset = mnStartRow - nTopRow;
+ }
+
+ for (; it != itEnd && nTopRow + nOffset <= size_t(mnEndRow);
+ ++it, ++nOffset)
{
ScAddress aPos(mnCol, nTopRow + nOffset, mnTab);
mrNotes.push_back(sc::NoteEntry(aPos, *it));
@@ -1290,6 +1301,22 @@ void ScColumn::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
std::for_each(maCellNotes.begin(), maCellNotes.end(), NoteEntryCollector(rNotes, nTab, nCol));
}
+void ScColumn::GetNotesInRange(SCROW nStartRow, SCROW nEndRow,
+ std::vector<sc::NoteEntry>& rNotes ) const
+{
+ std::pair<sc::CellNoteStoreType::const_iterator,size_t> aPos = maCellNotes.position(nStartRow);
+ sc::CellNoteStoreType::const_iterator it = aPos.first;
+ if (it == maCellNotes.end())
+ // Invalid row number.
+ return;
+
+ std::pair<sc::CellNoteStoreType::const_iterator,size_t> aEndPos =
+ maCellNotes.position(nEndRow);
+ sc::CellNoteStoreType::const_iterator itEnd = aEndPos.first;
+
+ std::for_each(it, itEnd, NoteEntryCollector(rNotes, nTab, nCol, nStartRow, nEndRow));
+}
+
SCSIZE ScColumn::GetEmptyLinesInBlock( SCROW nStartRow, SCROW nEndRow, ScDirection eDir ) const
{
// Given a range of rows, find a top or bottom empty segment.
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 708300e72a88..931994a0a3fd 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6226,6 +6226,18 @@ void ScDocument::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
}
}
+void ScDocument::GetNotesInRange( const ScRangeList& rRange, std::vector<sc::NoteEntry>& rNotes ) const
+{
+ for( size_t i = 0; i < rRange.size(); ++i)
+ {
+ const ScRange* pRange = rRange[i];
+ for( SCTAB nTab = pRange->aStart.Tab(); nTab < pRange->aEnd.Tab(); ++nTab )
+ {
+ maTabs[nTab]->GetNotesInRange( *pRange, rNotes );
+ }
+ }
+}
+
bool ScDocument::ContainsNotesInRange( const ScRangeList& rRange ) const
{
for( size_t i = 0; i < rRange.size(); ++i)
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index c0d41d1ae6cf..d7fca4f9eb69 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1516,6 +1516,16 @@ void ScTable::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
aCol[nCol].GetAllNoteEntries(rNotes);
}
+void ScTable::GetNotesInRange( const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes ) const
+{
+ SCROW nStartRow = rRange.aStart.Row();
+ SCROW nEndRow = rRange.aEnd.Row();
+ for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
+ {
+ aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
+ }
+}
+
bool ScTable::ContainsNotesInRange( const ScRange& rRange ) const
{
SCROW nStartRow = rRange.aStart.Row();