[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Thu May 16 10:51:32 PDT 2013


 sc/inc/clipcontext.hxx              |   10 +++--
 sc/source/core/data/clipcontext.cxx |   65 +++++++++++++-----------------------
 sc/source/core/data/document.cxx    |   19 +---------
 3 files changed, 32 insertions(+), 62 deletions(-)

New commits:
commit a38e13f50998d9cc50f737f0352e2676af96f44a
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu May 16 13:52:33 2013 -0400

    Cleaned up a bit to remove the need to initialize the block positions.
    
    Change-Id: Iad2e69e4eb61167ad85581a83b19e3798c5edfd0

diff --git a/sc/inc/clipcontext.hxx b/sc/inc/clipcontext.hxx
index 8b1f261..53f2110 100644
--- a/sc/inc/clipcontext.hxx
+++ b/sc/inc/clipcontext.hxx
@@ -27,6 +27,8 @@ class CopyFromClipContext
 
     TablesType maTables;
 
+    ScDocument& mrDoc;
+
     ScDocument* mpRefUndoDoc;
     ScDocument* mpClipDoc;
     sal_uInt16  mnInsertFlag;
@@ -36,16 +38,16 @@ class CopyFromClipContext
     bool        mbSkipAttrForEmptyCells:1;
 
     CopyFromClipContext(); // disabled
+
 public:
-    CopyFromClipContext(
+    CopyFromClipContext(ScDocument& rDoc,
         ScDocument* pRefUndoDoc, ScDocument* pClipDoc, sal_uInt16 nInsertFlag,
         bool bAsLink, bool bSkipAttrForEmptyCells);
 
-    bool initBlockPositions(ScDocument& rDoc, SCCOL nCol1, SCCOL nCol2);
-    void setTabRange(SCTAB nStart, SCTAB nEnd);
-
     ~CopyFromClipContext();
 
+    void setTabRange(SCTAB nStart, SCTAB nEnd);
+
     ColumnBlockPosition* getBlockPosition(SCTAB nTab, SCCOL nCol);
 
     ScDocument* getUndoDoc();
diff --git a/sc/source/core/data/clipcontext.cxx b/sc/source/core/data/clipcontext.cxx
index e3e66a2..1d19dd1 100644
--- a/sc/source/core/data/clipcontext.cxx
+++ b/sc/source/core/data/clipcontext.cxx
@@ -12,9 +12,10 @@
 
 namespace sc {
 
-CopyFromClipContext::CopyFromClipContext(
+CopyFromClipContext::CopyFromClipContext(ScDocument& rDoc,
     ScDocument* pRefUndoDoc, ScDocument* pClipDoc, sal_uInt16 nInsertFlag,
     bool bAsLink, bool bSkipAttrForEmptyCells) :
+    mrDoc(rDoc),
     mpRefUndoDoc(pRefUndoDoc), mpClipDoc(pClipDoc), mnInsertFlag(nInsertFlag),
     mnTabStart(-1), mnTabEnd(-1),
     mbAsLink(bAsLink), mbSkipAttrForEmptyCells(bSkipAttrForEmptyCells) {}
@@ -23,44 +24,6 @@ CopyFromClipContext::~CopyFromClipContext()
 {
 }
 
-bool CopyFromClipContext::initBlockPositions(ScDocument& rDoc, SCCOL nCol1, SCCOL nCol2)
-{
-    if (mnTabStart < 0 || mnTabEnd < 0 || mnTabStart > mnTabEnd)
-        return false;
-
-    size_t nSize = mnTabEnd - mnTabStart + 1;
-    if (maTables.size() < nSize)
-        maTables.resize(nSize);
-
-    for (size_t i = 0; i < nSize; ++i)
-    {
-        SCTAB nTab = i + mnTabStart;
-        ColumnsType& rCols = maTables[i];
-        for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
-        {
-            ColumnsType::iterator it = rCols.find(nCol);
-            if (it != rCols.end())
-                // This column has already been initialized. Skip it.
-                continue;
-
-            std::pair<ColumnsType::iterator,bool> r =
-                rCols.insert(
-                    ColumnsType::value_type(nCol, ColumnBlockPosition()));
-
-            if (!r.second)
-                // insertion failed.
-                return false;
-
-            it = r.first;
-
-            if (!rDoc.InitColumnBlockPosition(it->second, nTab, nCol))
-                return false;
-        }
-    }
-
-    return true;
-}
-
 void CopyFromClipContext::setTabRange(SCTAB nStart, SCTAB nEnd)
 {
     mnTabStart = nStart;
@@ -69,14 +32,34 @@ void CopyFromClipContext::setTabRange(SCTAB nStart, SCTAB nEnd)
 
 ColumnBlockPosition* CopyFromClipContext::getBlockPosition(SCTAB nTab, SCCOL nCol)
 {
+    if (mnTabStart < 0 || mnTabEnd < 0 || mnTabStart > mnTabEnd)
+        return NULL;
+
     size_t nTabIndex = nTab - mnTabStart;
     if (nTabIndex >= maTables.size())
-        return NULL;
+        maTables.resize(nTabIndex+1);
 
     ColumnsType& rCols = maTables[nTabIndex];
+
     ColumnsType::iterator it = rCols.find(nCol);
+    if (it != rCols.end())
+        // Block position for this column has already been fetched.
+        return &it->second;
+
+    std::pair<ColumnsType::iterator,bool> r =
+        rCols.insert(
+            ColumnsType::value_type(nCol, ColumnBlockPosition()));
+
+    if (!r.second)
+        // insertion failed.
+        return NULL;
+
+    it = r.first;
+
+    if (!mrDoc.InitColumnBlockPosition(it->second, nTab, nCol))
+        return NULL;
 
-    return it == rCols.end() ? NULL : &it->second;
+    return &it->second;
 }
 
 ScDocument* CopyFromClipContext::getUndoDoc()
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 213b4f5..b8d4497 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -2515,7 +2515,7 @@ void ScDocument::CopyFromClip( const ScRange& rDestRange, const ScMarkData& rMar
     if ( ( nInsFlag & IDF_ATTRIB ) && !bSkipAttrForEmpty )
         nDelFlag |= IDF_ATTRIB;
 
-    sc::CopyFromClipContext aCxt(pRefUndoDoc, pClipDoc, nInsFlag, bAsLink, bSkipAttrForEmpty);
+    sc::CopyFromClipContext aCxt(*this, pRefUndoDoc, pClipDoc, nInsFlag, bAsLink, bSkipAttrForEmpty);
     std::pair<SCTAB,SCTAB> aTabRanges = getMarkedTableRange(maTabs, rMark);
     aCxt.setTabRange(aTabRanges.first, aTabRanges.second);
 
@@ -2526,18 +2526,6 @@ void ScDocument::CopyFromClip( const ScRange& rDestRange, const ScMarkData& rMar
         pDestRanges = &aLocalRangeList;
     }
 
-    // Initialize column block positions first.
-    for (size_t nRange = 0; nRange < pDestRanges->size(); ++nRange)
-    {
-        const ScRange* pRange = (*pDestRanges)[nRange];
-        SCCOL nCol1 = pRange->aStart.Col();
-        SCCOL nCol2 = pRange->aEnd.Col();
-
-        if (!aCxt.initBlockPositions(*this, nCol1, nCol2))
-            // Initialization failed!
-            return;
-    }
-
     bInsertingFromOtherDoc = true;  // kein Broadcast/Listener aufbauen bei Insert
 
     SCCOL nClipStartCol = aClipRange.aStart.Col();
@@ -2646,7 +2634,7 @@ void ScDocument::CopyMultiRangeFromClip(
     SCROW nRow1 = rDestPos.Row();
     ScClipParam& rClipParam = pClipDoc->GetClipParam();
 
-    sc::CopyFromClipContext aCxt(NULL, pClipDoc, nInsFlag, bAsLink, bSkipAttrForEmpty);
+    sc::CopyFromClipContext aCxt(*this, NULL, pClipDoc, nInsFlag, bAsLink, bSkipAttrForEmpty);
     std::pair<SCTAB,SCTAB> aTabRanges = getMarkedTableRange(maTabs, rMark);
     aCxt.setTabRange(aTabRanges.first, aTabRanges.second);
 
@@ -2671,9 +2659,6 @@ void ScDocument::CopyMultiRangeFromClip(
         SCsROW nDy = static_cast<SCsROW>(nBegRow - p->aStart.Row());
         SCCOL nCol2 = nCol1 + p->aEnd.Col() - p->aStart.Col();
 
-        if (!aCxt.initBlockPositions(*this, nCol1, nCol2))
-            return;
-
         SCROW nEndRow = lcl_getLastNonFilteredRow(rFlags, nBegRow, nLastMarkedRow, nRowCount);
 
         if (!bSkipAttrForEmpty)


More information about the Libreoffice-commits mailing list