[ooo-build-commit] .: sc/inc sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Tue Oct 5 11:10:47 PDT 2010


 sc/inc/table.hxx                 |    8 
 sc/source/core/data/document.cxx |    3 
 sc/source/core/data/table1.cxx   |  318 +++++++++++++++++++++++++--------------
 3 files changed, 221 insertions(+), 108 deletions(-)

New commits:
commit c1cfb775ee4382505372b5e41886cfec9357a78e
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Tue Oct 5 14:06:55 2010 -0400

    Ported calc-perf-ods-import-row-heights.diff from ooo-build.
    
    Avoid re-calculating cell note positions on every single row height
    change during import.  That makes file load take forever.

diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 39818bf..82d0e70 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -606,6 +606,14 @@ public:
                                     const Fraction& rZoomX, const Fraction& rZoomY,
                                     BOOL bForce,
                                     ScProgress* pOuterProgress = NULL, ULONG nProgressStart = 0 );
+
+    void        SetOptimalHeightOnly(SCROW nStartRow, SCROW nEndRow, USHORT nExtra,
+                                     OutputDevice* pDev,
+                                     double nPPTX, double nPPTY,
+                                     const Fraction& rZoomX, const Fraction& rZoomY,
+                                     BOOL bForce,
+                                     ScProgress* pOuterProgress = NULL, ULONG nProgressStart = 0 );
+
     long		GetNeededSize( SCCOL nCol, SCROW nRow,
                                     OutputDevice* pDev,
                                     double nPPTX, double nPPTY,
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index b9dfb4d..998091c 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3344,8 +3344,9 @@ void ScDocument::UpdateAllRowHeights( OutputDevice* pDev, double nPPTX, double n
     for ( SCTAB nTab=0; nTab<=MAXTAB; nTab++ )
         if ( pTab[nTab] && ( !pTabMark || pTabMark->GetTableSelect(nTab) ) )
         {
-            pTab[nTab]->SetOptimalHeight( 0, MAXROW, 0,
+            pTab[nTab]->SetOptimalHeightOnly( 0, MAXROW, 0,
                         pDev, nPPTX, nPPTY, rZoomX, rZoomY, FALSE, &aProgress, nProgressStart );
+            pTab[nTab]->SetDrawPageSize(true, true);
             nProgressStart += pTab[nTab]->GetWeightedCount();
         }
 }
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index d3d707f..cf7e004 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1,7 +1,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -53,6 +53,177 @@
 #include "sheetevents.hxx"
 #include "segmenttree.hxx"
 
+#include <vector>
+
+using ::std::vector;
+
+namespace {
+
+ScProgress* GetProgressBar(
+    SCSIZE nCount, SCSIZE nTotalCount, ScProgress* pOuterProgress, ScDocument* pDoc)
+{
+    if (nTotalCount < 1000)
+    {
+        // if the total number of rows is less than 1000, don't even bother
+        // with the progress bar because drawing progress bar can be very
+        // expensive especially in GTK.
+        return NULL;
+    }
+
+    if (pOuterProgress)
+        return pOuterProgress;
+
+    if (nCount > 1)
+        return new ScProgress(
+            pDoc->GetDocumentShell(), ScGlobal::GetRscString(STR_PROGRESS_HEIGHTING), nTotalCount);
+
+    return NULL;
+}
+
+void GetOptimalHeightsInColumn(
+    ScColumn* pCol, SCROW nStartRow, SCROW nEndRow, vector<USHORT>& aHeights,
+    OutputDevice* pDev, double nPPTX, double nPPTY, const Fraction& rZoomX, const Fraction& rZoomY, bool bForce,
+    ScProgress* pProgress, sal_uInt32 nProgressStart)
+{
+    SCSIZE nCount = static_cast<SCSIZE>(nEndRow-nStartRow+1);
+
+    //	zuerst einmal ueber den ganzen Bereich
+    //	(mit der letzten Spalte in der Hoffnung, dass die am ehesten noch auf
+    //	 Standard formatiert ist)
+
+    pCol[MAXCOL].GetOptimalHeight(
+            nStartRow, nEndRow, &aHeights[0], pDev, nPPTX, nPPTY, rZoomX, rZoomY, bForce, 0, 0 );
+
+    //	daraus Standardhoehe suchen, die im unteren Bereich gilt
+
+    USHORT nMinHeight = aHeights[nCount-1];
+    SCSIZE nPos = nCount-1;
+    while ( nPos && aHeights[nPos-1] >= nMinHeight )
+        --nPos;
+    SCROW nMinStart = nStartRow + nPos;
+
+    ULONG nWeightedCount = 0;
+    for (SCCOL nCol=0; nCol<MAXCOL; nCol++)		// MAXCOL schon oben
+    {
+        pCol[nCol].GetOptimalHeight(
+            nStartRow, nEndRow, &aHeights[0], pDev, nPPTX, nPPTY, rZoomX, rZoomY, bForce,
+            nMinHeight, nMinStart );
+
+        if (pProgress)
+        {
+            ULONG nWeight = pCol[nCol].GetWeightedCount();
+            if (nWeight)		// nochmal denselben Status muss auch nicht sein
+            {
+                nWeightedCount += nWeight;
+                pProgress->SetState( nWeightedCount + nProgressStart );
+            }
+        }
+    }
+}
+
+struct OptimalHeightsFuncObjBase
+{
+    virtual ~OptimalHeightsFuncObjBase() {}
+    virtual bool operator() (SCROW nStartRow, SCROW nEndRow, USHORT nHeight) = 0;
+};
+
+struct SetRowHeightOnlyFunc : public OptimalHeightsFuncObjBase
+{
+    ScTable* mpTab;
+    SetRowHeightOnlyFunc(ScTable* pTab) :
+        mpTab(pTab)
+    {}
+
+    virtual bool operator() (SCROW nStartRow, SCROW nEndRow, USHORT nHeight)
+    {
+        mpTab->SetRowHeightOnly(nStartRow, nEndRow, nHeight);
+        return false;
+    }
+};
+
+struct SetRowHeightRangeFunc : public OptimalHeightsFuncObjBase
+{
+    ScTable* mpTab;
+    double mnPPTX;
+    double mnPPTY;
+
+    SetRowHeightRangeFunc(ScTable* pTab, double nPPTX, double nPPTY) :
+        mpTab(pTab),
+        mnPPTX(nPPTX),
+        mnPPTY(nPPTY)
+    {}
+
+    virtual bool operator() (SCROW nStartRow, SCROW nEndRow, USHORT nHeight)
+    {
+        return mpTab->SetRowHeightRange(nStartRow, nEndRow, nHeight, mnPPTX, mnPPTY);
+    }
+};
+
+bool SetOptimalHeightsToRows(OptimalHeightsFuncObjBase& rFuncObj,
+    ScBitMaskCompressedArray<SCROW, BYTE>* pRowFlags, SCROW nStartRow, SCROW nEndRow, USHORT nExtra,
+    const vector<USHORT>& aHeights, bool bForce)
+{
+    SCSIZE nCount = static_cast<SCSIZE>(nEndRow-nStartRow+1);
+    bool bChanged = false;
+    SCROW nRngStart = 0;
+    SCROW nRngEnd = 0;
+    USHORT nLast = 0;
+    for (SCSIZE i=0; i<nCount; i++)
+    {
+        size_t nIndex;
+        SCROW nRegionEndRow;
+        BYTE nRowFlag = pRowFlags->GetValue( nStartRow+i, nIndex, nRegionEndRow );
+        if ( nRegionEndRow > nEndRow )
+            nRegionEndRow = nEndRow;
+        SCSIZE nMoreRows = nRegionEndRow - ( nStartRow+i );     // additional equal rows after first
+
+        bool bAutoSize = ((nRowFlag & CR_MANUALSIZE) == 0);
+        if ( bAutoSize || bForce )
+        {
+            if (nExtra)
+            {
+                if (bAutoSize)
+                    pRowFlags->SetValue( nStartRow+i, nRegionEndRow, nRowFlag | CR_MANUALSIZE);
+            }
+            else if (!bAutoSize)
+                pRowFlags->SetValue( nStartRow+i, nRegionEndRow, nRowFlag & ~CR_MANUALSIZE);
+
+            for (SCSIZE nInner = i; nInner <= i + nMoreRows; ++nInner)
+            {
+                if (nLast)
+                {
+                    if (aHeights[nInner]+nExtra == nLast)
+                        nRngEnd = nStartRow+nInner;
+                    else
+                    {
+                        bChanged |= rFuncObj(nRngStart, nRngEnd, nLast);
+                        nLast = 0;
+                    }
+                }
+                if (!nLast)
+                {
+                    nLast = aHeights[nInner]+nExtra;
+                    nRngStart = nStartRow+nInner;
+                    nRngEnd = nStartRow+nInner;
+                }
+            }
+        }
+        else
+        {
+            if (nLast)
+                bChanged |= rFuncObj(nRngStart, nRngEnd, nLast);
+            nLast = 0;
+        }
+        i += nMoreRows;     // already handled - skip
+    }
+    if (nLast)
+        bChanged |= rFuncObj(nRngStart, nRngEnd, nLast);
+
+    return bChanged;
+}
+
+}
+
 // -----------------------------------------------------------------------
 
 ScTable::ScTable( ScDocument* pDoc, SCTAB nNewTab, const String& rNewName,
@@ -290,120 +461,53 @@ BOOL ScTable::SetOptimalHeight( SCROW nStartRow, SCROW nEndRow, USHORT nExtra,
         return FALSE;
     }
 
-    BOOL    bChanged = FALSE;
     SCSIZE  nCount = static_cast<SCSIZE>(nEndRow-nStartRow+1);
 
-    ULONG nTotalCount = GetWeightedCount();
-    ScProgress* pProgress = NULL;
-    if (nTotalCount >= 1000)
-    {
-        // if the total number of rows is less than 1000, don't even bother
-        // with the progress bar because drawing progress bar can be very
-        // expensive especially in GTK.
+    ScProgress* pProgress = GetProgressBar(nCount, GetWeightedCount(), pOuterProgress, pDocument);
 
-        if ( pOuterProgress )
-            pProgress = pOuterProgress;
-        else if ( nCount > 1 )
-            pProgress = new ScProgress(
-                pDocument->GetDocumentShell(),
-                ScGlobal::GetRscString(STR_PROGRESS_HEIGHTING), nTotalCount );
-    }
+    vector<USHORT> aHeights(nCount, 0);
 
-    USHORT* pHeight = new USHORT[nCount];                   // Twips !
-    memset( pHeight, 0, sizeof(USHORT) * nCount );
+    GetOptimalHeightsInColumn(
+        aCol, nStartRow, nEndRow, aHeights, pDev, nPPTX, nPPTY, rZoomX, rZoomY, bForce,
+        pProgress, nProgressStart);
 
-    //	zuerst einmal ueber den ganzen Bereich
-    //	(mit der letzten Spalte in der Hoffnung, dass die am ehesten noch auf
-    //	 Standard formatiert ist)
+    SetRowHeightRangeFunc aFunc(this, nPPTX, nPPTY);
+    bool bChanged = SetOptimalHeightsToRows(
+        aFunc, pRowFlags, nStartRow, nEndRow, nExtra, aHeights, bForce);
 
-    aCol[MAXCOL].GetOptimalHeight(
-            nStartRow, nEndRow, pHeight, pDev, nPPTX, nPPTY, rZoomX, rZoomY, bForce, 0, 0 );
+    if ( pProgress != pOuterProgress )
+        delete pProgress;
 
-    //	daraus Standardhoehe suchen, die im unteren Bereich gilt
+    return bChanged;
+}
 
-    USHORT nMinHeight = pHeight[nCount-1];
-    SCSIZE nPos = nCount-1;
-    while ( nPos && pHeight[nPos-1] >= nMinHeight )
-        --nPos;
-    SCROW nMinStart = nStartRow + nPos;
+void ScTable::SetOptimalHeightOnly( SCROW nStartRow, SCROW nEndRow, USHORT nExtra,
+                                OutputDevice* pDev,
+                                double nPPTX, double nPPTY,
+                                const Fraction& rZoomX, const Fraction& rZoomY,
+                                BOOL bForce, ScProgress* pOuterProgress, ULONG nProgressStart )
+{
+    DBG_ASSERT( nExtra==0 || bForce, "autom. OptimalHeight mit Extra" );
 
-    ULONG nWeightedCount = 0;
-    for (SCCOL nCol=0; nCol<MAXCOL; nCol++)		// MAXCOL schon oben
-    {
-        aCol[nCol].GetOptimalHeight(
-            nStartRow, nEndRow, pHeight, pDev, nPPTX, nPPTY, rZoomX, rZoomY, bForce,
-            nMinHeight, nMinStart );
+    if ( !pDocument->IsAdjustHeightEnabled() )
+        return;
 
-        if (pProgress)
-        {
-            ULONG nWeight = aCol[nCol].GetWeightedCount();
-            if (nWeight)		// nochmal denselben Status muss auch nicht sein
-            {
-                nWeightedCount += nWeight;
-                pProgress->SetState( nWeightedCount + nProgressStart );
-            }
-        }
-    }
+    SCSIZE  nCount = static_cast<SCSIZE>(nEndRow-nStartRow+1);
 
-    SCROW nRngStart = 0;
-    SCROW nRngEnd = 0;
-    USHORT nLast = 0;
-    for (SCSIZE i=0; i<nCount; i++)
-    {
-        size_t nIndex;
-        SCROW nRegionEndRow;
-        BYTE nRowFlag = pRowFlags->GetValue( nStartRow+i, nIndex, nRegionEndRow );
-        if ( nRegionEndRow > nEndRow )
-            nRegionEndRow = nEndRow;
-        SCSIZE nMoreRows = nRegionEndRow - ( nStartRow+i );     // additional equal rows after first
+    ScProgress* pProgress = GetProgressBar(nCount, GetWeightedCount(), pOuterProgress, pDocument);
 
-        bool bAutoSize = ((nRowFlag & CR_MANUALSIZE) == 0);
-        if ( bAutoSize || bForce )
-        {
-            if (nExtra)
-            {
-                if (bAutoSize)
-                    pRowFlags->SetValue( nStartRow+i, nRegionEndRow, nRowFlag | CR_MANUALSIZE);
-            }
-            else if (!bAutoSize)
-                pRowFlags->SetValue( nStartRow+i, nRegionEndRow, nRowFlag & ~CR_MANUALSIZE);
+    vector<USHORT> aHeights(nCount, 0);
 
-            for (SCSIZE nInner = i; nInner <= i + nMoreRows; ++nInner)
-            {
-                if (nLast)
-                {
-                    if (pHeight[nInner]+nExtra == nLast)
-                        nRngEnd = nStartRow+nInner;
-                    else
-                    {
-                        bChanged |= SetRowHeightRange( nRngStart, nRngEnd, nLast, nPPTX, nPPTY );
-                        nLast = 0;
-                    }
-                }
-                if (!nLast)
-                {
-                    nLast = pHeight[nInner]+nExtra;
-                    nRngStart = nStartRow+nInner;
-                    nRngEnd = nStartRow+nInner;
-                }
-            }
-        }
-        else
-        {
-            if (nLast)
-                bChanged |= SetRowHeightRange( nRngStart, nRngEnd, nLast, nPPTX, nPPTY );
-            nLast = 0;
-        }
-        i += nMoreRows;     // already handled - skip
-    }
-    if (nLast)
-        bChanged |= SetRowHeightRange( nRngStart, nRngEnd, nLast, nPPTX, nPPTY );
+    GetOptimalHeightsInColumn(
+        aCol, nStartRow, nEndRow, aHeights, pDev, nPPTX, nPPTY, rZoomX, rZoomY, bForce,
+        pProgress, nProgressStart);
+
+    SetRowHeightOnlyFunc aFunc(this);
+    SetOptimalHeightsToRows(
+        aFunc, pRowFlags, nStartRow, nEndRow, nExtra, aHeights, bForce);
 
-    delete[] pHeight;
     if ( pProgress != pOuterProgress )
         delete pProgress;
-
-    return bChanged;
 }
 
 BOOL ScTable::GetCellArea( SCCOL& rEndCol, SCROW& rEndRow ) const
@@ -970,7 +1074,7 @@ void ScTable::GetNextPos( SCCOL& rCol, SCROW& rRow, SCsCOL nMovX, SCsROW nMovY,
     {
         BOOL bUp = ( nMovY < 0 );
         nRow = rMark.GetNextMarked( nCol, nRow, bUp );
-        while ( VALIDROW(nRow) && 
+        while ( VALIDROW(nRow) &&
                 (RowHidden(nRow) || pDocument->HasAttrib(nCol, nRow, nTab, nCol, nRow, nTab, HASATTR_OVERLAPPED)) )
         {
             //	#53697# ausgeblendete ueberspringen (s.o.)
@@ -1000,7 +1104,7 @@ void ScTable::GetNextPos( SCCOL& rCol, SCROW& rRow, SCsCOL nMovX, SCsROW nMovY,
             else if (nRow > MAXROW)
                 nRow = 0;
             nRow = rMark.GetNextMarked( nCol, nRow, bUp );
-            while ( VALIDROW(nRow) && 
+            while ( VALIDROW(nRow) &&
                     (RowHidden(nRow) || pDocument->HasAttrib(nCol, nRow, nTab, nCol, nRow, nTab, HASATTR_OVERLAPPED)) )
             {
                 //	#53697# ausgeblendete ueberspringen (s.o.)
@@ -1612,7 +1716,7 @@ ScTable::VisibleDataCellIterator::VisibleDataCellIterator(ScFlatBoolRowSegments&
     mrRowSegs(rRowSegs),
     mrColumn(rColumn),
     mpCell(NULL),
-    mnCurRow(ROW_NOT_FOUND), 
+    mnCurRow(ROW_NOT_FOUND),
     mnUBound(ROW_NOT_FOUND)
 {
 }
@@ -1624,20 +1728,20 @@ ScTable::VisibleDataCellIterator::~VisibleDataCellIterator()
 ScBaseCell* ScTable::VisibleDataCellIterator::reset(SCROW nRow)
 {
     if (nRow > MAXROW)
-    {    
+    {
         mnCurRow = ROW_NOT_FOUND;
         return NULL;
     }
 
     ScFlatBoolRowSegments::RangeData aData;
     if (!mrRowSegs.getRangeData(nRow, aData))
-    {    
+    {
         mnCurRow = ROW_NOT_FOUND;
         return NULL;
     }
 
     if (!aData.mbValue)
-    {    
+    {
         // specified row is visible.  Take it.
         mnCurRow = nRow;
         mnUBound = aData.mnRow2;
@@ -1649,7 +1753,7 @@ ScBaseCell* ScTable::VisibleDataCellIterator::reset(SCROW nRow)
         mnCurRow = aData.mnRow2 + 1;
         mnUBound = mnCurRow; // get range data on the next iteration.
         if (mnCurRow > MAXROW)
-        {    
+        {
             // Make sure the row doesn't exceed our current limit.
             mnCurRow = ROW_NOT_FOUND;
             return NULL;
@@ -1699,7 +1803,7 @@ ScBaseCell* ScTable::VisibleDataCellIterator::next()
             return mpCell;
     }
     mnCurRow = ROW_NOT_FOUND;
-    return NULL;    
+    return NULL;
 }
 
 SCROW ScTable::VisibleDataCellIterator::getRow() const


More information about the ooo-build-commit mailing list