sc/source/core/data/column.cxx | 66 ++++++++++++++++------------------------ sc/source/core/data/column3.cxx | 39 +++++++++-------------- 2 files changed, 43 insertions(+), 62 deletions(-)
New commits: commit 7cc10ff6cac7fdac9fcc258cbaaf0fcd8bd890ed Author: Laurent Godard <lgodard.li...@laposte.net> Date: Wed Sep 18 17:22:32 2013 +0200 refactor copy handlers - no more segfault in unit test - loop on rows is suboptimal Change-Id: I40ce1babc8e54807545a34bd2719df90088b75c2 diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 4cdcf9a..3438165 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -1302,33 +1302,24 @@ class CopyToClipHandler } } - void duplicateNotes(SCROW nStartRow, size_t nOffset, size_t nDataSize ) + void duplicateNotes(SCROW nStartRow, size_t nDataSize ) // TODO : notes suboptimal { sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore(); - std::vector<ScPostIt*> aNotes; - aNotes.reserve(nDataSize); - SCROW nRow = nStartRow; + SCROW nRowMax = nStartRow + nDataSize; - sc::CellNoteStoreType::const_iterator itNote = maSrcCellNotes.begin(); - std::advance(itNote, nOffset); - sc::CellNoteStoreType::const_iterator itNoteEnd = itNote; - std::advance(itNoteEnd, nDataSize); - - for (; itNote != itNoteEnd; ++itNote, ++nRow) + for (SCROW nRow = nStartRow; nRow < nRowMax; ++nRow) + { + ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow); + if (pSrcNote) { - ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow); - if (pSrcNote) - { - ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab()); - ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ), - mrDestCol.GetDoc(), - aDestPos, true ); - aNotes.push_back(pClonedNote); - } + ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab()); + ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ), + mrDestCol.GetDoc(), + aDestPos, true ); + mrDestCol.GetDoc().ReleaseNote(aDestPos); + mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote); } - - maDestPos.miCellNotePos = mrDestCol.GetCellNoteStore().set( - maDestPos.miCellNotePos, nStartRow, aNotes.begin(), aNotes.end()); + } } public: @@ -1438,7 +1429,7 @@ public: setDefaultAttrsToDest(nTopRow, nDataSize); if (mbCopyNotes) - duplicateNotes(nTopRow, nOffset, nDataSize ); + duplicateNotes(nTopRow, nDataSize ); } }; @@ -1852,25 +1843,24 @@ class CopyByCloneHandler } } - void duplicateNotes(SCROW nStartRow, size_t nOffset, size_t nDataSize ) // TODO : notes suboptimal + void duplicateNotes(SCROW nStartRow, size_t nDataSize ) // TODO : notes suboptimal { sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore(); + SCROW nRowMax = nStartRow + nDataSize; - for (SCROW nRow = nStartRow; nRow < nStartRow + nDataSize; ++nRow) + for (SCROW nRow = nStartRow; nRow < nRowMax; ++nRow) + { + ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow); + if (pSrcNote) { - ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow); - ScPostIt* pClonedNote; - if (pSrcNote) - { - ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab()); - pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ), - mrDestCol.GetDoc(), - aDestPos, true ); - mrDestCol.GetDoc().ReleaseNote(aDestPos); - mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote); - } + ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab()); + ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ), + mrDestCol.GetDoc(), + aDestPos, true ); + mrDestCol.GetDoc().ReleaseNote(aDestPos); + mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote); } - + } } public: @@ -1892,7 +1882,7 @@ public: size_t nRow = aNode.position + nOffset; if (mnCopyFlags & (IDF_NOTE|IDF_ADDNOTES)) - duplicateNotes(nRow, nOffset, nDataSize ); + duplicateNotes(nRow, nDataSize ); switch (aNode.type) { diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 31a4ff3..f8ef4c5 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -697,34 +697,25 @@ class CopyCellsFromClipHandler maDestBlockPos, nDestRow, new ScFormulaCell(&mrDestCol.GetDoc(), aDestPos, &aArr)); } - void duplicateNotes(SCROW nStartRow, size_t nOffset, size_t nDataSize ) + void duplicateNotes(SCROW nStartRow, size_t nDataSize ) // TODO : notes suboptimal { sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore(); - std::vector<ScPostIt*> aNotes; - aNotes.reserve(nDataSize); - SCROW nRow = nStartRow; - sc::CellNoteStoreType::const_iterator itNote = maSrcCellNotes.begin(); - std::advance(itNote, nOffset); - sc::CellNoteStoreType::const_iterator itNoteEnd = itNote; - std::advance(itNoteEnd, nDataSize); + SCROW nRowMax = nStartRow + nDataSize; - for (; itNote != itNoteEnd; ++itNote, ++nRow) + for (SCROW nRow = nStartRow; nRow < nRowMax; ++nRow) + { + ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow); + if (pSrcNote) { - ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow); - ScPostIt* pClonedNote; - if (pSrcNote) - { - ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow+mnRowOffset, mrDestCol.GetTab()); - pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ), - mrDestCol.GetDoc(), - aDestPos, true ); - } - aNotes.push_back(pClonedNote); + ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow+mnRowOffset, mrDestCol.GetTab()); + ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ), + mrDestCol.GetDoc(), + aDestPos, true ); + mrDestCol.GetDoc().ReleaseNote(aDestPos); + mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote); } - - maDestBlockPos.miCellNotePos = mrDestCol.GetCellNoteStore().set( - maDestBlockPos.miCellNotePos, nStartRow+mnRowOffset, aNotes.begin(), aNotes.end()); + } } public: @@ -761,7 +752,7 @@ public: if (node.type == sc::element_type_empty) { if (bCopyCellNotes) - duplicateNotes(nSrcRow1, nOffset, nDataSize ); + duplicateNotes(nSrcRow1, nDataSize ); return; } @@ -928,7 +919,7 @@ public: ; } if (bCopyCellNotes) - duplicateNotes(nSrcRow1, nOffset, nDataSize ); + duplicateNotes(nSrcRow1, nDataSize ); } }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits