[Libreoffice-commits] core.git: Branch 'aoo/trunk' - sc/inc sc/source

Steve Yin steve_y at apache.org
Fri Jan 3 02:08:10 PST 2014


 sc/inc/attarray.hxx              |    5 +++++
 sc/inc/column.hxx                |    3 +++
 sc/inc/document.hxx              |    4 ++++
 sc/inc/table.hxx                 |    3 +++
 sc/source/core/data/attarray.cxx |   30 ++++++++++++++++++++++++++++++
 sc/source/core/data/column2.cxx  |   14 ++++++++++++--
 sc/source/core/data/documen3.cxx |   24 ++++++++++++++++++++++++
 sc/source/core/data/document.cxx |   35 +++++++++++++++++++++++++++++++++++
 sc/source/core/data/table4.cxx   |   24 +++++++++++++++++++++---
 9 files changed, 137 insertions(+), 5 deletions(-)

New commits:
commit acc76cb44c51fbefc8f34009300acb9382c3ad27
Author: Steve Yin <steve_y at apache.org>
Date:   Fri Jan 3 08:48:02 2014 +0000

    Bug 123909 - Select one column, paste cell range with merged cell in, AOO will be not responding

diff --git a/sc/inc/attarray.hxx b/sc/inc/attarray.hxx
index c4914b2..6771b7c 100644
--- a/sc/inc/attarray.hxx
+++ b/sc/inc/attarray.hxx
@@ -188,6 +188,11 @@ public:
     void    DeleteHardAttr( SCROW nStartRow, SCROW nEndRow );
 
 //UNUSED2008-05  void    ConvertFontsAfterLoad();     // old binary file format
+
+    /* i123909: Pre-calculate needed memory, and pre-reserve enough memory */
+    bool    Reserve( SCSIZE nCount );
+    SCSIZE  Count() const{ return nCount; }
+    SCSIZE  Count( SCROW nRw1, SCROW nRw2 );
 };
 
 
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 45c42f0..e856bf8 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -404,6 +404,9 @@ public:
     xub_StrLen  GetMaxNumberStringLen( sal_uInt16& nPrecision,
                                        SCROW nRowStart, SCROW nRowEnd ) const;
 
+    SCSIZE      GetPatternCount( );
+    SCSIZE      GetPatternCount( SCROW nRw1, SCROW nRw2 );
+    bool        ReservedPatternCount( SCSIZE nReserved );
 private:
     ScBaseCell* CloneCell(SCSIZE nIndex, sal_uInt16 nFlags, ScDocument& rDestDoc, const ScAddress& rDestPos);
 //UNUSED2008-05  void       CorrectSymbolCells( CharSet eStreamCharSet );
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index cf4ac16..88980a2 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1908,6 +1908,10 @@ private: // CLOOK-Impl-Methoden
 
 public:
     void    FillDPCache( ScDPTableDataCache * pCache, SCTAB nDocTab, SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCROW nEndRow );
+private:
+    SCSIZE GetPatternCount( SCTAB nTab, SCCOL nCol );
+    SCSIZE GetPatternCount( SCTAB nTab, SCCOL nCol, SCROW nRw1, SCROW nRw2 );
+    bool   ReservedPatternCount( SCTAB nTab, SCCOL nCol, SCSIZE nReserved );
 };
 inline void ScDocument::GetSortParam( ScSortParam& rParam, SCTAB nTab )
 {
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 0363eda..052f873 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -311,6 +311,9 @@ public:
                            SvNumberFormatter* pFormatter = NULL, bool bDetectNumberFormat = true );
     void        SetValue( SCCOL nCol, SCROW nRow, const double& rVal );
     void        SetError( SCCOL nCol, SCROW nRow, sal_uInt16 nError);
+    SCSIZE      GetPatternCount( SCCOL nCol );
+    SCSIZE      GetPatternCount( SCCOL nCol, SCROW nRw1, SCROW nRw2 );
+    bool        ReservedPatternCount( SCCOL nCol, SCSIZE nReserved );
 
     void        GetString( SCCOL nCol, SCROW nRow, String& rString );
     void    FillDPCache( ScDPTableDataCache * pCache, SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCROW nEndRow );
diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index 78e1594..d2dea6d 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -295,6 +295,24 @@ void ScAttrArray::SetPattern( SCROW nRow, const ScPatternAttr* pPattern, sal_Boo
     SetPatternArea( nRow, nRow, pPattern, bPutToPool );
 }
 
+bool ScAttrArray::Reserve( SCSIZE nReserve )
+{
+    if ( nCount <= nReserve )
+    {
+        if( ScAttrEntry* pNewData = new (std::nothrow) ScAttrEntry[nReserve] )
+        {
+            nLimit = nReserve;
+            memcpy( pNewData, pData, nCount*sizeof(ScAttrEntry) );
+            delete[] pData;
+            pData = pNewData;
+            return true;
+        }
+        else
+            return false;
+    }
+    else
+        return false;
+}
 
 void ScAttrArray::SetPatternArea(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pPattern, sal_Bool bPutToPool )
 {
@@ -2647,3 +2665,15 @@ void ScAttrArray::Load( SvStream& /* rStream */ )
 //UNUSED2008-05      }
 //UNUSED2008-05  }
 
+SCSIZE ScAttrArray::Count( SCROW nStartRow, SCROW nEndRow )
+{
+    SCSIZE  nIndex1, nIndex2;
+
+    if( !Search( nStartRow, nIndex1 ) )
+        return 0;
+
+    if( !Search( nEndRow, nIndex2 ) )
+        nIndex2 = this->nCount - 1;
+
+    return nIndex2 - nIndex1 + 1;
+}
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 4fa3022..8c3f8fb 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1885,7 +1885,17 @@ sal_uLong ScColumn::GetCodeCount() const
     return nCodeCount;
 }
 
+SCSIZE ScColumn::GetPatternCount()
+{
+    return this->pAttrArray ? this->pAttrArray->Count() : 0;
+}
 
+SCSIZE ScColumn::GetPatternCount( SCROW nRw1, SCROW nRw2 )
+{
+    return this->pAttrArray ? this->pAttrArray->Count( nRw1, nRw2 ) : 0;
+}
 
-
-
+bool ScColumn::ReservedPatternCount( SCSIZE nReserved )
+{
+    return this->pAttrArray ? this->pAttrArray->Reserve( nReserved ) : false;
+}
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index df4183e..487eb94 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -2149,3 +2149,27 @@ void ScDocument::GetUsedDPObjectCache( std::list<ScDPTableDataCache*>& usedlist
     }
 }
 // End Comments
+
+SCSIZE ScDocument::GetPatternCount( SCTAB nTab, SCCOL nCol )
+{
+    if( ValidTab(nTab) && pTab[nTab] )
+        return pTab[nTab]->GetPatternCount( nCol );
+    else
+        return 0;
+}
+
+SCSIZE ScDocument::GetPatternCount( SCTAB nTab, SCCOL nCol, SCROW nRw1, SCROW nRw2 )
+{
+    if( ValidTab(nTab) && pTab[nTab] )
+        return pTab[nTab]->GetPatternCount( nCol, nRw1, nRw2 );
+    else
+        return 0;
+}
+
+bool ScDocument::ReservedPatternCount( SCTAB nTab, SCCOL nCol, SCSIZE nReserved )
+{
+    if( ValidTab(nTab) && pTab[nTab] )
+        return pTab[nTab]->ReservedPatternCount( nCol, nReserved );
+    else
+        return false;
+}
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index f28599f..2aefa7a 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -2187,6 +2187,26 @@ void ScDocument::CopyFromClip( const ScRange& rDestRange, const ScMarkData& rMar
                 if (nR2 > nRow2)
                     nR2 = nRow2;
 
+                const unsigned PERFORMANCEOPTIMIZATION4PATTERNTHRESHOLD = 8192;
+                bool bNeedPerformanceOptimization4Pattern = nRow2 - nRow1 > PERFORMANCEOPTIMIZATION4PATTERNTHRESHOLD;
+                std::vector< std::vector< SCSIZE > > vvPatternCount( bNeedPerformanceOptimization4Pattern ? nCol2 - nCol1 + 1 : 0 );
+                std::vector< SCTAB > vTables;
+
+                if( bNeedPerformanceOptimization4Pattern )
+                {
+                    for (SCTAB i = aCBFCP.nTabStart; i <= aCBFCP.nTabEnd; i++)
+                        if (pTab[i] && rMark.GetTableSelect( i ) )
+                            vTables.push_back( i );
+
+                    for( SCSIZE i = 0; i < vvPatternCount.size(); i++ )
+                    {
+                        vvPatternCount[i].resize( vTables.size() );
+
+                        for( std::vector< SCTAB >::size_type j = 0; j<vTables.size(); j++ )
+                            vvPatternCount[i][j] = this->GetPatternCount( vTables[j], nCol1+i );
+                    }
+                }
+
                 do
                 {
                     // Pasting is done column-wise, when pasting to a filtered
@@ -2223,6 +2243,21 @@ void ScDocument::CopyFromClip( const ScRange& rDestRange, const ScMarkData& rMar
                     nC2 = nC1 + nXw;
                     if (nC2 > nCol2)
                         nC2 = nCol2;
+
+                    if( bNeedPerformanceOptimization4Pattern && vvPatternCount.size() )
+                    {
+                        for( SCSIZE i = 0; i < vvPatternCount.size(); i++ )
+                        {
+                            vvPatternCount[i].resize( vTables.size() );
+
+                            for( std::vector< SCTAB >::size_type j = 0; j<vTables.size(); j++ )
+                                this->ReservedPatternCount( vTables[j], nCol1+i, vvPatternCount[i][j] + ( this->GetPatternCount( vTables[j], nCol1+i, nR1, nR2 ) ) * ( ( nRow2 - nRow1 + 1 ) / ( nYw + 1 ) ) );
+                        }
+
+                        bNeedPerformanceOptimization4Pattern = false;
+                        vvPatternCount.clear();
+                    }
+
                     nR1 = nR2 + 1;
                     nR2 = Min((SCROW)(nR1 + nYw), nRow2);
                 } while (nR1 <= nRow2);
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 185b75a..d419d6d 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -2024,8 +2024,26 @@ void ScTable::CompileColRowNameFormula()
     for (SCCOL i=0; i<=MAXCOL; i++) aCol[i].CompileColRowNameFormula();
 }
 
+SCSIZE ScTable::GetPatternCount( SCCOL nCol )
+{
+    if( ValidCol( nCol ) )
+        return aCol[nCol].GetPatternCount();
+    else
+        return 0;
+}
 
+SCSIZE ScTable::GetPatternCount( SCCOL nCol, SCROW nRw1, SCROW nRw2 )
+{
+    if( ValidCol( nCol ) && ValidRow( nRw1 ) && ValidRow( nRw2 ) )
+        return aCol[nCol].GetPatternCount( nRw1, nRw2 );
+    else
+        return 0;
+}
 
-
-
-
+bool ScTable::ReservedPatternCount( SCCOL nCol, SCSIZE nReserved )
+{
+    if( ValidCol( nCol ) )
+        return aCol[nCol].ReservedPatternCount( nReserved );
+    else
+        return false;
+}


More information about the Libreoffice-commits mailing list