[Libreoffice-commits] .: 2 commits - sc/inc sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Wed Jan 19 23:10:36 PST 2011


 sc/inc/dptablecache.hxx              |   11 ++++--
 sc/source/core/data/dptablecache.cxx |   59 +++++++++--------------------------
 2 files changed, 23 insertions(+), 47 deletions(-)

New commits:
commit d73cc7750bf562153c06d578b1c4419a72ff2117
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Jan 20 02:08:28 2011 -0500

    Finally, the inner arrays of DataGridType is now ptr_vector.
    
    Also, no point resetting the value of data member in destructor.

diff --git a/sc/inc/dptablecache.hxx b/sc/inc/dptablecache.hxx
index f2c4615..f8c53d5 100644
--- a/sc/inc/dptablecache.hxx
+++ b/sc/inc/dptablecache.hxx
@@ -47,9 +47,11 @@ struct ScQueryParam;
 
 class SC_DLLPUBLIC ScDPTableDataCache
 {
-    typedef ::boost::ptr_vector<ScDPItemData>                   DataListType;
-    typedef ::boost::ptr_vector< ::std::vector<ScDPItemData*> > DataGridType;
-    typedef ::boost::ptr_vector< ::std::vector<SCROW> >         RowGridType;
+public:
+    typedef ::boost::ptr_vector<ScDPItemData>           DataListType;
+private:
+    typedef ::boost::ptr_vector<DataListType>           DataGridType;
+    typedef ::boost::ptr_vector< ::std::vector<SCROW> > RowGridType;
 
     ScDocument* mpDoc;
 
@@ -82,7 +84,7 @@ public:
     SCROW GetDimMemberCount( SCCOL nDim ) const;
 
     SCROW GetSortedItemDataId( SCCOL nDim, SCROW nOrder ) const;
-    const std::vector<ScDPItemData*>& GetDimMemberValues( SCCOL nDim )const;
+    const DataListType& GetDimMemberValues( SCCOL nDim ) const;
     void SetId( long nId ){ mnID = nId;}
     bool InitFromDoc(ScDocument* pDoc, const ScRange& rRange);
     bool InitFromDataBase(const  ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& xRowSet, const Date& rNullDate);
diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx
index 23d2534..3b9ed90 100644
--- a/sc/source/core/data/dptablecache.cxx
+++ b/sc/source/core/data/dptablecache.cxx
@@ -68,7 +68,7 @@ bool lcl_isDate( ULONG nNumType )
     return ( (nNumType & NUMBERFORMAT_DATE) != 0 )? 1:0 ;
 }
 
-bool lcl_Search( const std::vector<ScDPItemData*>& list, const ::std::vector<SCROW>& rOrder, const ScDPItemData& item, SCROW& rIndex)
+bool lcl_Search( const ScDPTableDataCache::DataListType& list, const ::std::vector<SCROW>& rOrder, const ScDPItemData& item, SCROW& rIndex)
 {
     rIndex = list.size();
     bool bFound = false;
@@ -79,7 +79,7 @@ bool lcl_Search( const std::vector<ScDPItemData*>& list, const ::std::vector<SCR
     while (nLo <= nHi)
     {
         nIndex = (nLo + nHi) / 2;
-        nCompare = ScDPItemData::Compare( *list[rOrder[nIndex]], item );
+        nCompare = ScDPItemData::Compare( list[rOrder[nIndex]], item );
         if (nCompare < 0)
             nLo = nIndex + 1;
         else
@@ -381,7 +381,7 @@ bool ScDPTableDataCache::operator== ( const ScDPTableDataCache& r ) const
             {
                 for ( size_t j = 0; j < nMembersCount; j++ )
                 {
-                    if ( *( GetDimMemberValues( i )[j] ) == *( r.GetDimMemberValues( i )[j] ) )
+                    if ( GetDimMemberValues(i)[j] == r.GetDimMemberValues(i)[j] )
                         continue;
                     else
                         return false;
@@ -411,17 +411,6 @@ ScDPTableDataCache::ScDPTableDataCache(ScDocument* pDoc) :
 
 ScDPTableDataCache::~ScDPTableDataCache()
 {
-    if ( IsValid() )
-    {
-        USHORT nCol;
-        for (  nCol=0; nCol < GetColumnCount() ; nCol++ )
-        {
-            for ( ULONG row = 0 ;  row < maTableDataValues[nCol].size(); row++ )
-                delete maTableDataValues[nCol][row];
-        }
-
-        mnColumnCount = 0;
-    }
 }
 
 bool ScDPTableDataCache::IsValid() const
@@ -467,15 +456,9 @@ bool ScDPTableDataCache::InitFromDoc(ScDocument* pDoc, const ScRange& rRange)
     USHORT nEndCol = rRange.aEnd.Col();
     USHORT nDocTab = rRange.aStart.Tab();
 
-    long nOldColumCount = mnColumnCount;
     mnColumnCount = nEndCol - nStartCol + 1;
     if ( IsValid() )
     {
-        for ( USHORT nCol=0; nCol < nOldColumCount ; nCol++ )
-        {
-            for ( ULONG row = 0 ;  row < maTableDataValues[nCol].size(); row++ )
-                delete maTableDataValues[nCol][row];
-        }
         maTableDataValues.clear();
         maSourceData.clear();
         maGlobalOrder.clear();
@@ -489,7 +472,7 @@ bool ScDPTableDataCache::InitFromDoc(ScDocument* pDoc, const ScRange& rRange)
     maIndexOrder.reserve(mnColumnCount);
     for (long i = 0; i < mnColumnCount; ++i)
     {
-        maTableDataValues.push_back(new vector<ScDPItemData*>());
+        maTableDataValues.push_back(new DataListType);
         maSourceData.push_back(new vector<SCROW>());
         maGlobalOrder.push_back(new vector<SCROW>());
         maIndexOrder.push_back(new vector<SCROW>());
@@ -520,15 +503,9 @@ bool ScDPTableDataCache::InitFromDataBase (const Reference<sdbc::XRowSet>& xRowS
         if (!xMeta.is())
             return false;
 
-        long nOldColumCount = mnColumnCount;
         mnColumnCount = xMeta->getColumnCount();
         if (IsValid())
         {
-            for (USHORT nCol=0; nCol < nOldColumCount ; nCol++)
-            {
-                for (ULONG row = 0 ;  row < maTableDataValues[nCol].size(); row++)
-                    delete maTableDataValues[nCol][row];
-            }
             maTableDataValues.clear();
             maSourceData.clear();
             maGlobalOrder.clear();
@@ -544,7 +521,7 @@ bool ScDPTableDataCache::InitFromDataBase (const Reference<sdbc::XRowSet>& xRowS
         maIndexOrder.reserve(mnColumnCount);
         for (long i = 0; i < mnColumnCount; ++i)
         {
-            maTableDataValues.push_back(new vector<ScDPItemData*>());
+            maTableDataValues.push_back(new DataListType);
             maSourceData.push_back(new vector<SCROW>());
             maGlobalOrder.push_back(new vector<SCROW>());
             maIndexOrder.push_back(new vector<SCROW>());
@@ -590,7 +567,7 @@ ULONG ScDPTableDataCache::GetDimNumType( SCCOL nDim) const
     if ( maTableDataValues[nDim].size()==0 )
         return NUMBERFORMAT_UNDEFINED;
     else
-        return GetNumType(maTableDataValues[nDim][0]->nNumFormat);
+        return GetNumType(maTableDataValues[nDim][0].nNumFormat);
 }
 
 bool ScDPTableDataCache::ValidQuery( SCROW nRow, const ScQueryParam &rParam, bool *pSpecial)
@@ -902,7 +879,7 @@ SCROW ScDPTableDataCache::GetItemDataId(USHORT nDim, SCROW nRow, bool bRepeatIfE
 
     if ( bRepeatIfEmpty )
     {
-        while ( nRow >0 && !maTableDataValues[nDim][ maSourceData[nDim][nRow] ]->IsHasData() )
+        while ( nRow >0 && !maTableDataValues[nDim][ maSourceData[nDim][nRow] ].IsHasData() )
         --nRow;
     }
 
@@ -917,7 +894,7 @@ const ScDPItemData* ScDPTableDataCache::GetItemDataById(long nDim, SCROW nId) co
     if (  (size_t)nId >= maTableDataValues[nDim].size() || nDim >= mnColumnCount  || nId < 0  )
         return NULL;
     else
-        return maTableDataValues[nDim][nId];
+        return &maTableDataValues[nDim][nId];
 }
 
 SCROW ScDPTableDataCache::GetRowCount() const
@@ -928,7 +905,7 @@ SCROW ScDPTableDataCache::GetRowCount() const
         return 0;
 }
 
-const std::vector<ScDPItemData*>& ScDPTableDataCache::GetDimMemberValues(SCCOL nDim) const
+const ScDPTableDataCache::DataListType& ScDPTableDataCache::GetDimMemberValues(SCCOL nDim) const
 {
     DBG_ASSERT( nDim>=0 && nDim < mnColumnCount ," nDim < mnColumnCount ");
     return maTableDataValues[nDim];
@@ -959,7 +936,7 @@ ULONG ScDPTableDataCache::GetNumberFormat( long nDim ) const
     if ( maTableDataValues[nDim].size()==0 )
         return 0;
     else
-        return maTableDataValues[nDim][0]->nNumFormat;
+        return maTableDataValues[nDim][0].nNumFormat;
 }
 
 bool ScDPTableDataCache::IsDateDimension( long nDim ) const
@@ -969,7 +946,7 @@ bool ScDPTableDataCache::IsDateDimension( long nDim ) const
     else if ( maTableDataValues[nDim].size()==0 )
         return false;
     else
-        return maTableDataValues[nDim][0]->IsDate();
+        return maTableDataValues[nDim][0].IsDate();
 
 }
 
@@ -1001,7 +978,7 @@ SCROW ScDPTableDataCache::GetIdByItemData(long nDim, String sItemData ) const
     {
         for ( size_t n = 0; n< maTableDataValues[nDim].size(); n++ )
         {
-            if ( maTableDataValues[nDim][n]->GetString() == sItemData )
+            if ( maTableDataValues[nDim][n].GetString() == sItemData )
                 return n;
         }
     }
@@ -1016,7 +993,7 @@ SCROW ScDPTableDataCache::GetIdByItemData( long nDim, const ScDPItemData& rData
     {
         for ( size_t n = 0; n< maTableDataValues[nDim].size(); n++ )
         {
-            if ( *maTableDataValues[nDim][n] == rData )
+            if ( maTableDataValues[nDim][n] == rData )
                 return n;
         }
     }
commit c2379675cdc4d95b1ff43566cfbd56cdf4bb8f84
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Jan 20 01:55:56 2011 -0500

    maLabelNames now stored in ptr_vector.
    
    Thereby further elimination of manual deletion of stored instances.

diff --git a/sc/inc/dptablecache.hxx b/sc/inc/dptablecache.hxx
index 8f57ae4..f2c4615 100644
--- a/sc/inc/dptablecache.hxx
+++ b/sc/inc/dptablecache.hxx
@@ -47,6 +47,7 @@ struct ScQueryParam;
 
 class SC_DLLPUBLIC ScDPTableDataCache
 {
+    typedef ::boost::ptr_vector<ScDPItemData>                   DataListType;
     typedef ::boost::ptr_vector< ::std::vector<ScDPItemData*> > DataGridType;
     typedef ::boost::ptr_vector< ::std::vector<SCROW> >         RowGridType;
 
@@ -59,7 +60,7 @@ class SC_DLLPUBLIC ScDPTableDataCache
     RowGridType                 maSourceData;      // Data Pilot Table's source data
     RowGridType                 maGlobalOrder;     // Sorted members index
     RowGridType                 maIndexOrder;      // Index the sorted numbers
-    std::vector<ScDPItemData*>  maLabelNames;      //Source Label data
+    DataListType                maLabelNames;      // Source label data
     std::vector<bool>           mbEmptyRow;        //If empty row?
 
     mutable ScDPItemDataPool    maAdditionalData;
diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx
index 6ca47fd..23d2534 100644
--- a/sc/source/core/data/dptablecache.cxx
+++ b/sc/source/core/data/dptablecache.cxx
@@ -419,8 +419,6 @@ ScDPTableDataCache::~ScDPTableDataCache()
             for ( ULONG row = 0 ;  row < maTableDataValues[nCol].size(); row++ )
                 delete maTableDataValues[nCol][row];
         }
-        for ( nCol =0; nCol < maLabelNames.size(); nCol++ )
-            delete maLabelNames[nCol];
 
         mnColumnCount = 0;
     }
@@ -477,7 +475,6 @@ bool ScDPTableDataCache::InitFromDoc(ScDocument* pDoc, const ScRange& rRange)
         {
             for ( ULONG row = 0 ;  row < maTableDataValues[nCol].size(); row++ )
                 delete maTableDataValues[nCol][row];
-            delete maLabelNames[nCol];
         }
         maTableDataValues.clear();
         maSourceData.clear();
@@ -531,7 +528,6 @@ bool ScDPTableDataCache::InitFromDataBase (const Reference<sdbc::XRowSet>& xRowS
             {
                 for (ULONG row = 0 ;  row < maTableDataValues[nCol].size(); row++)
                     delete maTableDataValues[nCol][row];
-                delete maLabelNames[nCol];
             }
             maTableDataValues.clear();
             maSourceData.clear();
@@ -862,7 +858,7 @@ String ScDPTableDataCache::GetDimensionName( USHORT nColumn ) const
 
     if ( static_cast<size_t>(nColumn+1) < maLabelNames.size() )
     {
-        return maLabelNames[nColumn+1]->aString;
+        return maLabelNames[nColumn+1].aString;
     }
     else
         return String();
@@ -883,7 +879,7 @@ void ScDPTableDataCache::AddLabel(ScDPItemData *pData)
     {
         for ( long i= maLabelNames.size()-1; i>=0; i-- )
         {
-            if( maLabelNames[i]->aString == strNewName )
+            if( maLabelNames[i].aString == strNewName )
             {
                 strNewName  =  pData->aString;
                 strNewName += String::CreateFromInt32( nIndex );
@@ -993,7 +989,7 @@ SCCOL ScDPTableDataCache::GetDimensionIndex(String sName) const
 {
     for ( size_t n = 1; n < maLabelNames.size(); n ++ )
     {
-        if ( maLabelNames[n]->GetString() == sName )
+        if ( maLabelNames[n].GetString() == sName )
             return (SCCOL)(n-1);
     }
     return -1;


More information about the Libreoffice-commits mailing list