[Libreoffice-commits] core.git: Branch 'private/kohei/calc-sort-fix' - 2 commits - sc/inc sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Tue Apr 22 20:07:56 PDT 2014


 sc/inc/column.hxx              |    1 
 sc/inc/table.hxx               |    1 
 sc/source/core/data/column.cxx |  332 -----------------------------------------
 sc/source/core/data/table3.cxx |   41 -----
 4 files changed, 3 insertions(+), 372 deletions(-)

New commits:
commit afd890c5f1abfc36fd4b230ccf401a052ecddba6
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Apr 22 23:07:34 2014 -0400

    SwapRow() is no more!
    
    Good riddance.  It was optimized for the old cell storage.
    
    Change-Id: I374194fe211d5b13dd60dbb68b9511a366fb32bd

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 02ec925..3a7dae1 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -186,7 +186,6 @@ public:
 
     void        Delete( SCROW nRow );
     void        FreeAll();
-    void        SwapRow( SCROW nRow1, SCROW nRow2 );
     void        SwapCell( SCROW nRow, ScColumn& rCol);
 
     bool        HasAttrib( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const;
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index b90de97..624a3d4 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -1007,7 +1007,6 @@ private:
     bool        IsSorted(SCCOLROW nStart, SCCOLROW nEnd) const;
     void        DecoladeRow( ScSortInfoArray*, SCROW nRow1, SCROW nRow2 );
     void        SwapCol(SCCOL nCol1, SCCOL nCol2);
-    void        SwapRow(SCROW nRow1, SCROW nRow2);
     short CompareCell(
         sal_uInt16 nSort,
         ScRefCellValue& rCell1, SCCOL nCell1Col, SCROW nCell1Row,
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index de9f65e..89d998b 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -841,338 +841,6 @@ const sc::CellTextAttr* ScColumn::GetCellTextAttr( sc::ColumnBlockConstPosition&
 
 namespace {
 
-ScFormulaCell* cloneFormulaCell(ScDocument* pDoc, const ScAddress& rNewPos, ScFormulaCell& rOldCell)
-{
-    ScFormulaCell* pNew = new ScFormulaCell(rOldCell, *pDoc, rNewPos, SC_CLONECELL_ADJUST3DREL);
-    rOldCell.EndListeningTo(pDoc);
-    pNew->StartListeningTo(pDoc);
-    pNew->SetDirty();
-    return pNew;
-}
-
-}
-
-void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
-{
-    if (nRow1 == nRow2)
-        // Nothing to swap.
-        return;
-
-    // Ensure that nRow1 < nRow2.
-    if (nRow2 < nRow1)
-        std::swap(nRow1, nRow2);
-
-    // Broadcasters (if exist) should NOT be swapped.
-
-    sc::CellStoreType::position_type aPos1 = maCells.position(nRow1);
-    if (aPos1.first == maCells.end())
-        return;
-
-    sc::CellStoreType::position_type aPos2 = maCells.position(aPos1.first, nRow2);
-    if (aPos2.first == maCells.end())
-        return;
-
-    std::vector<SCROW> aRows;
-    aRows.reserve(2);
-    aRows.push_back(nRow1);
-    aRows.push_back(nRow2);
-
-    sc::CellStoreType::iterator it1 = aPos1.first, it2 = aPos2.first;
-
-    if (it1->type == it2->type)
-    {
-        // Both positions are of the same type. Do a simple value swap.
-        switch (it1->type)
-        {
-            case sc::element_type_empty:
-                // Both are empty. Nothing to swap.
-                return;
-            case sc::element_type_numeric:
-                std::swap(
-                    sc::numeric_block::at(*it1->data, aPos1.second),
-                    sc::numeric_block::at(*it2->data, aPos2.second));
-            break;
-            case sc::element_type_string:
-                std::swap(
-                    sc::string_block::at(*it1->data, aPos1.second),
-                    sc::string_block::at(*it2->data, aPos2.second));
-            break;
-            case sc::element_type_edittext:
-                std::swap(
-                    sc::edittext_block::at(*it1->data, aPos1.second),
-                    sc::edittext_block::at(*it2->data, aPos2.second));
-            break;
-            case sc::element_type_formula:
-            {
-                // Swapping of formula cells involve adjustment of references wrt their positions.
-                sc::formula_block::iterator itf1 = sc::formula_block::begin(*it1->data);
-                sc::formula_block::iterator itf2 = sc::formula_block::begin(*it2->data);
-                std::advance(itf1, aPos1.second);
-                std::advance(itf2, aPos2.second);
-
-                // Is it an identical formula in the same group - if so,
-                // take a shortcut to swap the result data:
-                if(!(*itf1)->SwapWithinGroup(*itf2))
-                {
-                    // otherwise we need to really move the formula &
-                    // re-write dependencies etc.
-                    boost::scoped_ptr<ScFormulaCell> pOld1(*itf1);
-                    boost::scoped_ptr<ScFormulaCell> pOld2(*itf2);
-
-                    DetachFormulaCell(aPos1, **itf1);
-                    DetachFormulaCell(aPos2, **itf2);
-                    ScFormulaCell* pNew1 = cloneFormulaCell(pDocument, ScAddress(nCol, nRow1, nTab), *pOld2);
-                    ScFormulaCell* pNew2 = cloneFormulaCell(pDocument, ScAddress(nCol, nRow2, nTab), *pOld1);
-                    *itf1 = pNew1;
-                    *itf2 = pNew2;
-
-                    ActivateNewFormulaCell(aPos1, *pNew1);
-                    ActivateNewFormulaCell(aPos2, *pNew2);
-                }
-            }
-            break;
-            default:
-                ;
-        }
-
-        SwapCellTextAttrs(nRow1, nRow2);
-        SwapCellNotes(nRow1, nRow2);
-        CellStorageModified();
-        BroadcastCells(aRows, SC_HINT_DATACHANGED);
-        return;
-    }
-
-    // The two cells are of different types.
-
-    ScRefCellValue aCell1 = GetCellValue(aPos1.first, aPos1.second);
-    ScRefCellValue aCell2 = GetCellValue(aPos2.first, aPos2.second);
-
-    // Make sure to put cells in row 1 first then row 2!
-
-    if (aCell1.meType == CELLTYPE_NONE)
-    {
-        // cell 1 is empty and cell 2 is not.
-        switch (aCell2.meType)
-        {
-            case CELLTYPE_VALUE:
-                it1 = maCells.set(it1, nRow1, aCell2.mfValue); // it2 becomes invalid.
-                maCells.set_empty(it1, nRow2, nRow2);
-            break;
-            case CELLTYPE_STRING:
-                it1 = maCells.set(it1, nRow1, *aCell2.mpString);
-                maCells.set_empty(it1, nRow2, nRow2);
-            break;
-            case CELLTYPE_EDIT:
-            {
-                it1 = maCells.set(
-                    it1, nRow1, const_cast<EditTextObject*>(aCell2.mpEditText));
-                EditTextObject* p;
-                maCells.release(it1, nRow2, p);
-            }
-            break;
-            case CELLTYPE_FORMULA:
-            {
-                // cell 1 is empty and cell 2 is a formula cell.
-                ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow1, nTab), *aCell2.mpFormula);
-                DetachFormulaCell(aPos2, *aCell2.mpFormula);
-                it1 = maCells.set(it1, nRow1, pNew);
-                maCells.set_empty(it1, nRow2, nRow2); // original formula cell gets deleted.
-                ActivateNewFormulaCell(it1, nRow1, *pNew);
-            }
-            break;
-            default:
-                ;
-        }
-
-        SwapCellTextAttrs(nRow1, nRow2);
-        SwapCellNotes(nRow1, nRow2);
-        CellStorageModified();
-        BroadcastCells(aRows, SC_HINT_DATACHANGED);
-        return;
-    }
-
-    if (aCell2.meType == CELLTYPE_NONE)
-    {
-        // cell 1 is not empty and cell 2 is empty.
-        switch (aCell1.meType)
-        {
-            case CELLTYPE_VALUE:
-                // Value is copied in Cell1.
-                it1 = maCells.set_empty(it1, nRow1, nRow1);
-                maCells.set(it1, nRow2, aCell1.mfValue);
-            break;
-            case CELLTYPE_STRING:
-            {
-                svl::SharedString aStr = *aCell1.mpString; // make a copy.
-                it1 = maCells.set_empty(it1, nRow1, nRow1); // original string is gone.
-                maCells.set(it1, nRow2, aStr);
-            }
-            break;
-            case CELLTYPE_EDIT:
-            {
-                EditTextObject* p;
-                it1 = maCells.release(it1, nRow1, p);
-                maCells.set(it1, nRow2, p);
-            }
-            break;
-            case CELLTYPE_FORMULA:
-            {
-                // cell 1 is a formula cell and cell 2 is empty.
-                ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow2, nTab), *aCell1.mpFormula);
-                DetachFormulaCell(aPos1, *aCell1.mpFormula);
-                it1 = maCells.set_empty(it1, nRow1, nRow1); // original formula cell is gone.
-                it1 = maCells.set(it1, nRow2, pNew);
-                ActivateNewFormulaCell(it1, nRow2, *pNew);
-            }
-            break;
-            default:
-                ;
-        }
-
-        SwapCellTextAttrs(nRow1, nRow2);
-        SwapCellNotes(nRow1, nRow2);
-        CellStorageModified();
-        BroadcastCells(aRows, SC_HINT_DATACHANGED);
-        return;
-    }
-
-    // Neither cells are empty, and they are of different types.
-    switch (aCell1.meType)
-    {
-        case CELLTYPE_VALUE:
-        {
-            switch (aCell2.meType)
-            {
-                case CELLTYPE_STRING:
-                    it1 = maCells.set(it1, nRow1, *aCell2.mpString);
-                break;
-                case CELLTYPE_EDIT:
-                {
-                    it1 = maCells.set(
-                        it1, nRow1, const_cast<EditTextObject*>(aCell2.mpEditText));
-                    EditTextObject* p;
-                    it1 = maCells.release(it1, nRow2, p);
-                }
-                break;
-                case CELLTYPE_FORMULA:
-                {
-                    DetachFormulaCell(aPos2, *aCell2.mpFormula);
-                    ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow1, nTab), *aCell2.mpFormula);
-                    it1 = maCells.set(it1, nRow1, pNew);
-                    ActivateNewFormulaCell(it1, nRow1, *pNew);
-                    // The old formula cell will get overwritten below.
-                }
-                break;
-                default:
-                    ;
-            }
-
-            maCells.set(it1, nRow2, aCell1.mfValue);
-
-        }
-        break;
-        case CELLTYPE_STRING:
-        {
-            svl::SharedString aStr = *aCell1.mpString; // make a copy.
-            switch (aCell2.meType)
-            {
-                case CELLTYPE_VALUE:
-                    it1 = maCells.set(it1, nRow1, aCell2.mfValue);
-                break;
-                case CELLTYPE_EDIT:
-                {
-                    it1 = maCells.set(
-                        it1, nRow1, const_cast<EditTextObject*>(aCell2.mpEditText));
-                    EditTextObject* p;
-                    it1 = maCells.release(it1, nRow2, p); // prevent it being overwritten.
-                }
-                break;
-                case CELLTYPE_FORMULA:
-                {
-                    // cell 1 - string, cell 2 - formula
-                    DetachFormulaCell(aPos2, *aCell2.mpFormula);
-                    ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow1, nTab), *aCell2.mpFormula);
-                    it1 = maCells.set(it1, nRow1, pNew);
-                    ActivateNewFormulaCell(it1, nRow1, *pNew);
-                    // Old formula cell will get overwritten below.
-                }
-                break;
-                default:
-                    ;
-            }
-
-            maCells.set(it1, nRow2, aStr);
-        }
-        break;
-        case CELLTYPE_EDIT:
-        {
-            EditTextObject* p;
-            it1 = maCells.release(it1, nRow1, p);
-
-            switch (aCell2.meType)
-            {
-                case CELLTYPE_VALUE:
-                    it1 = maCells.set(it1, nRow1, aCell2.mfValue);
-                break;
-                case CELLTYPE_STRING:
-                    it1 = maCells.set(it1, nRow1, *aCell2.mpString);
-                break;
-                case CELLTYPE_FORMULA:
-                {
-                    DetachFormulaCell(aPos2, *aCell2.mpFormula);
-                    ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow1, nTab), *aCell2.mpFormula);
-                    it1 = maCells.set(it1, nRow1, pNew);
-                    ActivateNewFormulaCell(it1, nRow1, *pNew);
-                    // Old formula cell will get overwritten below.
-                }
-                break;
-                default:
-                    ;
-            }
-
-            maCells.set(it1, nRow2, const_cast<EditTextObject*>(aCell1.mpEditText));
-        }
-        break;
-        case CELLTYPE_FORMULA:
-        {
-            // cell 1 is a formula cell and cell 2 is not.
-            DetachFormulaCell(aPos1, *aCell1.mpFormula);
-            ScFormulaCell* pNew = cloneFormulaCell(pDocument, ScAddress(nCol, nRow2, nTab), *aCell1.mpFormula);
-            switch (aCell2.meType)
-            {
-                case CELLTYPE_VALUE:
-                    it1 = maCells.set(it1, nRow1, aCell2.mfValue);
-                break;
-                case CELLTYPE_STRING:
-                    it1 = maCells.set(it1, nRow1, *aCell2.mpString);
-                break;
-                case CELLTYPE_EDIT:
-                {
-                    it1 = maCells.set(it1, nRow1, aCell2.mpEditText);
-                    EditTextObject* p;
-                    it1 = maCells.release(it1, nRow2, p);
-                }
-                break;
-                default:
-                    ;
-            }
-
-            it1 = maCells.set(it1, nRow2, pNew);
-            ActivateNewFormulaCell(it1, nRow2, *pNew);
-        }
-        break;
-        default:
-            ;
-    }
-
-    SwapCellTextAttrs(nRow1, nRow2);
-    SwapCellNotes(nRow1, nRow2);
-    CellStorageModified();
-    BroadcastCells(aRows, SC_HINT_DATACHANGED);
-}
-
-namespace {
-
 /**
  * Adjust references in formula cell with respect to column-wise relocation.
  */
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index f39bbbe..acd8f5e 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -935,40 +935,6 @@ void ScTable::SwapCol(SCCOL nCol1, SCCOL nCol2)
     }
 }
 
-void ScTable::SwapRow(SCROW nRow1, SCROW nRow2)
-{
-    SCCOL nColStart = aSortParam.nCol1;
-    SCCOL nColEnd = aSortParam.nCol2;
-    for (SCCOL nCol = nColStart; nCol <= nColEnd; nCol++)
-    {
-        aCol[nCol].SwapRow(nRow1, nRow2);
-        if (aSortParam.bIncludePattern)
-        {
-            const ScPatternAttr* pPat1 = GetPattern(nCol, nRow1);
-            const ScPatternAttr* pPat2 = GetPattern(nCol, nRow2);
-            if (pPat1 != pPat2)
-            {
-                pDocument->GetPool()->Put(*pPat1);
-                SetPattern(nCol, nRow1, *pPat2, true);
-                SetPattern(nCol, nRow2, *pPat1, true);
-                pDocument->GetPool()->Remove(*pPat1);
-            }
-        }
-    }
-    if (bGlobalKeepQuery)
-    {
-        bool bRow1Hidden = RowHidden(nRow1);
-        bool bRow2Hidden = RowHidden(nRow2);
-        SetRowHidden(nRow1, nRow1, bRow2Hidden);
-        SetRowHidden(nRow2, nRow2, bRow1Hidden);
-
-        bool bRow1Filtered = RowFiltered(nRow1);
-        bool bRow2Filtered = RowFiltered(nRow2);
-        SetRowFiltered(nRow1, nRow1, bRow2Filtered);
-        SetRowFiltered(nRow2, nRow2, bRow1Filtered);
-    }
-}
-
 short ScTable::Compare(SCCOLROW nIndex1, SCCOLROW nIndex2) const
 {
     short nRes;
commit e86e96455781ce8792dcc7666c4d247e9dd58128
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Apr 22 22:54:25 2014 -0400

    Use scoped_ptr for this.
    
    Change-Id: I54d0bbe460f95ada7632d7c9cbedb8a677995fd4

diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 88f3ea7..f39bbbe 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2063,9 +2063,9 @@ void ScTable::TopTenQuery( ScQueryParam& rParam )
                     bSortCollatorInitialized = true;
                     InitSortCollator( aLocalSortParam );
                 }
-                ScSortInfoArray* pArray = CreateSortInfoArray(nRow1, rParam.nRow2, bGlobalKeepQuery);
-                DecoladeRow( pArray, nRow1, rParam.nRow2 );
-                QuickSort( pArray, nRow1, rParam.nRow2 );
+                boost::scoped_ptr<ScSortInfoArray> pArray(CreateSortInfoArray(nRow1, rParam.nRow2, bGlobalKeepQuery));
+                DecoladeRow( pArray.get(), nRow1, rParam.nRow2 );
+                QuickSort( pArray.get(), nRow1, rParam.nRow2 );
                 ScSortInfo** ppInfo = pArray->GetFirstArray();
                 SCSIZE nValidCount = nCount;
                 // keine Note-/Leerzellen zaehlen, sind ans Ende sortiert
@@ -2142,7 +2142,6 @@ void ScTable::TopTenQuery( ScQueryParam& rParam )
                     rItem.meType = ScQueryEntry::ByValue;
                     rItem.mfVal = 0;
                 }
-                delete pArray;
             }
             break;
             default:


More information about the Libreoffice-commits mailing list