[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    KSpread: OpenDocument Saving Speedup (Part 2: Column Processing)
From:       Stefan Nikolaus <stefan.nikolaus () kdemail ! net>
Date:       2006-04-29 12:43:30
Message-ID: 200604291443.34073.stefan.nikolaus () kdemail ! net
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi,

here's the second part of the OpenDocument saving improvement, that should get 
reviewed by another KSpread developer.

It is similar to the first one. This time the processing of the columns should 
become faster.

Same approach: Using the cluster functionality. The ColumnCluster hasn't had 
a 'next' method before the saving speedup patch, so I've implemented it.

The next chunk follows (hopefully) today ...

Bye,
Stefan

["saving-speedup-2.diff" (text/x-diff)]

Index: kspread_sheet.cc
===================================================================
--- kspread_sheet.cc	(Revision 535329)
+++ kspread_sheet.cc	(Arbeitskopie)
@@ -7302,12 +7302,23 @@
 }
 
 
-void Sheet::saveOasisColRowCell( KoXmlWriter& xmlWriter, KoGenStyles &mainStyles, \
int maxCols, int maxRows, GenValidationStyles &valStyle ) +void \
Sheet::saveOasisColRowCell( KoXmlWriter& xmlWriter, KoGenStyles &mainStyles, +        \
int maxCols, int maxRows, GenValidationStyles &valStyle )  {
+    kdDebug() << "Sheet::saveOasisColRowCell: " << d->name << endl;
+    kdDebug() << "maxCols: " << maxCols << endl;
+    kdDebug() << "maxRows: " << maxRows << endl;
+
+    // saving the columns
+    //
     int i = 1;
-    while ( i <= maxCols )
+    ColumnFormat* column = columnFormat( i );
+    ColumnFormat* nextColumn = d->columns.next( i );
+    while ( !column->isDefault() || nextColumn )
     {
-        ColumnFormat* column = columnFormat( i );
+        kdDebug() << "Sheet::saveOasisColRowCell: first col loop:"
+                  << " i: " << i
+                  << " column: " << column->column() << endl;
         KoGenStyle currentColumnStyle( Doc::STYLE_COLUMN, "table-column" );
         currentColumnStyle.addPropertyPt( "style:column-width", column->dblWidth() \
                );/*FIXME pt and not mm */
         currentColumnStyle.addProperty( "fo:break-before", "auto" );/*FIXME auto or \
not ?*/ @@ -7316,31 +7327,53 @@
         KoGenStyle currentDefaultCellStyle; // the type is determined in \
                saveOasisCellStyle
         QString currentDefaultCellStyleName = column->saveOasisCellStyle( \
currentDefaultCellStyle, mainStyles );  
-
         bool hide = column->isHide();
+        bool refColumnIsDefault = column->isDefault();
         int j = i + 1;
         int repeated = 1;
-        while ( j <= maxCols )
+
+        while ( nextColumn )
         {
-            ColumnFormat* nextColumn = columnFormat( j );
-            KoGenStyle nextColumnStyle( Doc::STYLE_COLUMN, "table-column" );
-            nextColumnStyle.addPropertyPt( "style:column-width", \
                nextColumn->dblWidth() );/*FIXME pt and not mm */
-            nextColumnStyle.addProperty( "fo:break-before", "auto" );/*FIXME auto or \
not ?*/ +          kdDebug() << "Sheet::saveOasisColRowCell: second col loop:"
+                    << " j: " << j
+                    << " column: " << nextColumn->column() << endl;
+          // not the adjacent column?
+          if ( nextColumn->column() != j )
+          {
+            if ( refColumnIsDefault )
+            {
+              // if the origin column was a default column,
+              // we count the default columns
+              repeated = nextColumn->column() - j + 1;
+            }
+            // otherwise we just stop here to process the adjacent
+            // column in the next iteration of the outer loop
+            break;
+          }
 
-            KoGenStyle nextDefaultCellStyle; // the type is determined in \
                saveOasisCellStyle
-            QString nextDefaultCellStyleName = nextColumn->saveOasisCellStyle( \
nextDefaultCellStyle, mainStyles ); +          KoGenStyle nextColumnStyle( \
Doc::STYLE_COLUMN, "table-column" ); +          nextColumnStyle.addPropertyPt( \
"style:column-width", nextColumn->dblWidth() );/*FIXME pt and not mm */ +          \
nextColumnStyle.addProperty( "fo:break-before", "auto" );/*FIXME auto or not ?*/  
-            //FIXME all the time repeate == 2
-            if ( ( nextColumnStyle == currentColumnStyle ) && ( hide == \
nextColumn->isHide() ) && ( nextDefaultCellStyleName == currentDefaultCellStyleName ) \
                )
-                ++repeated;
-            else
-                break;
-            ++j;
+          KoGenStyle nextDefaultCellStyle; // the type is determined in \
saveOasisCellStyle +          QString nextDefaultCellStyleName = \
nextColumn->saveOasisCellStyle( nextDefaultCellStyle, mainStyles ); +
+          if ( hide != nextColumn->isHide() ||
+               nextDefaultCellStyleName != currentDefaultCellStyleName ||
+               !( nextColumnStyle == currentColumnStyle ) )
+          {
+            break;
+          }
+
+          ++repeated;
+          nextColumn = d->columns.next( j++ );
         }
+
         xmlWriter.startElement( "table:table-column" );
         xmlWriter.addAttribute( "table:style-name", mainStyles.lookup( \
                currentColumnStyle, "co" ) );
-        //FIXME doesn't create format if it's default format
 
+        //FIXME don't create format if it's default format
+
         // skip 'table:default-cell-style-name' attribute for the default style
         if ( !currentDefaultCellStyle.isDefaultStyle() )
             xmlWriter.addAttribute( "table:default-cell-style-name", \
currentDefaultCellStyleName ); @@ -7350,8 +7383,17 @@
 
         if ( repeated > 1 )
             xmlWriter.addAttribute( "table:number-columns-repeated", repeated  );
+
         xmlWriter.endElement();
+
+        kdDebug() << "Sheet::saveOasisColRowCell: column " << i << " "
+                  << "repeated " << repeated << " time(s)" << endl;
         i += repeated;
+
+        if ( i > maxCols )
+          break;
+        column = columnFormat( i );
+        nextColumn = d->columns.next( i );
     }
 
     for ( i = 1; i <= maxRows; ++i )
Index: kspread_cluster.cc
===================================================================
--- kspread_cluster.cc	(Revision 535017)
+++ kspread_cluster.cc	(Arbeitskopie)
@@ -160,7 +160,7 @@
 	m_first->setPreviousCell( cell );
     }
     m_first = cell;
-    
+
     if (x > m_biggestX) m_biggestX = x;
     if (y > m_biggestY) m_biggestY = y;
 }
@@ -635,7 +635,7 @@
     int col2, int row2) const
 {
   Value empty;
-  
+
   //swap first/second values if needed
   if (col1 > col2)
   {
@@ -677,10 +677,10 @@
       if (cell)
       {
         Value val = cell->value();
-        array.setElement (col-col1, row-row1, val); 
+        array.setElement (col-col1, row-row1, val);
       }
     }
-  
+
   //return the result
   return array;
 }
@@ -1131,6 +1131,38 @@
     return m_autoDelete;
 }
 
+ColumnFormat* ColumnCluster::next( int col ) const
+{
+  if ( col >= KSPREAD_CLUSTER_MAX || col < 0 )
+  {
+    kdDebug(36001) << "ColumnCluster::next: invalid column value (col: "
+        << col << ")" << endl;
+    return 0;
+  }
+
+  int cx = (col + 1) / KSPREAD_CLUSTER_LEVEL2;
+  int dx = (col + 1) % KSPREAD_CLUSTER_LEVEL2;
+
+  while ( cx < KSPREAD_CLUSTER_LEVEL1 )
+  {
+    if ( m_cluster[ cx ] )
+    {
+      while ( dx < KSPREAD_CLUSTER_LEVEL2 )
+      {
+
+        if ( m_cluster[ cx ][  dx ] )
+        {
+          return m_cluster[ cx ][ dx ];
+        }
+        ++dx;
+      }
+    }
+    ++cx;
+    dx = 0;
+  }
+  return 0;
+}
+
 /****************************************************
  *
  * RowCluster
Index: kspread_cluster.h
===================================================================
--- kspread_cluster.h	(Revision 535017)
+++ kspread_cluster.h	(Arbeitskopie)
@@ -137,7 +137,7 @@
 
     /**
      * Removes all elements from the column.
-     * 
+     *
      */
     void clearColumn( int col );
     void clearRow( int row );
@@ -251,7 +251,7 @@
 
     /** helper method used by valueRange */
     Value makeArray (int col1, int row1, int col2, int row2) const;
-    
+
     Cell*** m_cluster;
     Cell* m_first;
     bool m_autoDelete;
@@ -278,7 +278,8 @@
     void setAutoDelete( bool );
     bool autoDelete() const;
 
-    ColumnFormat* first()const { return m_first; }
+    ColumnFormat* first() const { return m_first; }
+    ColumnFormat* next( int col ) const;
 
 private:
     ColumnFormat*** m_cluster;


[Attachment #8 (application/pgp-signature)]

_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic