Index: source/filter/excel/xehelper.cxx =================================================================== RCS file: /cvs/sc/sc/source/filter/excel/xehelper.cxx,v retrieving revision 1.27.102.1 diff -u -w -p -r1.27.102.1 xehelper.cxx --- source/filter/excel/xehelper.cxx 15 May 2007 15:10:45 -0000 1.27.102.1 +++ source/filter/excel/xehelper.cxx 22 May 2007 15:29:13 -0000 @@ -1137,92 +1137,89 @@ String XclExpUrlHelper::EncodeDde( const // Cached Value Lists ========================================================= -XclExpCachedValue::~XclExpCachedValue() +XclExpCachedMatrix::XclExpCachedMatrix( const ScMatrix& rMatrix ) + : mrMatrix( rMatrix ) { + const_cast(mrMatrix).IncRef(); } - -// ---------------------------------------------------------------------------- - -void XclExpCachedDouble::Save( XclExpStream& rStrm ) const +XclExpCachedMatrix::~XclExpCachedMatrix() { - rStrm.SetSliceSize( 9 ); - rStrm << EXC_CACHEDVAL_DOUBLE << mfVal; + const_cast(mrMatrix).DecRef(); } -// ---------------------------------------------------------------------------- - -XclExpCachedString::XclExpCachedString( const String& rStr, XclStrFlags nFlags ) : - maStr( rStr, nFlags ) +void XclExpCachedMatrix::GetDimensions( SCSIZE & nCols, SCSIZE & nRows ) const { + mrMatrix.GetDimensions( nCols, nRows ); + + DBG_ASSERT( nCols && mnRows, "XclExpCachedMatrix::GetDimensions - empty matrix" ); + DBG_ASSERT( nCols <= 256, "XclExpCachedMatrix::GetDimensions - too many columns" ); } -void XclExpCachedString::Save( XclExpStream& rStrm ) const +sal_Size XclExpCachedMatrix::GetSize() const { - rStrm.SetSliceSize( 6 ); - rStrm << EXC_CACHEDVAL_STRING << maStr; -} + SCSIZE nCols, nRows; -// ---------------------------------------------------------------------------- + GetDimensions( nCols, nRows ); -XclExpCachedError::XclExpCachedError( USHORT nScError ) : - mnError( XclTools::GetXclErrorCode( nScError ) ) -{ + /* The returned size may be wrong if the matrix contains strings. The only + effect is that the export stream has to update a wrong record size which is + faster than to iterate through all cached values and calculate their sizes. */ + return 3 + 9 * (nCols * nRows); } -void XclExpCachedError::Save( XclExpStream& rStrm ) const +void XclExpCachedMatrix::Save( XclExpStream& rStrm ) const { - rStrm.SetSliceSize( 9 ); - rStrm << EXC_CACHEDVAL_ERROR << mnError; - rStrm.WriteZeroBytes( 7 ); -} + SCSIZE nCols, nRows; -// ---------------------------------------------------------------------------- + GetDimensions( nCols, nRows ); -XclExpCachedMatrix::XclExpCachedMatrix( const ScMatrix& rMatrix, XclStrFlags nFlags ) -{ - rMatrix.GetDimensions( mnScCols, mnScRows ); - DBG_ASSERT( mnScCols && mnScRows, "XclExpCachedMatrix::XclExpCachedMatrix - empty matrix" ); - DBG_ASSERT( mnScCols <= 256, "XclExpCachedMatrix::XclExpCachedMatrix - too many columns" ); + if( rStrm.GetRoot().GetBiff() <= EXC_BIFF5 ) + // in BIFF2-BIFF7: 256 columns represented by 0 columns + rStrm << static_cast< sal_uInt8 >( nCols ) << static_cast< sal_uInt16 >( nRows ); + else + // in BIFF8: columns and rows decreaed by 1 + rStrm << static_cast< sal_uInt8 >( nCols - 1 ) << static_cast< sal_uInt16 >( nRows - 1 ); - for( SCSIZE nScRow = 0; nScRow < mnScRows; ++nScRow ) + for( SCSIZE nRow = 0; nRow < nRows; ++nRow ) { - for( SCSIZE nScCol = 0; nScCol < mnScCols; ++nScCol ) + for( SCSIZE nCol = 0; nCol < nCols; ++nCol ) { - XclExpCachedValue* pNewVal = 0; ScMatValType nMatValType = SC_MATVAL_VALUE; - const ScMatrixValue* pMatVal = rMatrix.Get( nScCol, nScRow, nMatValType ); - if( !pMatVal ) - pNewVal = new XclExpCachedString( EMPTY_STRING, nFlags ); - else if( ScMatrix::IsStringType( nMatValType ) ) - pNewVal = new XclExpCachedString( pMatVal->GetString(), nFlags ); - else if( USHORT nScError = pMatVal->GetError() ) - pNewVal = new XclExpCachedError( nScError ); - else - pNewVal = new XclExpCachedDouble( pMatVal->fVal ); - maValueList.Append( pNewVal ); - } + const ScMatrixValue* pMatVal = mrMatrix.Get( nCol, nRow, nMatValType ); + + if( !pMatVal || SC_MATVAL_EMPTY == nMatValType ) + { + rStrm.SetSliceSize( 9 ); + rStrm << EXC_CACHEDVAL_EMPTY; + rStrm.WriteZeroBytes( 8 ); } + else if( ScMatrix::IsStringType( nMatValType ) ) + { + XclExpString aStr( pMatVal->GetString(), EXC_STR_DEFAULT ); + rStrm.SetSliceSize( 6 ); + rStrm << EXC_CACHEDVAL_STRING << aStr; } - -sal_Size XclExpCachedMatrix::GetSize() const + else if( SC_MATVAL_BOOLEAN == nMatValType ) { - /* The returned size may be wrong if the matrix contains strings. The only - effect is that the export stream has to update a wrong record size which is - faster than to iterate through all cached values and calculate their sizes. */ - return 3 + 9 * maValueList.Count(); + sal_Int8 nBool = pMatVal->GetBoolean(); + rStrm.SetSliceSize( 9 ); + rStrm << EXC_CACHEDVAL_BOOL << nBool; + rStrm.WriteZeroBytes( 7 ); } - -void XclExpCachedMatrix::Save( XclExpStream& rStrm ) const + else if( USHORT nScError = pMatVal->GetError() ) { - if( rStrm.GetRoot().GetBiff() <= EXC_BIFF5 ) - // in BIFF2-BIFF7: 256 columns represented by 0 columns - rStrm << static_cast< sal_uInt8 >( mnScCols ) << static_cast< sal_uInt16 >( mnScRows ); + sal_Int8 nError ( XclTools::GetXclErrorCode( nScError ) ); + rStrm.SetSliceSize( 9 ); + rStrm << EXC_CACHEDVAL_ERROR << nError; + rStrm.WriteZeroBytes( 7 ); + } else - // in BIFF8: columns and rows decreaed by 1 - rStrm << static_cast< sal_uInt8 >( mnScCols - 1 ) << static_cast< sal_uInt16 >( mnScRows - 1 ); - - for( const XclExpCachedValue* pValue = maValueList.First(); pValue; pValue = maValueList.Next() ) - pValue->Save( rStrm ); + { + rStrm.SetSliceSize( 9 ); + rStrm << EXC_CACHEDVAL_DOUBLE << pMatVal->fVal; + } + } + } } // ============================================================================ Index: source/filter/excel/xihelper.cxx =================================================================== RCS file: /cvs/sc/sc/source/filter/excel/xihelper.cxx,v retrieving revision 1.26 diff -u -w -p -r1.26 xihelper.cxx --- source/filter/excel/xihelper.cxx 27 Feb 2007 12:26:55 -0000 1.26 +++ source/filter/excel/xihelper.cxx 22 May 2007 15:29:13 -0000 @@ -861,9 +861,8 @@ XclImpCachedValue::XclImpCachedValue( Xc case EXC_CACHEDVAL_ERROR: { double fVal; - rStrm.Ignore( 1 ); rStrm >> mnBoolErr; - rStrm.Ignore( 6 ); + rStrm.Ignore( 7 ); const ScTokenArray* pScTokArr = rStrm.GetRoot().GetOldFmlaConverter().GetBoolErr( XclTools::ErrorToEnum( fVal, mnType == EXC_CACHEDVAL_ERROR, mnBoolErr ) ); @@ -941,7 +940,7 @@ ScMatrixRef XclImpCachedMatrix::CreateSc xScMatrix->PutString( pValue->GetString(), nScCol, nScRow ); break; case EXC_CACHEDVAL_BOOL: - xScMatrix->PutDouble( pValue->GetBool() ? 1.0 : 0.0, nScCol, nScRow ); + xScMatrix->PutBoolean( pValue->GetBool(), nScCol, nScRow ); break; case EXC_CACHEDVAL_ERROR: xScMatrix->PutError( pValue->GetError(), nScCol, nScRow ); Index: source/filter/inc/xehelper.hxx =================================================================== RCS file: /cvs/sc/sc/source/filter/inc/xehelper.hxx,v retrieving revision 1.18 diff -u -w -p -r1.18 xehelper.hxx --- source/filter/inc/xehelper.hxx 10 Jul 2006 13:55:09 -0000 1.18 +++ source/filter/inc/xehelper.hxx 22 May 2007 15:29:13 -0000 @@ -436,76 +436,19 @@ public: static String EncodeDde( const String& rApplic, const String rTopic ); }; -// Cached Value Lists ========================================================= - -/** The base class for cached values. - @descr Cached values are used to store a list or a 2D array of double, - string and Boolean values and error codes, for instannce in the records - CRN and EXTERNNAME or in the token tArray. */ -class XclExpCachedValue -{ -public: - virtual ~XclExpCachedValue(); - virtual void Save( XclExpStream& rStrm ) const = 0; -}; - -// ---------------------------------------------------------------------------- - -/** A cached value that stores a double. */ -class XclExpCachedDouble : public XclExpCachedValue -{ -public: - explicit inline XclExpCachedDouble( double fVal ) : mfVal( fVal ) {} - /** Writes the double value to stream. */ - virtual void Save( XclExpStream& rStrm ) const; - -private: - double mfVal; /// The double value. -}; - // ---------------------------------------------------------------------------- - -/** A cached value that stores a string. */ -class XclExpCachedString : public XclExpCachedValue -{ -public: - explicit XclExpCachedString( const String& rStr, XclStrFlags nFlags = EXC_STR_DEFAULT ); - /** Writes the string to stream. */ - virtual void Save( XclExpStream& rStrm ) const; - -private: - XclExpString maStr; -}; - -// ---------------------------------------------------------------------------- - -/** A cached value that stores an error code. */ -class XclExpCachedError : public XclExpCachedValue -{ -public: - explicit XclExpCachedError( USHORT nScError ); - /** Writes the error code to stream. */ - virtual void Save( XclExpStream& rStrm ) const; - -private: - sal_uInt8 mnError; -}; - -// ---------------------------------------------------------------------------- - class ScDocument; class ScMatrix; /** Contains cached values in a 2-dimensional array. */ class XclExpCachedMatrix { + void GetDimensions( SCSIZE & nCols, SCSIZE & nRows ) const; public: /** Constructs and fills a new matrix. - @param rMatrix The Calc value matrix. - @param nFlags Flags for writing strings. */ - explicit XclExpCachedMatrix( - const ScMatrix& rMatrix, - XclStrFlags nFlags = EXC_STR_DEFAULT ); + @param rMatrix The Calc value matrix. */ + explicit XclExpCachedMatrix( const ScMatrix& rMatrix ); + ~XclExpCachedMatrix(); /** Returns the byte count of all contained data. */ sal_Size GetSize() const; @@ -513,11 +456,7 @@ public: void Save( XclExpStream& rStrm ) const; private: - typedef ScfDelList< XclExpCachedValue > XclExpCachedValueList; - - XclExpCachedValueList maValueList; /// The list containing the cached values. - SCSIZE mnScCols; /// Calc column count of the value matrix. - SCSIZE mnScRows; /// Calc row count of the value matrix. + const ScMatrix& mrMatrix; }; // ============================================================================