include/oox/token/tokenmap.hxx | 9 include/sax/fastattribs.hxx | 42 +- include/sax/fshelper.hxx | 4 oox/source/core/xmlfilterbase.cxx | 7 oox/source/token/tokenmap.cxx | 7 package/Library_package2.mk | 1 package/inc/ZipOutputEntry.hxx | 79 +++++ package/inc/ZipOutputStream.hxx | 49 --- package/inc/ZipPackageFolder.hxx | 5 package/source/zipapi/ZipOutputEntry.cxx | 367 +++++++++++++++++++++++++ package/source/zipapi/ZipOutputStream.cxx | 351 ----------------------- package/source/zippackage/ZipPackage.cxx | 36 +- package/source/zippackage/ZipPackageFolder.cxx | 31 +- sax/source/fastparser/fastparser.cxx | 7 sax/source/tools/CachedOutputStream.hxx | 121 ++++++++ sax/source/tools/fastattribs.cxx | 41 -- sax/source/tools/fastserializer.cxx | 324 ++++++++++++---------- sax/source/tools/fastserializer.hxx | 95 +++--- sax/source/tools/fshelper.cxx | 55 +-- sc/Library_sc.mk | 1 sc/inc/column.hxx | 4 sc/inc/document.hxx | 2 sc/inc/documentimport.hxx | 19 + sc/inc/formulacell.hxx | 3 sc/inc/numformat.hxx | 46 +++ sc/inc/rowheightcontext.hxx | 6 sc/inc/table.hxx | 4 sc/source/core/data/column.cxx | 60 +++- sc/source/core/data/column2.cxx | 28 + sc/source/core/data/column3.cxx | 41 ++ sc/source/core/data/document.cxx | 8 sc/source/core/data/documentimport.cxx | 117 +++++++ sc/source/core/data/formulacell.cxx | 25 + sc/source/core/data/rowheightcontext.cxx | 5 sc/source/core/data/table1.cxx | 41 +- sc/source/core/data/table2.cxx | 24 + sc/source/core/opencl/op_statistical.cxx | 6 sc/source/core/opencl/opbase.cxx | 73 ++++ sc/source/core/opencl/opbase.hxx | 68 +--- sc/source/core/tool/address.cxx | 86 ++--- sc/source/core/tool/numformat.cxx | 82 +++++ sc/source/filter/excel/excdoc.cxx | 2 sc/source/filter/excel/xecontent.cxx | 12 sc/source/filter/excel/xeextlst.cxx | 2 sc/source/filter/excel/xestream.cxx | 14 sc/source/filter/excel/xetable.cxx | 2 sc/source/filter/excel/xistyle.cxx | 24 - sc/source/filter/excel/xlroot.cxx | 21 + sc/source/filter/inc/numberformatsbuffer.hxx | 4 sc/source/filter/inc/stylesbuffer.hxx | 19 + sc/source/filter/inc/xeroot.hxx | 3 sc/source/filter/inc/xestream.hxx | 3 sc/source/filter/inc/xlroot.hxx | 10 sc/source/filter/oox/numberformatsbuffer.cxx | 16 - sc/source/filter/oox/sheetdatabuffer.cxx | 28 + sc/source/filter/oox/stylesbuffer.cxx | 98 +++++- sc/source/filter/oox/worksheethelper.cxx | 13 sc/source/filter/xcl97/XclExpChangeTrack.cxx | 2 sc/source/filter/xml/xmlimprt.cxx | 29 - sc/source/ui/view/viewfun2.cxx | 2 sd/source/filter/eppt/pptx-epptooxml.cxx | 2 61 files changed, 1731 insertions(+), 955 deletions(-)
New commits: commit e04873f05ddacb35814d93055980b655ef107bd6 Author: Matúš Kukan <matus.ku...@collabora.com> Date: Thu Oct 9 15:22:54 2014 +0200 package: Add ZipOutputEntry to isolate deflating of streams. Preparation commit for deflating streams in parallel. We still use the same single XOutputStream (ByteChucker :-) for sequential writing but this can now be changed more easily. Change-Id: Idf26cc2187461660e31ac2e12c4708e761596fb2 diff --git a/package/Library_package2.mk b/package/Library_package2.mk index 269cf81..f563d0a 100644 --- a/package/Library_package2.mk +++ b/package/Library_package2.mk @@ -55,6 +55,7 @@ $(eval $(call gb_Library_add_exception_objects,package2,\ package/source/zipapi/XUnbufferedStream \ package/source/zipapi/ZipEnumeration \ package/source/zipapi/ZipFile \ + package/source/zipapi/ZipOutputEntry \ package/source/zipapi/ZipOutputStream \ package/source/zippackage/wrapstreamforshare \ package/source/zippackage/zipfileaccess \ diff --git a/package/inc/ZipOutputEntry.hxx b/package/inc/ZipOutputEntry.hxx new file mode 100644 index 0000000..a1d03d3 --- /dev/null +++ b/package/inc/ZipOutputEntry.hxx @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX +#define INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/xml/crypto/XCipherContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> + +#include <package/Deflater.hxx> +#include <ByteChucker.hxx> +#include <CRC32.hxx> + +struct ZipEntry; +class ZipPackageStream; + +class ZipOutputEntry +{ + ::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer; + ZipUtils::Deflater m_aDeflater; + + ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext; + + CRC32 m_aCRC; + ByteChucker &m_rChucker; + ZipEntry *m_pCurrentEntry; + sal_Int16 m_nDigested; + bool m_bEncryptCurrentEntry; + ZipPackageStream* m_pCurrentStream; + +public: + ZipOutputEntry( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, + ByteChucker& rChucker, ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt = false); + + ~ZipOutputEntry(); + + // rawWrite to support a direct write to the output stream + void SAL_CALL rawWrite( ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) + throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + void SAL_CALL rawCloseEntry( ) + throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + // XZipOutputEntry interfaces + void SAL_CALL closeEntry( ) + throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) + throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + static sal_uInt32 getCurrentDosTime ( ); + +private: + void doDeflate(); + sal_Int32 writeLOC( const ZipEntry &rEntry ) + throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + void writeEXT( const ZipEntry &rEntry ) + throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx index 146e642..95c27f3 100644 --- a/package/inc/ZipOutputStream.hxx +++ b/package/inc/ZipOutputStream.hxx @@ -21,75 +21,36 @@ #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/xml/crypto/XCipherContext.hpp> -#include <com/sun/star/xml/crypto/XDigestContext.hpp> -#include <package/Deflater.hxx> #include <ByteChucker.hxx> -#include <CRC32.hxx> #include <vector> struct ZipEntry; -class ZipPackageStream; class ZipOutputStream { -protected: - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> m_xContext; ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > m_xStream; - ::std::vector < ZipEntry * > m_aZipList; - ::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer; - - OUString m_sComment; - ZipUtils::Deflater m_aDeflater; - - ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; - ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext; - - CRC32 m_aCRC; ByteChucker m_aChucker; - ZipEntry *m_pCurrentEntry; - sal_Int16 m_nDigested; - bool m_bFinished, m_bEncryptCurrentEntry; - ZipPackageStream* m_pCurrentStream; + bool m_bFinished; public: ZipOutputStream( - const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > &xOStream ); ~ZipOutputStream(); - // rawWrite to support a direct write to the output stream - void SAL_CALL rawWrite( ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - void SAL_CALL rawCloseEntry( ) + void addEntry( ZipEntry *pZipEntry ); + void finish() throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + ByteChucker& getChucker(); - // XZipOutputStream interfaces - void SAL_CALL putNextEntry( ZipEntry& rEntry, - ZipPackageStream* pStream, - bool bEncrypt = false ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - void SAL_CALL closeEntry( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - void SAL_CALL finish( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - static sal_uInt32 getCurrentDosTime ( ); -protected: - void doDeflate(); +private: void writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); void writeCEN( const ZipEntry &rEntry ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - void writeEXT( const ZipEntry &rEntry ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - sal_Int32 writeLOC( const ZipEntry &rEntry ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); }; #endif diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx index 6053b48..dd0ff95 100644 --- a/package/inc/ZipPackageFolder.hxx +++ b/package/inc/ZipPackageFolder.hxx @@ -22,6 +22,7 @@ #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/beans/StringPair.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <HashMaps.hxx> #include <ZipPackageEntry.hxx> #include <cppuhelper/implbase2.hxx> @@ -50,13 +51,15 @@ class ZipPackageFolder : public cppu::ImplInheritanceHelper2 > { private: + css::uno::Reference< css::uno::XComponentContext> m_xContext; ContentHash maContents; sal_Int32 m_nFormat; OUString m_sVersion; public: - ZipPackageFolder( sal_Int32 nFormat, + ZipPackageFolder( css::uno::Reference< css::uno::XComponentContext> xContext, + sal_Int32 nFormat, bool bAllowRemoveOnInsert ); virtual ~ZipPackageFolder(); diff --git a/package/source/zipapi/ZipOutputEntry.cxx b/package/source/zipapi/ZipOutputEntry.cxx new file mode 100644 index 0000000..a3e3cc8 --- /dev/null +++ b/package/source/zipapi/ZipOutputEntry.cxx @@ -0,0 +1,367 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <ZipOutputEntry.hxx> + +#include <com/sun/star/packages/zip/ZipConstants.hpp> +#include <comphelper/storagehelper.hxx> + +#include <osl/time.h> + +#include <PackageConstants.hxx> +#include <ZipEntry.hxx> +#include <ZipFile.hxx> +#include <ZipPackageStream.hxx> + +using namespace com::sun::star; +using namespace com::sun::star::io; +using namespace com::sun::star::uno; +using namespace com::sun::star::packages::zip::ZipConstants; + +/** This class is used to deflate Zip entries + */ +ZipOutputEntry::ZipOutputEntry( const uno::Reference< uno::XComponentContext >& rxContext, + ByteChucker& rChucker, + ZipEntry& rEntry, + ZipPackageStream* pStream, + bool bEncrypt) +: m_aDeflateBuffer(n_ConstBufferSize) +, m_aDeflater(DEFAULT_COMPRESSION, true) +, m_rChucker(rChucker) +, m_pCurrentEntry(&rEntry) +, m_nDigested(0) +, m_bEncryptCurrentEntry(false) +, m_pCurrentStream(NULL) +{ + if (rEntry.nTime == -1) + rEntry.nTime = getCurrentDosTime(); + if (rEntry.nMethod == -1) + rEntry.nMethod = DEFLATED; + rEntry.nVersion = 20; + rEntry.nFlag = 1 << 11; + if (rEntry.nSize == -1 || rEntry.nCompressedSize == -1 || + rEntry.nCrc == -1) + { + rEntry.nSize = rEntry.nCompressedSize = 0; + rEntry.nFlag |= 8; + } + + if (bEncrypt) + { + m_bEncryptCurrentEntry = true; + + m_xCipherContext = ZipFile::StaticGetCipher( rxContext, pStream->GetEncryptionData(), true ); + m_xDigestContext = ZipFile::StaticGetDigestContextForChecksum( rxContext, pStream->GetEncryptionData() ); + m_nDigested = 0; + rEntry.nFlag |= 1 << 4; + m_pCurrentStream = pStream; + } + sal_Int32 nLOCLength = writeLOC(rEntry); + rEntry.nOffset = m_rChucker.GetPosition() - nLOCLength; +} + +ZipOutputEntry::~ZipOutputEntry( void ) +{ +} + +void SAL_CALL ZipOutputEntry::closeEntry( ) + throw(IOException, RuntimeException) +{ + ZipEntry *pEntry = m_pCurrentEntry; + if (pEntry) + { + switch (pEntry->nMethod) + { + case DEFLATED: + m_aDeflater.finish(); + while (!m_aDeflater.finished()) + doDeflate(); + if ((pEntry->nFlag & 8) == 0) + { + if (pEntry->nSize != m_aDeflater.getTotalIn()) + { + OSL_FAIL("Invalid entry size"); + } + if (pEntry->nCompressedSize != m_aDeflater.getTotalOut()) + { + // Different compression strategies make the merit of this + // test somewhat dubious + pEntry->nCompressedSize = m_aDeflater.getTotalOut(); + } + if (pEntry->nCrc != m_aCRC.getValue()) + { + OSL_FAIL("Invalid entry CRC-32"); + } + } + else + { + if ( !m_bEncryptCurrentEntry ) + { + pEntry->nSize = m_aDeflater.getTotalIn(); + pEntry->nCompressedSize = m_aDeflater.getTotalOut(); + } + pEntry->nCrc = m_aCRC.getValue(); + writeEXT(*pEntry); + } + m_aDeflater.reset(); + m_aCRC.reset(); + break; + case STORED: + if (!((pEntry->nFlag & 8) == 0)) + OSL_FAIL( "Serious error, one of compressed size, size or CRC was -1 in a STORED stream"); + break; + default: + OSL_FAIL("Invalid compression method"); + break; + } + + if (m_bEncryptCurrentEntry) + { + m_bEncryptCurrentEntry = false; + + m_xCipherContext.clear(); + + uno::Sequence< sal_Int8 > aDigestSeq; + if ( m_xDigestContext.is() ) + { + aDigestSeq = m_xDigestContext->finalizeDigestAndDispose(); + m_xDigestContext.clear(); + } + + if ( m_pCurrentStream ) + m_pCurrentStream->setDigest( aDigestSeq ); + } + m_pCurrentEntry = NULL; + m_pCurrentStream = NULL; + } +} + +void SAL_CALL ZipOutputEntry::write( const Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) + throw(IOException, RuntimeException) +{ + switch (m_pCurrentEntry->nMethod) + { + case DEFLATED: + if (!m_aDeflater.finished()) + { + m_aDeflater.setInputSegment(rBuffer, nNewOffset, nNewLength); + while (!m_aDeflater.needsInput()) + doDeflate(); + if (!m_bEncryptCurrentEntry) + m_aCRC.updateSegment(rBuffer, nNewOffset, nNewLength); + } + break; + case STORED: + { + Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength ); + m_rChucker.WriteBytes( aTmpBuffer ); + } + break; + } +} + +void SAL_CALL ZipOutputEntry::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int32 /*nNewOffset*/, sal_Int32 nNewLength ) + throw(IOException, RuntimeException) +{ + Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength ); + m_rChucker.WriteBytes( aTmpBuffer ); +} + +void SAL_CALL ZipOutputEntry::rawCloseEntry( ) + throw(IOException, RuntimeException) +{ + if ( m_pCurrentEntry->nMethod == DEFLATED && ( m_pCurrentEntry->nFlag & 8 ) ) + writeEXT(*m_pCurrentEntry); + m_pCurrentEntry = NULL; +} + +void ZipOutputEntry::doDeflate() +{ + sal_Int32 nLength = m_aDeflater.doDeflateSegment(m_aDeflateBuffer, 0, m_aDeflateBuffer.getLength()); + + if ( nLength > 0 ) + { + uno::Sequence< sal_Int8 > aTmpBuffer( m_aDeflateBuffer.getConstArray(), nLength ); + if ( m_bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() ) + { + // Need to update our digest before encryption... + sal_Int32 nDiff = n_ConstDigestLength - m_nDigested; + if ( nDiff ) + { + sal_Int32 nEat = ::std::min( nLength, nDiff ); + uno::Sequence< sal_Int8 > aTmpSeq( aTmpBuffer.getConstArray(), nEat ); + m_xDigestContext->updateDigest( aTmpSeq ); + m_nDigested = m_nDigested + static_cast< sal_Int16 >( nEat ); + } + + // FIXME64: uno::Sequence not 64bit safe. + uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->convertWithCipherContext( aTmpBuffer ); + + m_rChucker.WriteBytes( aEncryptionBuffer ); + + // the sizes as well as checksum for encrypted streams is calculated here + m_pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); + m_pCurrentEntry->nSize = m_pCurrentEntry->nCompressedSize; + m_aCRC.update( aEncryptionBuffer ); + } + else + { + m_rChucker.WriteBytes ( aTmpBuffer ); + } + } + + if ( m_aDeflater.finished() && m_bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() ) + { + // FIXME64: sequence not 64bit safe. + uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose(); + if ( aEncryptionBuffer.getLength() ) + { + m_rChucker.WriteBytes( aEncryptionBuffer ); + + // the sizes as well as checksum for encrypted streams is calculated hier + m_pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); + m_pCurrentEntry->nSize = m_pCurrentEntry->nCompressedSize; + m_aCRC.update( aEncryptionBuffer ); + } + } +} + +static sal_uInt32 getTruncated( sal_Int64 nNum, bool *pIsTruncated ) +{ + if( nNum >= 0xffffffff ) + { + *pIsTruncated = true; + return 0xffffffff; + } + else + return static_cast< sal_uInt32 >( nNum ); +} + +void ZipOutputEntry::writeEXT( const ZipEntry &rEntry ) + throw(IOException, RuntimeException) +{ + bool bWrite64Header = false; + + m_rChucker << EXTSIG; + m_rChucker << static_cast < sal_uInt32> ( rEntry.nCrc ); + m_rChucker << getTruncated( rEntry.nCompressedSize, &bWrite64Header ); + m_rChucker << getTruncated( rEntry.nSize, &bWrite64Header ); + + if( bWrite64Header ) + { + // FIXME64: need to append a ZIP64 header instead of throwing + // We're about to silently lose people's data - which they are + // unlikely to appreciate so fail instead: + throw IOException( "File contains streams that are too large." ); + } +} + +sal_Int32 ZipOutputEntry::writeLOC( const ZipEntry &rEntry ) + throw(IOException, RuntimeException) +{ + if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, true ) ) + throw IOException("Unexpected character is used in file name." ); + + OString sUTF8Name = OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 ); + sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); + + m_rChucker << LOCSIG; + m_rChucker << rEntry.nVersion; + + if (rEntry.nFlag & (1 << 4) ) + { + // If it's an encrypted entry, we pretend its stored plain text + sal_Int16 nTmpFlag = rEntry.nFlag; + nTmpFlag &= ~(1 <<4 ); + m_rChucker << nTmpFlag; + m_rChucker << static_cast < sal_Int16 > ( STORED ); + } + else + { + m_rChucker << rEntry.nFlag; + m_rChucker << rEntry.nMethod; + } + + bool bWrite64Header = false; + + m_rChucker << static_cast < sal_uInt32 > (rEntry.nTime); + if ((rEntry.nFlag & 8) == 8 ) + { + m_rChucker << static_cast < sal_Int32 > (0); + m_rChucker << static_cast < sal_Int32 > (0); + m_rChucker << static_cast < sal_Int32 > (0); + } + else + { + m_rChucker << static_cast < sal_uInt32 > (rEntry.nCrc); + m_rChucker << getTruncated( rEntry.nCompressedSize, &bWrite64Header ); + m_rChucker << getTruncated( rEntry.nSize, &bWrite64Header ); + } + m_rChucker << nNameLength; + m_rChucker << static_cast < sal_Int16 > (0); + + if( bWrite64Header ) + { + // FIXME64: need to append a ZIP64 header instead of throwing + // We're about to silently lose people's data - which they are + // unlikely to appreciate so fail instead: + throw IOException( "File contains streams that are too large." ); + } + + Sequence < sal_Int8 > aSequence( (sal_Int8*)sUTF8Name.getStr(), sUTF8Name.getLength() ); + m_rChucker.WriteBytes( aSequence ); + + return LOCHDR + nNameLength; +} +sal_uInt32 ZipOutputEntry::getCurrentDosTime( ) +{ + oslDateTime aDateTime; + TimeValue aTimeValue; + osl_getSystemTime ( &aTimeValue ); + osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime); + + // at year 2108, there is an overflow + // -> some decision needs to be made + // how to handle the ZIP file format (just overflow?) + + // if the current system time is before 1980, + // then the time traveller will have to make a decision + // how to handle the ZIP file format before it is invented + // (just underflow?) + + assert(aDateTime.Year > 1980 && aDateTime.Year < 2108); + + sal_uInt32 nYear = static_cast <sal_uInt32> (aDateTime.Year); + + if (nYear>=1980) + nYear-=1980; + else if (nYear>=80) + { + nYear-=80; + } + sal_uInt32 nResult = static_cast < sal_uInt32>( ( ( ( aDateTime.Day) + + ( 32 * (aDateTime.Month)) + + ( 512 * nYear ) ) << 16) | + ( ( aDateTime.Seconds/2) + + ( 32 * aDateTime.Minutes) + + ( 2048 * static_cast <sal_uInt32 > (aDateTime.Hours) ) ) ); + return nResult; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx index 34f0979..7cd5acd 100644 --- a/package/source/zipapi/ZipOutputStream.cxx +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -17,18 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <ZipOutputStream.hxx> + #include <com/sun/star/packages/zip/ZipConstants.hpp> #include <com/sun/star/io/XOutputStream.hpp> #include <comphelper/storagehelper.hxx> -#include <osl/time.h> - -#include <EncryptionData.hxx> #include <PackageConstants.hxx> #include <ZipEntry.hxx> -#include <ZipFile.hxx> -#include <ZipPackageStream.hxx> -#include <ZipOutputStream.hxx> using namespace com::sun::star; using namespace com::sun::star::io; @@ -37,18 +33,10 @@ using namespace com::sun::star::packages::zip::ZipConstants; /** This class is used to write Zip files */ -ZipOutputStream::ZipOutputStream( const uno::Reference< uno::XComponentContext >& rxContext, - const uno::Reference < XOutputStream > &xOStream ) -: m_xContext( rxContext ) -, m_xStream(xOStream) -, m_aDeflateBuffer(n_ConstBufferSize) -, m_aDeflater(DEFAULT_COMPRESSION, true) +ZipOutputStream::ZipOutputStream( const uno::Reference < io::XOutputStream > &xOStream ) +: m_xStream(xOStream) , m_aChucker(xOStream) -, m_pCurrentEntry(NULL) -, m_nDigested(0) , m_bFinished(false) -, m_bEncryptCurrentEntry(false) -, m_pCurrentStream(NULL) { } @@ -58,162 +46,17 @@ ZipOutputStream::~ZipOutputStream( void ) delete m_aZipList[i]; } -void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry, - ZipPackageStream* pStream, - bool bEncrypt) - throw(IOException, RuntimeException) -{ - if (m_pCurrentEntry != NULL) - closeEntry(); - if (rEntry.nTime == -1) - rEntry.nTime = getCurrentDosTime(); - if (rEntry.nMethod == -1) - rEntry.nMethod = DEFLATED; - rEntry.nVersion = 20; - rEntry.nFlag = 1 << 11; - if (rEntry.nSize == -1 || rEntry.nCompressedSize == -1 || - rEntry.nCrc == -1) - { - rEntry.nSize = rEntry.nCompressedSize = 0; - rEntry.nFlag |= 8; - } - - if (bEncrypt) - { - m_bEncryptCurrentEntry = true; - - m_xCipherContext = ZipFile::StaticGetCipher( m_xContext, pStream->GetEncryptionData(), true ); - m_xDigestContext = ZipFile::StaticGetDigestContextForChecksum( m_xContext, pStream->GetEncryptionData() ); - m_nDigested = 0; - rEntry.nFlag |= 1 << 4; - m_pCurrentStream = pStream; - } - sal_Int32 nLOCLength = writeLOC(rEntry); - rEntry.nOffset = m_aChucker.GetPosition() - nLOCLength; - m_aZipList.push_back( &rEntry ); - m_pCurrentEntry = &rEntry; -} - -void SAL_CALL ZipOutputStream::closeEntry( ) - throw(IOException, RuntimeException) -{ - ZipEntry *pEntry = m_pCurrentEntry; - if (pEntry) - { - switch (pEntry->nMethod) - { - case DEFLATED: - m_aDeflater.finish(); - while (!m_aDeflater.finished()) - doDeflate(); - if ((pEntry->nFlag & 8) == 0) - { - if (pEntry->nSize != m_aDeflater.getTotalIn()) - { - OSL_FAIL("Invalid entry size"); - } - if (pEntry->nCompressedSize != m_aDeflater.getTotalOut()) - { - // Different compression strategies make the merit of this - // test somewhat dubious - pEntry->nCompressedSize = m_aDeflater.getTotalOut(); - } - if (pEntry->nCrc != m_aCRC.getValue()) - { - OSL_FAIL("Invalid entry CRC-32"); - } - } - else - { - if ( !m_bEncryptCurrentEntry ) - { - pEntry->nSize = m_aDeflater.getTotalIn(); - pEntry->nCompressedSize = m_aDeflater.getTotalOut(); - } - pEntry->nCrc = m_aCRC.getValue(); - writeEXT(*pEntry); - } - m_aDeflater.reset(); - m_aCRC.reset(); - break; - case STORED: - if (!((pEntry->nFlag & 8) == 0)) - OSL_FAIL( "Serious error, one of compressed size, size or CRC was -1 in a STORED stream"); - break; - default: - OSL_FAIL("Invalid compression method"); - break; - } - - if (m_bEncryptCurrentEntry) - { - m_bEncryptCurrentEntry = false; - - m_xCipherContext.clear(); - - uno::Sequence< sal_Int8 > aDigestSeq; - if ( m_xDigestContext.is() ) - { - aDigestSeq = m_xDigestContext->finalizeDigestAndDispose(); - m_xDigestContext.clear(); - } - - if ( m_pCurrentStream ) - m_pCurrentStream->setDigest( aDigestSeq ); - } - m_pCurrentEntry = NULL; - m_pCurrentStream = NULL; - } -} - -void SAL_CALL ZipOutputStream::write( const Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) - throw(IOException, RuntimeException) -{ - switch (m_pCurrentEntry->nMethod) - { - case DEFLATED: - if (!m_aDeflater.finished()) - { - m_aDeflater.setInputSegment(rBuffer, nNewOffset, nNewLength); - while (!m_aDeflater.needsInput()) - doDeflate(); - if (!m_bEncryptCurrentEntry) - m_aCRC.updateSegment(rBuffer, nNewOffset, nNewLength); - } - break; - case STORED: - { - Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength ); - m_aChucker.WriteBytes( aTmpBuffer ); - } - break; - } -} - -void SAL_CALL ZipOutputStream::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int32 /*nNewOffset*/, sal_Int32 nNewLength ) - throw(IOException, RuntimeException) +void ZipOutputStream::addEntry( ZipEntry *pZipEntry ) { - Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength ); - m_aChucker.WriteBytes( aTmpBuffer ); + m_aZipList.push_back( pZipEntry ); } -void SAL_CALL ZipOutputStream::rawCloseEntry( ) - throw(IOException, RuntimeException) -{ - if ( m_pCurrentEntry->nMethod == DEFLATED && ( m_pCurrentEntry->nFlag & 8 ) ) - writeEXT(*m_pCurrentEntry); - m_pCurrentEntry = NULL; -} - -void SAL_CALL ZipOutputStream::finish( ) +void ZipOutputStream::finish( ) throw(IOException, RuntimeException) { if (m_bFinished) return; - if (m_pCurrentEntry != NULL) - closeEntry(); - if (m_aZipList.size() < 1) OSL_FAIL("Zip file must have at least one entry!\n"); @@ -225,55 +68,9 @@ void SAL_CALL ZipOutputStream::finish( ) m_xStream->flush(); } -void ZipOutputStream::doDeflate() +ByteChucker& ZipOutputStream::getChucker() { - sal_Int32 nLength = m_aDeflater.doDeflateSegment(m_aDeflateBuffer, 0, m_aDeflateBuffer.getLength()); - - if ( nLength > 0 ) - { - uno::Sequence< sal_Int8 > aTmpBuffer( m_aDeflateBuffer.getConstArray(), nLength ); - if ( m_bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() ) - { - // Need to update our digest before encryption... - sal_Int32 nDiff = n_ConstDigestLength - m_nDigested; - if ( nDiff ) - { - sal_Int32 nEat = ::std::min( nLength, nDiff ); - uno::Sequence< sal_Int8 > aTmpSeq( aTmpBuffer.getConstArray(), nEat ); - m_xDigestContext->updateDigest( aTmpSeq ); - m_nDigested = m_nDigested + static_cast< sal_Int16 >( nEat ); - } - - // FIXME64: uno::Sequence not 64bit safe. - uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->convertWithCipherContext( aTmpBuffer ); - - m_aChucker.WriteBytes( aEncryptionBuffer ); - - // the sizes as well as checksum for encrypted streams is calculated here - m_pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); - m_pCurrentEntry->nSize = m_pCurrentEntry->nCompressedSize; - m_aCRC.update( aEncryptionBuffer ); - } - else - { - m_aChucker.WriteBytes ( aTmpBuffer ); - } - } - - if ( m_aDeflater.finished() && m_bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() ) - { - // FIXME64: sequence not 64bit safe. - uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose(); - if ( aEncryptionBuffer.getLength() ) - { - m_aChucker.WriteBytes( aEncryptionBuffer ); - - // the sizes as well as checksum for encrypted streams is calculated hier - m_pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); - m_pCurrentEntry->nSize = m_pCurrentEntry->nCompressedSize; - m_aCRC.update( aEncryptionBuffer ); - } - } + return m_aChucker; } void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) @@ -350,135 +147,5 @@ void ZipOutputStream::writeCEN( const ZipEntry &rEntry ) Sequence < sal_Int8 > aSequence( (sal_Int8*)sUTF8Name.getStr(), sUTF8Name.getLength() ); m_aChucker.WriteBytes( aSequence ); } -void ZipOutputStream::writeEXT( const ZipEntry &rEntry ) - throw(IOException, RuntimeException) -{ - bool bWrite64Header = false; - - m_aChucker << EXTSIG; - m_aChucker << static_cast < sal_uInt32> ( rEntry.nCrc ); - m_aChucker << getTruncated( rEntry.nCompressedSize, &bWrite64Header ); - m_aChucker << getTruncated( rEntry.nSize, &bWrite64Header ); - - if( bWrite64Header ) - { - // FIXME64: need to append a ZIP64 header instead of throwing - // We're about to silently lose people's data - which they are - // unlikely to appreciate so fail instead: - throw IOException( "File contains streams that are too large." ); - } -} - -sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry ) - throw(IOException, RuntimeException) -{ - if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, true ) ) - throw IOException("Unexpected character is used in file name." ); - - OString sUTF8Name = OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 ); - sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); - - m_aChucker << LOCSIG; - m_aChucker << rEntry.nVersion; - - if (rEntry.nFlag & (1 << 4) ) - { - // If it's an encrypted entry, we pretend its stored plain text - sal_Int16 nTmpFlag = rEntry.nFlag; - nTmpFlag &= ~(1 <<4 ); - m_aChucker << nTmpFlag; - m_aChucker << static_cast < sal_Int16 > ( STORED ); - } - else - { - m_aChucker << rEntry.nFlag; - m_aChucker << rEntry.nMethod; - } - - bool bWrite64Header = false; - - m_aChucker << static_cast < sal_uInt32 > (rEntry.nTime); - if ((rEntry.nFlag & 8) == 8 ) - { - m_aChucker << static_cast < sal_Int32 > (0); - m_aChucker << static_cast < sal_Int32 > (0); - m_aChucker << static_cast < sal_Int32 > (0); - } - else - { - m_aChucker << static_cast < sal_uInt32 > (rEntry.nCrc); - m_aChucker << getTruncated( rEntry.nCompressedSize, &bWrite64Header ); - m_aChucker << getTruncated( rEntry.nSize, &bWrite64Header ); - } - m_aChucker << nNameLength; - m_aChucker << static_cast < sal_Int16 > (0); - - if( bWrite64Header ) - { - // FIXME64: need to append a ZIP64 header instead of throwing - // We're about to silently lose people's data - which they are - // unlikely to appreciate so fail instead: - throw IOException( "File contains streams that are too large." ); - } - - Sequence < sal_Int8 > aSequence( (sal_Int8*)sUTF8Name.getStr(), sUTF8Name.getLength() ); - m_aChucker.WriteBytes( aSequence ); - - return LOCHDR + nNameLength; -} -sal_uInt32 ZipOutputStream::getCurrentDosTime( ) -{ - oslDateTime aDateTime; - TimeValue aTimeValue; - osl_getSystemTime ( &aTimeValue ); - osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime); - - // at year 2108, there is an overflow - // -> some decision needs to be made - // how to handle the ZIP file format (just overflow?) - - // if the current system time is before 1980, - // then the time traveller will have to make a decision - // how to handle the ZIP file format before it is invented - // (just underflow?) - - assert(aDateTime.Year > 1980 && aDateTime.Year < 2108); - - sal_uInt32 nYear = static_cast <sal_uInt32> (aDateTime.Year); - - if (nYear>=1980) - nYear-=1980; - else if (nYear>=80) - { - nYear-=80; - } - sal_uInt32 nResult = static_cast < sal_uInt32>( ( ( ( aDateTime.Day) + - ( 32 * (aDateTime.Month)) + - ( 512 * nYear ) ) << 16) | - ( ( aDateTime.Seconds/2) + - ( 32 * aDateTime.Minutes) + - ( 2048 * static_cast <sal_uInt32 > (aDateTime.Hours) ) ) ); - return nResult; -} -/* - - This is actually never used, so I removed it, but thought that the - implementation details may be useful in the future...mtg 20010307 - - I stopped using the time library and used the OSL version instead, but - it might still be useful to have this code here.. - -void ZipOutputStream::dosDateToTMDate ( tm &rTime, sal_uInt32 nDosDate) -{ - sal_uInt32 nDate = static_cast < sal_uInt32 > (nDosDate >> 16); - rTime.tm_mday = static_cast < sal_uInt32 > ( nDate & 0x1F); - rTime.tm_mon = static_cast < sal_uInt32 > ( ( ( (nDate) & 0x1E0)/0x20)-1); - rTime.tm_year = static_cast < sal_uInt32 > ( ( (nDate & 0x0FE00)/0x0200)+1980); - - rTime.tm_hour = static_cast < sal_uInt32 > ( (nDosDate & 0xF800)/0x800); - rTime.tm_min = static_cast < sal_uInt32 > ( (nDosDate & 0x7E0)/0x20); - rTime.tm_sec = static_cast < sal_uInt32 > ( 2 * (nDosDate & 0x1F) ); -} -*/ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 3bc0627..0a26c5a 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -22,6 +22,7 @@ #include <ZipEnumeration.hxx> #include <ZipPackageStream.hxx> #include <ZipPackageFolder.hxx> +#include <ZipOutputEntry.hxx> #include <ZipOutputStream.hxx> #include <ZipPackageBuffer.hxx> #include <ZipFile.hxx> @@ -156,7 +157,7 @@ ZipPackage::ZipPackage ( const uno::Reference < XComponentContext > &xContext ) , m_pRootFolder( NULL ) , m_pZipFile( NULL ) { - m_xRootFolder = m_pRootFolder = new ZipPackageFolder( m_nFormat, m_bAllowRemoveOnInsert ); + m_xRootFolder = m_pRootFolder = new ZipPackageFolder( m_xContext, m_nFormat, m_bAllowRemoveOnInsert ); } ZipPackage::~ZipPackage( void ) @@ -539,7 +540,7 @@ void ZipPackage::getZipFileContents() break; if ( !pCurrent->hasByName( sTemp ) ) { - pPkgFolder = new ZipPackageFolder( m_nFormat, m_bAllowRemoveOnInsert ); + pPkgFolder = new ZipPackageFolder( m_xContext, m_nFormat, m_bAllowRemoveOnInsert ); pPkgFolder->setName( sTemp ); pPkgFolder->doSetParent( pCurrent, true ); pCurrent = pPkgFolder; @@ -953,7 +954,7 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c if ( aArguments.getLength() ) aArguments[0] >>= bArg; if ( bArg ) - xRef = *new ZipPackageFolder ( m_nFormat, m_bAllowRemoveOnInsert ); + xRef = *new ZipPackageFolder ( m_xContext, m_nFormat, m_bAllowRemoveOnInsert ); else xRef = *new ZipPackageStream ( *this, m_xContext, m_bAllowRemoveOnInsert ); @@ -975,7 +976,7 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) pEntry->sPath = sMime; pEntry->nMethod = STORED; pEntry->nSize = pEntry->nCompressedSize = nBufferLength; - pEntry->nTime = ZipOutputStream::getCurrentDosTime(); + pEntry->nTime = ZipOutputEntry::getCurrentDosTime(); CRC32 aCRC32; aCRC32.update( aType ); @@ -983,9 +984,10 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) try { - aZipOut.putNextEntry( *pEntry, NULL ); - aZipOut.write( aType, 0, nBufferLength ); - aZipOut.closeEntry(); + ZipOutputEntry aZipEntry(m_xContext, aZipOut.getChucker(), *pEntry, NULL); + aZipEntry.write(aType, 0, nBufferLength); + aZipEntry.closeEntry(); + aZipOut.addEntry(pEntry); } catch ( const ::com::sun::star::io::IOException & r ) { @@ -1008,7 +1010,7 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq pEntry->nMethod = DEFLATED; pEntry->nCrc = -1; pEntry->nSize = pEntry->nCompressedSize = -1; - pEntry->nTime = ZipOutputStream::getCurrentDosTime(); + pEntry->nTime = ZipOutputEntry::getCurrentDosTime(); // Convert vector into a uno::Sequence uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence ( aManList.size() ); @@ -1025,9 +1027,10 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq pBuffer->realloc( nBufferLength ); // the manifest.xml is never encrypted - so pass an empty reference - aZipOut.putNextEntry( *pEntry, NULL ); - aZipOut.write( pBuffer->getSequence(), 0, nBufferLength ); - aZipOut.closeEntry(); + ZipOutputEntry aZipEntry(m_xContext, aZipOut.getChucker(), *pEntry, NULL); + aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength); + aZipEntry.closeEntry(); + aZipOut.addEntry(pEntry); } void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList ) @@ -1040,7 +1043,7 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno: pEntry->nMethod = DEFLATED; pEntry->nCrc = -1; pEntry->nSize = pEntry->nCompressedSize = -1; - pEntry->nTime = ZipOutputStream::getCurrentDosTime(); + pEntry->nTime = ZipOutputEntry::getCurrentDosTime(); // Convert vector into a uno::Sequence // TODO/LATER: use Defaulst entries in future @@ -1075,9 +1078,10 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno: pBuffer->realloc( nBufferLength ); // there is no encryption in this format currently - aZipOut.putNextEntry( *pEntry, NULL ); - aZipOut.write( pBuffer->getSequence(), 0, nBufferLength ); - aZipOut.closeEntry(); + ZipOutputEntry aZipEntry(m_xContext, aZipOut.getChucker(), *pEntry, NULL); + aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength); + aZipEntry.closeEntry(); + aZipOut.addEntry(pEntry); } void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream ) @@ -1138,7 +1142,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() } // Hand it to the ZipOutputStream: - ZipOutputStream aZipOut( m_xContext, xTempOut ); + ZipOutputStream aZipOut( xTempOut ); try { if ( m_nFormat == embed::StorageFormats::PACKAGE ) diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index c0baf90..c6a3b37 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -21,6 +21,7 @@ #include <ZipPackageFolder.hxx> #include <ZipFile.hxx> +#include <ZipOutputEntry.hxx> #include <ZipOutputStream.hxx> #include <ZipPackageStream.hxx> #include <PackageConstants.hxx> @@ -60,9 +61,11 @@ using namespace ::com::sun::star; namespace { struct lcl_CachedImplId : public rtl::Static< cppu::OImplementationId, lcl_CachedImplId > {}; } -ZipPackageFolder::ZipPackageFolder ( sal_Int32 nFormat, +ZipPackageFolder::ZipPackageFolder ( css::uno::Reference< css::uno::XComponentContext> xContext, + sal_Int32 nFormat, bool bAllowRemoveOnInsert ) -: m_nFormat( nFormat ) + : m_xContext( xContext ) + , m_nFormat( nFormat ) { this->mbAllowRemoveOnInsert = bAllowRemoveOnInsert; @@ -338,6 +341,7 @@ static bool ZipPackageFolder_saveChild( } static bool ZipPackageStream_saveChild( + css::uno::Reference< css::uno::XComponentContext> xContext, const ContentInfo &rInfo, const OUString &rPath, std::vector < uno::Sequence < PropertyValue > > &rManList, @@ -563,7 +567,7 @@ static bool ZipPackageStream_saveChild( if ( bRawStream ) xStream->skipBytes( rInfo.pStream->GetMagicalHackPos() ); - rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, false ); + ZipOutputEntry aZipEntry(xContext, rZipOut.getChucker(), *pTempEntry, rInfo.pStream, false); // the entry is provided to the ZipOutputStream that will delete it pAutoTempEntry.release(); @@ -573,11 +577,12 @@ static bool ZipPackageStream_saveChild( do { nLength = xStream->readBytes( aSeq, n_ConstBufferSize ); - rZipOut.rawWrite(aSeq, 0, nLength); + aZipEntry.rawWrite(aSeq, 0, nLength); } while ( nLength == n_ConstBufferSize ); - rZipOut.rawCloseEntry(); + aZipEntry.rawCloseEntry(); + rZipOut.addEntry(pTempEntry); } catch ( ZipException& ) { @@ -620,7 +625,7 @@ static bool ZipPackageStream_saveChild( try { - rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, bToBeEncrypted); + ZipOutputEntry aZipEntry(xContext, rZipOut.getChucker(), *pTempEntry, rInfo.pStream, bToBeEncrypted); // the entry is provided to the ZipOutputStream that will delete it pAutoTempEntry.release(); @@ -629,11 +634,12 @@ static bool ZipPackageStream_saveChild( do { nLength = xStream->readBytes(aSeq, n_ConstBufferSize); - rZipOut.write(aSeq, 0, nLength); + aZipEntry.write(aSeq, 0, nLength); } while ( nLength == n_ConstBufferSize ); - rZipOut.closeEntry(); + aZipEntry.closeEntry(); + rZipOut.addEntry(pTempEntry); } catch ( ZipException& ) { @@ -726,8 +732,9 @@ void ZipPackageFolder::saveContents( try { - rZipOut.putNextEntry( *pTempEntry, NULL, false ); - rZipOut.rawCloseEntry(); + ZipOutputEntry aZipEntry(m_xContext, rZipOut.getChucker(), *pTempEntry, NULL, false); + aZipEntry.rawCloseEntry(); + rZipOut.addEntry(pTempEntry); } catch ( ZipException& ) { @@ -748,7 +755,7 @@ void ZipPackageFolder::saveContents( if ( aIter != maContents.end() && !(*aIter).second->bFolder ) { bMimeTypeStreamStored = true; - bWritingFailed = !ZipPackageStream_saveChild( + bWritingFailed = !ZipPackageStream_saveChild( m_xContext, *aIter->second, rPath + aIter->first, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat ); } } @@ -769,7 +776,7 @@ void ZipPackageFolder::saveContents( } else { - bWritingFailed = !ZipPackageStream_saveChild( + bWritingFailed = !ZipPackageStream_saveChild( m_xContext, rInfo, rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat ); } } commit d5626897936e7b8c085542af7ac4671456533e47 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Fri Oct 3 16:43:25 2014 -0400 Inlining make no sense for virtual functions. Change-Id: I6392eaceb0544b7faa9a0c726acf6619d971dbb7 diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx index f19e36e..14ae124 100644 --- a/sc/source/core/opencl/opbase.cxx +++ b/sc/source/core/opencl/opbase.cxx @@ -88,17 +88,62 @@ DynamicKernelArgument::DynamicKernelArgument( const std::string& s, FormulaTreeNodeRef ft ) : mSymName(s), mFormulaTree(ft) { } +std::string DynamicKernelArgument::GenDoubleSlidingWindowDeclRef( bool ) const +{ + return std::string(""); +} + +/// When Mix, it will be called +std::string DynamicKernelArgument::GenStringSlidingWindowDeclRef( bool ) const +{ + return std::string(""); +} + +bool DynamicKernelArgument::IsMixedArgument() const +{ + return false; +} + /// Generate use/references to the argument void DynamicKernelArgument::GenDeclRef( std::stringstream& ss ) const { ss << mSymName; } +void DynamicKernelArgument::GenNumDeclRef( std::stringstream& ss ) const +{ + ss << ","; +} + +void DynamicKernelArgument::GenStringDeclRef( std::stringstream& ss ) const +{ + ss << ","; +} + +void DynamicKernelArgument::GenSlidingWindowFunction( std::stringstream& ) {} + FormulaToken* DynamicKernelArgument::GetFormulaToken() const { return mFormulaTree->GetFormulaToken(); } +std::string DynamicKernelArgument::DumpOpName() const +{ + return std::string(""); +} + +void DynamicKernelArgument::DumpInlineFun( std::set<std::string>&, std::set<std::string>& ) const {} + +const std::string& DynamicKernelArgument::GetName() const +{ + return mSymName; +} + +bool DynamicKernelArgument::NeedParallelReduction() const +{ + return false; +} + VectorRef::VectorRef( const std::string& s, FormulaTreeNodeRef ft, int idx ) : DynamicKernelArgument(s, ft), mpClmem(NULL), mnIndex(idx) { @@ -144,6 +189,8 @@ std::string VectorRef::GenSlidingWindowDeclRef( bool nested ) const return ss.str(); } +void VectorRef::GenSlidingWindowFunction( std::stringstream& ) {} + size_t VectorRef::GetWindowSize() const { FormulaToken* pCur = mFormulaTree->GetFormulaToken(); @@ -164,6 +211,28 @@ size_t VectorRef::GetWindowSize() const } } +std::string VectorRef::DumpOpName() const +{ + return std::string(""); +} + +void VectorRef::DumpInlineFun( std::set<std::string>&, std::set<std::string>& ) const {} + +const std::string& VectorRef::GetName() const +{ + return mSymName; +} + +cl_mem VectorRef::GetCLBuffer() const +{ + return mpClmem; +} + +bool VectorRef::NeedParallelReduction() const +{ + return false; +} + void Normal::GenSlidingWindowFunction( std::stringstream& ss, const std::string& sSymName, SubArguments& vSubArguments ) { diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx index 15dedc5..d806140 100644 --- a/sc/source/core/opencl/opbase.hxx +++ b/sc/source/core/opencl/opbase.hxx @@ -87,6 +87,7 @@ class DynamicKernelArgument : boost::noncopyable { public: DynamicKernelArgument( const std::string& s, FormulaTreeNodeRef ft ); + virtual ~DynamicKernelArgument() {} /// Generate declaration virtual void GenDecl( std::stringstream& ss ) const = 0; @@ -97,36 +98,31 @@ public: /// When referenced in a sliding window function virtual std::string GenSlidingWindowDeclRef( bool = false ) const = 0; + /// Create buffer and pass the buffer to a given kernel + virtual size_t Marshal( cl_kernel, int, int, cl_program ) = 0; + + virtual size_t GetWindowSize() const = 0; + /// When Mix, it will be called - virtual std::string GenDoubleSlidingWindowDeclRef( bool = false ) const - { return std::string(""); } + virtual std::string GenDoubleSlidingWindowDeclRef( bool = false ) const; /// When Mix, it will be called - virtual std::string GenStringSlidingWindowDeclRef( bool = false ) const - { return std::string(""); } + virtual std::string GenStringSlidingWindowDeclRef( bool = false ) const; - virtual bool IsMixedArgument() const - { return false; } + virtual bool IsMixedArgument() const; /// Generate use/references to the argument virtual void GenDeclRef( std::stringstream& ss ) const; - virtual void GenNumDeclRef( std::stringstream& ss ) const { ss << ",";} + virtual void GenNumDeclRef( std::stringstream& ss ) const; - virtual void GenStringDeclRef( std::stringstream& ss ) const { ss << ",";} + virtual void GenStringDeclRef( std::stringstream& ss ) const; - /// Create buffer and pass the buffer to a given kernel - virtual size_t Marshal( cl_kernel, int, int, cl_program ) = 0; - - virtual ~DynamicKernelArgument() { } - - virtual void GenSlidingWindowFunction( std::stringstream& ) { } + virtual void GenSlidingWindowFunction( std::stringstream& ); formula::FormulaToken* GetFormulaToken() const; - virtual size_t GetWindowSize() const = 0; - virtual std::string DumpOpName() const { return std::string(""); } - virtual void DumpInlineFun( std::set<std::string>&, - std::set<std::string>& ) const { } - const std::string& GetName() const { return mSymName; } - virtual bool NeedParallelReduction() const { return false; } + virtual std::string DumpOpName() const; + virtual void DumpInlineFun( std::set<std::string>&, std::set<std::string>& ) const; + const std::string& GetName() const; + virtual bool NeedParallelReduction() const; protected: std::string mSymName; @@ -142,6 +138,7 @@ class VectorRef : public DynamicKernelArgument { public: VectorRef( const std::string& s, FormulaTreeNodeRef ft, int index = 0 ); + virtual ~VectorRef(); /// Generate declaration virtual void GenDecl( std::stringstream& ss ) const SAL_OVERRIDE; @@ -154,16 +151,13 @@ public: /// Create buffer and pass the buffer to a given kernel virtual size_t Marshal( cl_kernel, int, int, cl_program ) SAL_OVERRIDE; - virtual ~VectorRef(); - - virtual void GenSlidingWindowFunction( std::stringstream& ) SAL_OVERRIDE { } + virtual void GenSlidingWindowFunction( std::stringstream& ) SAL_OVERRIDE; virtual size_t GetWindowSize() const SAL_OVERRIDE; - virtual std::string DumpOpName() const SAL_OVERRIDE { return std::string(""); } - virtual void DumpInlineFun( std::set<std::string>&, - std::set<std::string>& ) const SAL_OVERRIDE { } - const std::string& GetName() const { return mSymName; } - virtual cl_mem GetCLBuffer() const { return mpClmem; } - virtual bool NeedParallelReduction() const SAL_OVERRIDE { return false; } + virtual std::string DumpOpName() const SAL_OVERRIDE; + virtual void DumpInlineFun( std::set<std::string>&, std::set<std::string>& ) const SAL_OVERRIDE; + const std::string& GetName() const; + virtual cl_mem GetCLBuffer() const; + virtual bool NeedParallelReduction() const SAL_OVERRIDE; protected: // Used by marshaling @@ -200,7 +194,7 @@ public: typedef std::vector<SubArgument> SubArguments; virtual void GenSlidingWindowFunction( std::stringstream&, const std::string&, SubArguments& ) = 0; - virtual ~SlidingFunctionBase() { }; + virtual ~SlidingFunctionBase() { } }; class Normal : public SlidingFunctionBase commit 7ec804786830dce73a35b762e7db5ab1add9449b Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Fri Oct 3 16:28:54 2014 -0400 GetSymName() not used. Change-Id: Ia369bf99a5e381a6f1f9c3d8a2499aa1780f04b8 diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx index ea89378..15dedc5 100644 --- a/sc/source/core/opencl/opbase.hxx +++ b/sc/source/core/opencl/opbase.hxx @@ -120,7 +120,6 @@ public: virtual ~DynamicKernelArgument() { } virtual void GenSlidingWindowFunction( std::stringstream& ) { } - const std::string& GetSymName() const { return mSymName; } formula::FormulaToken* GetFormulaToken() const; virtual size_t GetWindowSize() const = 0; virtual std::string DumpOpName() const { return std::string(""); } @@ -158,7 +157,6 @@ public: virtual ~VectorRef(); virtual void GenSlidingWindowFunction( std::stringstream& ) SAL_OVERRIDE { } - const std::string& GetSymName() const { return mSymName; } virtual size_t GetWindowSize() const SAL_OVERRIDE; virtual std::string DumpOpName() const SAL_OVERRIDE { return std::string(""); } virtual void DumpInlineFun( std::set<std::string>&, commit e954633776019a340d85c45cd586578aaa9ece10 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Fri Oct 3 16:26:05 2014 -0400 GetNameAsString() identical to GetName(). Remove this and use GetName(). Change-Id: I26dce2dd11792ee118e78d23d652a5feb0789830 diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx index d2ece0d..839b46c 100644 --- a/sc/source/core/opencl/op_statistical.cxx +++ b/sc/source/core/opencl/op_statistical.cxx @@ -5661,14 +5661,14 @@ void OpMedian::GenSlidingWindowFunction( ss << " int nSize =endFlag- startFlag ;\n"; ss << " if (nSize & 1)\n"; ss << " {\n"; - ss << " tmp = "<<vSubArguments[0]->GetNameAsString(); + ss << " tmp = "<<vSubArguments[0]->GetName(); ss << " [startFlag+nSize/2];\n"; ss << " }\n"; ss << " else\n"; ss << " {\n"; - ss << " tmp =("<<vSubArguments[0]->GetNameAsString(); + ss << " tmp =("<<vSubArguments[0]->GetName(); ss << " [startFlag+nSize/2]+"; - ss << vSubArguments[0]->GetNameAsString(); + ss << vSubArguments[0]->GetName(); ss << " [startFlag+nSize/2-1])/2;\n"; ss << " }\n"; ss <<" return tmp;\n"; diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx index 497af94..ea89378 100644 --- a/sc/source/core/opencl/opbase.hxx +++ b/sc/source/core/opencl/opbase.hxx @@ -88,7 +88,6 @@ class DynamicKernelArgument : boost::noncopyable public: DynamicKernelArgument( const std::string& s, FormulaTreeNodeRef ft ); - const std::string& GetNameAsString() const { return mSymName; } /// Generate declaration virtual void GenDecl( std::stringstream& ss ) const = 0; @@ -145,7 +144,6 @@ class VectorRef : public DynamicKernelArgument public: VectorRef( const std::string& s, FormulaTreeNodeRef ft, int index = 0 ); - const std::string& GetNameAsString() const { return mSymName; } /// Generate declaration virtual void GenDecl( std::stringstream& ss ) const SAL_OVERRIDE; /// When declared as input to a sliding window function commit c03d6d52cfc1b5b24ceaf9e6806706d5ee8a02f3 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Fri Oct 3 16:21:14 2014 -0400 ( void ) -> () Change-Id: I0d3d1d9ab5f7bc270c89a2a98d45ebea3cc37e02 diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx index e1aef1f..f19e36e 100644 --- a/sc/source/core/opencl/opbase.cxx +++ b/sc/source/core/opencl/opbase.cxx @@ -94,7 +94,7 @@ void DynamicKernelArgument::GenDeclRef( std::stringstream& ss ) const ss << mSymName; } -FormulaToken* DynamicKernelArgument::GetFormulaToken( void ) const +FormulaToken* DynamicKernelArgument::GetFormulaToken() const { return mFormulaTree->GetFormulaToken(); } @@ -144,7 +144,7 @@ std::string VectorRef::GenSlidingWindowDeclRef( bool nested ) const return ss.str(); } -size_t VectorRef::GetWindowSize( void ) const +size_t VectorRef::GetWindowSize() const { FormulaToken* pCur = mFormulaTree->GetFormulaToken(); assert(pCur); diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx index 125d24d..497af94 100644 --- a/sc/source/core/opencl/opbase.hxx +++ b/sc/source/core/opencl/opbase.hxx @@ -73,7 +73,7 @@ public: Children.reserve(8); } std::vector<FormulaTreeNodeRef> Children; - formula::FormulaToken* GetFormulaToken( void ) const + formula::FormulaToken* GetFormulaToken() const { return const_cast<formula::FormulaToken*>(mpCurrentFormula.get()); } @@ -88,7 +88,7 @@ class DynamicKernelArgument : boost::noncopyable public: DynamicKernelArgument( const std::string& s, FormulaTreeNodeRef ft ); - const std::string& GetNameAsString( void ) const { return mSymName; } + const std::string& GetNameAsString() const { return mSymName; } /// Generate declaration virtual void GenDecl( std::stringstream& ss ) const = 0; @@ -121,14 +121,14 @@ public: virtual ~DynamicKernelArgument() { } virtual void GenSlidingWindowFunction( std::stringstream& ) { } - const std::string& GetSymName( void ) const { return mSymName; } - formula::FormulaToken* GetFormulaToken( void ) const; - virtual size_t GetWindowSize( void ) const = 0; - virtual std::string DumpOpName( void ) const { return std::string(""); } + const std::string& GetSymName() const { return mSymName; } + formula::FormulaToken* GetFormulaToken() const; + virtual size_t GetWindowSize() const = 0; + virtual std::string DumpOpName() const { return std::string(""); } virtual void DumpInlineFun( std::set<std::string>&, std::set<std::string>& ) const { } - const std::string& GetName( void ) const { return mSymName; } - virtual bool NeedParallelReduction( void ) const { return false; } + const std::string& GetName() const { return mSymName; } + virtual bool NeedParallelReduction() const { return false; } protected: std::string mSymName; @@ -145,7 +145,7 @@ class VectorRef : public DynamicKernelArgument public: VectorRef( const std::string& s, FormulaTreeNodeRef ft, int index = 0 ); - const std::string& GetNameAsString( void ) const { return mSymName; } + const std::string& GetNameAsString() const { return mSymName; } /// Generate declaration virtual void GenDecl( std::stringstream& ss ) const SAL_OVERRIDE; /// When declared as input to a sliding window function @@ -160,14 +160,14 @@ public: virtual ~VectorRef(); virtual void GenSlidingWindowFunction( std::stringstream& ) SAL_OVERRIDE { } - const std::string& GetSymName( void ) const { return mSymName; } - virtual size_t GetWindowSize( void ) const SAL_OVERRIDE; - virtual std::string DumpOpName( void ) const SAL_OVERRIDE { return std::string(""); } + const std::string& GetSymName() const { return mSymName; } + virtual size_t GetWindowSize() const SAL_OVERRIDE; + virtual std::string DumpOpName() const SAL_OVERRIDE { return std::string(""); } virtual void DumpInlineFun( std::set<std::string>&, std::set<std::string>& ) const SAL_OVERRIDE { } - const std::string& GetName( void ) const { return mSymName; } - virtual cl_mem GetCLBuffer( void ) const { return mpClmem; } - virtual bool NeedParallelReduction( void ) const SAL_OVERRIDE { return false; } + const std::string& GetName() const { return mSymName; } + virtual cl_mem GetCLBuffer() const { return mpClmem; } + virtual bool NeedParallelReduction() const SAL_OVERRIDE { return false; } protected: // Used by marshaling @@ -182,11 +182,11 @@ class OpBase public: typedef std::vector<std::string> ArgVector; typedef std::vector<std::string>::iterator ArgVectorIter; - virtual std::string GetBottom( void ) { return "";}; + virtual std::string GetBottom() { return "";}; virtual std::string Gen2( const std::string&/*lhs*/, const std::string&/*rhs*/ ) const { return "";} virtual std::string Gen( ArgVector& /*argVector*/ ) { return "";}; - virtual std::string BinFuncName( void ) const { return "";}; + virtual std::string BinFuncName() const { return "";}; virtual void BinInlineFun( std::set<std::string>&, std::set<std::string>& ) { } virtual bool takeString() const = 0; commit 667c075cc740039be80014fee029ea5bf7617f95 Author: Andras Timar <andras.ti...@collabora.com> Date: Mon Oct 6 19:20:33 2014 +0200 Windows build fix Change-Id: I686457ca92ce1d503ea184e4d613b880610942da diff --git a/sc/inc/documentimport.hxx b/sc/inc/documentimport.hxx index 7d46216..e561fcd 100644 --- a/sc/inc/documentimport.hxx +++ b/sc/inc/documentimport.hxx @@ -44,7 +44,7 @@ class SC_DLLPUBLIC ScDocumentImport : boost::noncopyable public: - struct Attrs + struct SC_DLLPUBLIC Attrs { ScAttrEntry* mpData; size_t mnSize; commit 3197cee4cf94faa2d2acd78d985d6b847c78ef60 Author: Matúš Kukan <matus.ku...@collabora.com> Date: Fri Oct 3 23:12:56 2014 +0200 FastSerializer: Also use cache for writing to ForMerge if we are inside mark() To ensure the correct order of calling ForMerge methods, call flush always before touching maMarkStack. This was the missing piece in optimizing write() methods, because of writeBytes() checking each time what to call. E.g. for Calc documents we don't use maMarkStack at all. So, just transfer the output to proper "ForMerge" when inside mark() and allow optimizations. This commit makes write() methods almost 1/3 as fast. Change-Id: I96c13888206c81f87e29b998839f78ea9d5570af diff --git a/sax/source/tools/CachedOutputStream.hxx b/sax/source/tools/CachedOutputStream.hxx index 8877bb7..fc74118 100644 --- a/sax/source/tools/CachedOutputStream.hxx +++ b/sax/source/tools/CachedOutputStream.hxx @@ -17,9 +17,17 @@ #include <cstring> #include <cstdlib> +#include <boost/shared_ptr.hpp> namespace sax_fastparser { +class ForMergeBase +{ +public: + virtual ~ForMergeBase() {} + virtual void append( const css::uno::Sequence<sal_Int8>& rWhat ) = 0; +}; + class CachedOutputStream { /// When buffer hits this size, it's written to mxOutputStream @@ -30,11 +38,16 @@ class CachedOutputStream sal_Int32 mnCacheWrittenSize; const css::uno::Sequence<sal_Int8> mpCache; uno_Sequence *pSeq; + bool mbWriteToOutStream; + /// ForMerge structure is used for sorting elements in Writer + boost::shared_ptr< ForMergeBase > mpForMerge; public: CachedOutputStream() : mnCacheWrittenSize(0) , mpCache(mnMaximumSize) , pSeq(mpCache.get()) + , mbWriteToOutStream(true) + , mpForMerge(NULL) {} ~CachedOutputStream() {} @@ -48,6 +61,20 @@ public: mxOutputStream = xOutputStream; } + void setOutput( boost::shared_ptr< ForMergeBase > pForMerge ) + { + flush(); + mbWriteToOutStream = false; + mpForMerge = pForMerge; + } + + void resetOutputToStream() + { + flush(); + mbWriteToOutStream = true; + mpForMerge.reset(); + } + /// cache string and if limit is hit, flush void writeBytes( const sal_Int8* pStr, sal_Int32 nLen ) { @@ -61,7 +88,10 @@ public: // In that case, just flush data and write immediately. if (nLen > mnMaximumSize) { - mxOutputStream->writeBytes( css::uno::Sequence<sal_Int8>(pStr, nLen) ); + if (mbWriteToOutStream) + mxOutputStream->writeBytes( css::uno::Sequence<sal_Int8>(pStr, nLen) ); + else + mpForMerge->append( css::uno::Sequence<sal_Int8>(pStr, nLen) ); return; } } @@ -75,7 +105,10 @@ public: { // resize the Sequence to written size pSeq->nElements = mnCacheWrittenSize; - mxOutputStream->writeBytes( mpCache ); + if (mbWriteToOutStream) + mxOutputStream->writeBytes( mpCache ); + else + mpForMerge->append( mpCache ); // and next time write to the beginning mnCacheWrittenSize = 0; } diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx index 0f05ec9..ac8376b 100644 --- a/sax/source/tools/fastserializer.cxx +++ b/sax/source/tools/fastserializer.cxx @@ -57,6 +57,7 @@ namespace sax_fastparser { FastSaxSerializer::FastSaxSerializer( const css::uno::Reference< css::io::XOutputStream >& xOutputStream ) : maCachedOutputStream() , maMarkStack() + , mbMarkStackEmpty(true) , mpDoubleStr(NULL) , mnDoubleStrCapacity(RTL_STR_MAX_VALUEOFDOUBLE) { @@ -152,6 +153,7 @@ namespace sax_fastparser { void FastSaxSerializer::endDocument() { + assert(mbMarkStackEmpty && maMarkStack.empty()); maCachedOutputStream.flush(); } @@ -186,8 +188,11 @@ namespace sax_fastparser { void FastSaxSerializer::startFastElement( ::sal_Int32 Element, FastAttributeList* pAttrList ) { - if ( !maMarkStack.empty() ) + if ( !mbMarkStackEmpty ) + { + maCachedOutputStream.flush(); maMarkStack.top()->setCurrentElement( Element ); + } #ifdef DBG_UTIL m_DebugStartedElements.push(Element); @@ -222,8 +227,11 @@ namespace sax_fastparser { void FastSaxSerializer::singleFastElement( ::sal_Int32 Element, FastAttributeList* pAttrList ) { - if ( !maMarkStack.empty() ) + if ( !mbMarkStackEmpty ) + { + maCachedOutputStream.flush(); maMarkStack.top()->setCurrentElement( Element ); + } writeBytes(sOpeningBracket, N_CHARS(sOpeningBracket)); @@ -303,28 +311,47 @@ namespace sax_fastparser { { boost::shared_ptr< ForMerge > pSort( new ForSort( aOrder ) ); maMarkStack.push( pSort ); + maCachedOutputStream.setOutput( pSort ); } else { boost::shared_ptr< ForMerge > pMerge( new ForMerge( ) ); maMarkStack.push( pMerge ); + maCachedOutputStream.setOutput( pMerge ); } + mbMarkStackEmpty = false; } void FastSaxSerializer::mergeTopMarks( sax_fastparser::MergeMarksEnum eMergeType ) { - if ( maMarkStack.empty() ) + SAL_WARN_IF(mbMarkStackEmpty, "sax", "Empty mark stack - nothing to merge"); + if ( mbMarkStackEmpty ) return; + // flush, so that we get everything in getData() + maCachedOutputStream.flush(); + if ( maMarkStack.size() == 1 && eMergeType != MERGE_MARKS_IGNORE) { - writeOutput( maMarkStack.top()->getData() ); + Sequence<sal_Int8> aSeq( maMarkStack.top()->getData() ); maMarkStack.pop(); + mbMarkStackEmpty = true; + maCachedOutputStream.resetOutputToStream(); + maCachedOutputStream.writeBytes( aSeq.getConstArray(), aSeq.getLength() ); return; } const Int8Sequence aMerge( maMarkStack.top()->getData() ); maMarkStack.pop(); + if (maMarkStack.empty()) + { + mbMarkStackEmpty = true; + maCachedOutputStream.resetOutputToStream(); + } + else + { + maCachedOutputStream.setOutput( maMarkStack.top() ); + } switch ( eMergeType ) { @@ -338,26 +365,12 @@ namespace sax_fastparser { void FastSaxSerializer::writeBytes( const Sequence< sal_Int8 >& rData ) { - writeBytes( reinterpret_cast<const char*>(rData.getConstArray()), rData.getLength() ); + maCachedOutputStream.writeBytes( rData.getConstArray(), rData.getLength() ); } void FastSaxSerializer::writeBytes( const char* pStr, size_t nLen ) { - if ( maMarkStack.empty() ) - writeOutput( reinterpret_cast<const sal_Int8*>(pStr), nLen ); - else - maMarkStack.top()->append( Sequence< sal_Int8 >( - reinterpret_cast<const sal_Int8*>(pStr), nLen) ); - } - - void FastSaxSerializer::writeOutput( const Sequence< ::sal_Int8 >& aData ) - { - writeOutput( aData.getConstArray(), aData.getLength() ); - } - - void FastSaxSerializer::writeOutput( const sal_Int8* pStr, size_t nLen ) - { - maCachedOutputStream.writeBytes( pStr, nLen ); + maCachedOutputStream.writeBytes( reinterpret_cast<const sal_Int8*>(pStr), nLen ); } FastSaxSerializer::Int8Sequence& FastSaxSerializer::ForMerge::getData() diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx index 5b740ce..8500b68 100644 --- a/sax/source/tools/fastserializer.hxx +++ b/sax/source/tools/fastserializer.hxx @@ -148,11 +148,14 @@ public: void mergeTopMarks( sax_fastparser::MergeMarksEnum eMergeType = sax_fastparser::MERGE_MARKS_APPEND ); private: - /// Helper class to cache data and write in chunks to XOutputStream + /** Helper class to cache data and write in chunks to XOutputStream or ForMerge::append. + * Its flush method needs to be called before touching maMarkStack + * to ensure correct order of ForSort methods. + */ CachedOutputStream maCachedOutputStream; ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxFastTokenHandler; - class ForMerge + class ForMerge : public ForMergeBase { Int8Sequence maData; Int8Sequence maPostponed; @@ -168,7 +171,7 @@ private: #endif virtual void prepend( const Int8Sequence &rWhat ); - virtual void append( const Int8Sequence &rWhat ); + virtual void append( const Int8Sequence &rWhat ) SAL_OVERRIDE; void postpone( const Int8Sequence &rWhat ); protected: @@ -205,6 +208,7 @@ private: }; ::std::stack< boost::shared_ptr< ForMerge > > maMarkStack; + bool mbMarkStackEmpty; // Would be better to use OStringBuffer instead of these two // but then we couldn't get the rtl_String* member :-( rtl_String *mpDoubleStr; @@ -217,8 +221,6 @@ private: void writeTokenValueList(); void writeFastAttributeList( FastAttributeList* pAttrList ); - void writeOutput( const sal_Int8* pStr, size_t nLen ); - void writeOutput( const css::uno::Sequence< ::sal_Int8 >& aData ); /** Forward the call to the output stream, or write to the stack. commit 384c71b13f2b390ae578b10bc906790bbb53c4d5 Author: Matúš Kukan <matus.ku...@collabora.com> Date: Fri Oct 3 20:45:04 2014 +0200 inline TokenMap::getUtf8TokenName Change-Id: Icd9c6ebc9feb3e7aba28b01729b582a8f49c832a diff --git a/include/oox/token/tokenmap.hxx b/include/oox/token/tokenmap.hxx index 6298773..50984e7 100644 --- a/include/oox/token/tokenmap.hxx +++ b/include/oox/token/tokenmap.hxx @@ -21,6 +21,7 @@ #define INCLUDED_OOX_TOKEN_TOKENMAP_HXX #include <vector> +#include <oox/token/tokens.hxx> #include <rtl/instance.hxx> #include <rtl/ustring.hxx> #include <com/sun/star/uno/Sequence.hxx> @@ -40,7 +41,13 @@ public: /** Returns the UTF8 name of the passed token identifier as byte sequence. */ ::com::sun::star::uno::Sequence< sal_Int8 > - getUtf8TokenName( sal_Int32 nToken ) const; + getUtf8TokenName( sal_Int32 nToken ) const + { + SAL_WARN_IF(nToken < 0 || nToken >= XML_TOKEN_COUNT, "oox", "Wrong nToken parameter"); + if (0 <= nToken && nToken < XML_TOKEN_COUNT) + return maTokenNames[ nToken ]; + return css::uno::Sequence< sal_Int8 >(); + } /** Returns the token identifier for the passed UTF8 token name. */ sal_Int32 getTokenFromUtf8( diff --git a/oox/source/token/tokenmap.cxx b/oox/source/token/tokenmap.cxx index dcd7284..318aee4 100644 --- a/oox/source/token/tokenmap.cxx +++ b/oox/source/token/tokenmap.cxx @@ -80,13 +80,6 @@ sal_Int32 TokenMap::getTokenFromUnicode( const OUString& rUnicodeName ) const return pToken ? pToken->nToken : XML_TOKEN_INVALID; } -Sequence< sal_Int8 > TokenMap::getUtf8TokenName( sal_Int32 nToken ) const -{ - if( (0 <= nToken) && (static_cast< size_t >( nToken ) < XML_TOKEN_COUNT) ) - return maTokenNames[ static_cast< size_t >( nToken ) ]; - return Sequence< sal_Int8 >(); -} - sal_Int32 TokenMap::getTokenPerfectHash( const char *pStr, sal_Int32 nLength ) const { const struct xmltoken* pToken = Perfect_Hash::in_word_set( pStr, nLength ); commit 9dab773e60dd3b41a717f432a3a85777c36935b7 Author: Matúš Kukan <matus.ku...@collabora.com> Date: Fri Oct 3 16:37:26 2014 +0200 FastSerializer: Simplify OUString write a bit more Change-Id: Ifa0746d635ec43cdc37867cf94bcc128bb8e2aca diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx index cd8b0ca..0f05ec9 100644 --- a/sax/source/tools/fastserializer.cxx +++ b/sax/source/tools/fastserializer.cxx @@ -53,15 +53,6 @@ static const char sEqualSignAndQuote[] = "=\""; static const char sSpace[] = " "; static const char sXmlHeader[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; -static bool lcl_isAscii(const OUString& sStr) -{ - for (sal_Int32 i = 0; i < sStr.getLength(); ++i) - if (sStr[i] & 0xff80) - return false; - - return true; -} - namespace sax_fastparser { FastSaxSerializer::FastSaxSerializer( const css::uno::Reference< css::io::XOutputStream >& xOutputStream ) : maCachedOutputStream() @@ -101,16 +92,16 @@ namespace sax_fastparser { void FastSaxSerializer::write( const OUString& sOutput, bool bEscape ) { - if (!lcl_isAscii(sOutput)) - { - write( OUStringToOString(sOutput, RTL_TEXTENCODING_UTF8), bEscape ); - return ; - } - - for (sal_Int32 i = 0; i < sOutput.getLength(); ++i) + const sal_Int32 nLength = sOutput.getLength(); + for (sal_Int32 i = 0; i < nLength; ++i) { - char c = sOutput[ i ]; - if (bEscape) switch( c ) + const sal_Unicode cUnicode = sOutput[ i ]; + const char cChar = cUnicode; + if (cUnicode & 0xff80) + { + write( OString(&cUnicode, 1, RTL_TEXTENCODING_UTF8) ); + } + else if(bEscape) switch( cChar ) { case '<': writeBytes( "<", 4 ); break; case '>': writeBytes( ">", 4 ); break; @@ -119,10 +110,10 @@ namespace sax_fastparser { case '"': writeBytes( """, 6 ); break; case '\n': writeBytes( " ", 5 ); break; case '\r': writeBytes( " ", 5 ); break; - default: writeBytes( &c, 1 ); break; + default: writeBytes( &cChar, 1 ); break; } else - writeBytes( &c, 1 ); + writeBytes( &cChar, 1 ); } } commit 06821c38ad9b3373fe22dea35cfa3e9e2fb1bbd7 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Fri Oct 3 15:16:06 2014 -0400 Let's consistently spell OpenCL as 'OpenCL'. Change-Id: I8bdcf0667b326b77d11001efeeefd5247987ebdc diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index cb2efa8..c8dbcce 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -3260,19 +3260,11 @@ public: DynamicKernelSoPArguments>(mpRoot, new OpNop); std::stringstream decl; -<<<<<<< HEAD if (OpenCLDevice::gpuEnv.mnKhrFp64Flag) { decl << "#pragma OPENCL EXTENSION cl_khr_fp64: enable\n"; } else if (OpenCLDevice::gpuEnv.mnAmdFp64Flag) -======= - if (OpenclDevice::gpuEnv.mnKhrFp64Flag) - { - decl << "#pragma OPENCL EXTENSION cl_khr_fp64: enable\n"; - } - else if (OpenclDevice::gpuEnv.mnAmdFp64Flag) ->>>>>>> Make the coding style consistent with the rest of Calc code. { decl << "#pragma OPENCL EXTENSION cl_amd_fp64: enable\n"; } @@ -3396,11 +3388,7 @@ void DynamicKernel::CreateKernel() // Compile kernel here!!! // Obtain cl context KernelEnv kEnv; -<<<<<<< HEAD OpenCLDevice::setKernelEnv(&kEnv); -======= - OpenclDevice::setKernelEnv(&kEnv); ->>>>>>> Make the coding style consistent with the rest of Calc code. const char* src = mFullProgramSrc.c_str(); static std::string lastOneKernelHash = ""; static std::string lastSecondKernelHash = ""; @@ -3422,19 +3410,11 @@ void DynamicKernel::CreateKernel() { clReleaseProgram(lastSecondProgram); } -<<<<<<< HEAD if (OpenCLDevice::buildProgramFromBinary("", &OpenCLDevice::gpuEnv, KernelHash.c_str(), 0)) { mpProgram = OpenCLDevice::gpuEnv.mpArryPrograms[0]; OpenCLDevice::gpuEnv.mpArryPrograms[0] = NULL; -======= - if (OpenclDevice::buildProgramFromBinary("", - &OpenclDevice::gpuEnv, KernelHash.c_str(), 0)) - { - mpProgram = OpenclDevice::gpuEnv.mpArryPrograms[0]; - OpenclDevice::gpuEnv.mpArryPrograms[0] = NULL; ->>>>>>> Make the coding style consistent with the rest of Calc code. } else { @@ -3443,11 +3423,7 @@ void DynamicKernel::CreateKernel() if (err != CL_SUCCESS) throw OpenCLError(err, __FILE__, __LINE__); err = clBuildProgram(mpProgram, 1, -<<<<<<< HEAD OpenCLDevice::gpuEnv.mpArryDevsID, "", NULL, NULL); -======= - OpenclDevice::gpuEnv.mpArryDevsID, "", NULL, NULL); ->>>>>>> Make the coding style consistent with the rest of Calc code. if (err != CL_SUCCESS) { #if OSL_DEBUG_LEVEL > 0 @@ -3455,11 +3431,7 @@ void DynamicKernel::CreateKernel() { cl_build_status stat; cl_int e = clGetProgramBuildInfo( -<<<<<<< HEAD mpProgram, OpenCLDevice::gpuEnv.mpArryDevsID[0], -======= - mpProgram, OpenclDevice::gpuEnv.mpArryDevsID[0], ->>>>>>> Make the coding style consistent with the rest of Calc code. CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &stat, 0); SAL_WARN_IF( @@ -3501,11 +3473,7 @@ void DynamicKernel::CreateKernel() throw OpenCLError(err, __FILE__, __LINE__); } // Generate binary out of compiled kernel. -<<<<<<< HEAD OpenCLDevice::generatBinFromKernelSource(mpProgram, -======= - OpenclDevice::generatBinFromKernelSource(mpProgram, ->>>>>>> Make the coding style consistent with the rest of Calc code. (mKernelSignature + GetMD5()).c_str()); } lastSecondKernelHash = lastOneKernelHash; @@ -3713,11 +3681,7 @@ bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc, } catch (const UnhandledToken& ut) { -<<<<<<< HEAD std::cerr << "\nDynamic formula compiler: unhandled token: "; -======= - std::cerr << "\nDynamic formual compiler: unhandled token: "; ->>>>>>> Make the coding style consistent with the rest of Calc code. std::cerr << ut.mMessage << "\n"; #ifdef NO_FALLBACK_TO_SWINTERP assert(false); @@ -3780,26 +3744,16 @@ SAL_DLLPUBLIC_EXPORT size_t getOpenCLPlatformCount() } SAL_DLLPUBLIC_EXPORT void SAL_CALL fillOpenCLInfo( -<<<<<<< HEAD sc::OpenCLPlatformInfo* pInfos, size_t nInfoSize ) { const std::vector<sc::OpenCLPlatformInfo>& rPlatforms = -======= - sc::OpenclPlatformInfo* pInfos, size_t nInfoSize ) -{ - const std::vector<sc::OpenclPlatformInfo>& rPlatforms = ->>>>>>> Make the coding style consistent with the rest of Calc code. sc::opencl::fillOpenCLInfo(); size_t n = std::min(rPlatforms.size(), nInfoSize); for (size_t i = 0; i < n; ++i) pInfos[i] = rPlatforms[i]; } -<<<<<<< HEAD SAL_DLLPUBLIC_EXPORT bool SAL_CALL switchOpenCLDevice( -======= -SAL_DLLPUBLIC_EXPORT bool SAL_CALL switchOpenClDevice( ->>>>>>> Make the coding style consistent with the rest of Calc code. const OUString* pDeviceId, bool bAutoSelect, bool bForceEvaluation ) { commit 188df25f94f4a8d2487a0b32d054c60cf895e0b2 Author: Matúš Kukan <matus.ku...@collabora.com> Date: Fri Oct 3 12:30:51 2014 +0200 FastSerializer: Avoid some cycles when dealing with doubles Would be easier to use OStringBuffer, but we can't get its pData member. Also its append(double) is suboptimal (or anything that uses rtl_str_valueOfDouble) - should be doing something like this commit. Change-Id: I8f3140081a574a84f0e60dc85cce1bd2de23cd34 diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx index 3876609..cd8b0ca 100644 --- a/sax/source/tools/fastserializer.cxx +++ b/sax/source/tools/fastserializer.cxx @@ -20,7 +20,7 @@ #include "fastserializer.hxx" #include <com/sun/star/xml/sax/FastTokenHandler.hpp> -#include <rtl/ustrbuf.hxx> +#include <rtl/math.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/sequenceasvector.hxx> @@ -66,19 +66,39 @@ namespace sax_fastparser { FastSaxSerializer::FastSaxSerializer( const css::uno::Reference< css::io::XOutputStream >& xOutputStream ) : maCachedOutputStream() , maMarkStack() + , mpDoubleStr(NULL) + , mnDoubleStrCapacity(RTL_STR_MAX_VALUEOFDOUBLE) { + rtl_string_new_WithLength(&mpDoubleStr, mnDoubleStrCapacity); mxFastTokenHandler = css::xml::sax::FastTokenHandler::create( ::comphelper::getProcessComponentContext()); assert(xOutputStream.is()); // cannot do anything without that maCachedOutputStream.setOutputStream( xOutputStream ); } - FastSaxSerializer::~FastSaxSerializer() {} + + FastSaxSerializer::~FastSaxSerializer() + { + rtl_string_release(mpDoubleStr); + } void FastSaxSerializer::startDocument() { writeBytes(sXmlHeader, N_CHARS(sXmlHeader)); } + void FastSaxSerializer::write( double value ) + { + rtl_math_doubleToString( + &mpDoubleStr, &mnDoubleStrCapacity, 0, value, rtl_math_StringFormat_G, + RTL_STR_MAX_VALUEOFDOUBLE - RTL_CONSTASCII_LENGTH("-x.E-xxx"), '.', 0, + 0, sal_True); + + write(mpDoubleStr->buffer, mpDoubleStr->length); + // and "clear" the string + mpDoubleStr->length = 0; + mnDoubleStrCapacity = RTL_STR_MAX_VALUEOFDOUBLE; + } + void FastSaxSerializer::write( const OUString& sOutput, bool bEscape ) { if (!lcl_isAscii(sOutput)) diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx index 60ef71b..5b740ce 100644 --- a/sax/source/tools/fastserializer.hxx +++ b/sax/source/tools/fastserializer.hxx @@ -110,6 +110,7 @@ public: void writeId( ::sal_Int32 Element ); OString getId( ::sal_Int32 Element ); + void write( double value ); void write( const OUString& s, bool bEscape = false ); void write( const OString& s, bool bEscape = false ); void write( const char* pStr, sal_Int32 nLen, bool bEscape = false ); @@ -204,6 +205,10 @@ private: }; ::std::stack< boost::shared_ptr< ForMerge > > maMarkStack; + // Would be better to use OStringBuffer instead of these two + // but then we couldn't get the rtl_String* member :-( + rtl_String *mpDoubleStr; + sal_Int32 mnDoubleStrCapacity; TokenValueList maTokenValues; #ifdef DBG_UTIL diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx index 801be10..15a5efa 100644 --- a/sax/source/tools/fshelper.cxx +++ b/sax/source/tools/fshelper.cxx @@ -126,7 +126,7 @@ FastSerializerHelper* FastSerializerHelper::write(sal_Int64 value) FastSerializerHelper* FastSerializerHelper::write(double value) { - mpSerializer->write(OString::number(value)); + mpSerializer->write(value); return this; } commit 35621ec0e60ec9a2ae608442a686e86a4f25cb4e Author: Matúš Kukan <matus.ku...@collabora.com> Date: Fri Oct 3 11:35:46 2014 +0200 FastSerializer: Use fixed sized Sequence directly as cache Well, at least the allocated space is fixed size. When passing that to XOutputStream, change the size in a hacky way. Change-Id: I24fa134286e3086beda25c9a6915549e7c69119a diff --git a/sax/source/tools/CachedOutputStream.hxx b/sax/source/tools/CachedOutputStream.hxx index 82c2b66..8877bb7 100644 --- a/sax/source/tools/CachedOutputStream.hxx +++ b/sax/source/tools/CachedOutputStream.hxx @@ -28,10 +28,14 @@ class CachedOutputStream /// Output stream, usually writing data into files. css::uno::Reference< css::io::XOutputStream > mxOutputStream; sal_Int32 mnCacheWrittenSize; - sal_Int8 mpCache[ mnMaximumSize ]; + const css::uno::Sequence<sal_Int8> mpCache; + uno_Sequence *pSeq; public: - CachedOutputStream() : mnCacheWrittenSize(0) {} + CachedOutputStream() : mnCacheWrittenSize(0) + , mpCache(mnMaximumSize) + , pSeq(mpCache.get()) + {} ~CachedOutputStream() {} css::uno::Reference< css::io::XOutputStream > getOutputStream() const @@ -62,14 +66,16 @@ public: } } - memcpy(mpCache + mnCacheWrittenSize, pStr, nLen); + memcpy(pSeq->elements + mnCacheWrittenSize, pStr, nLen); mnCacheWrittenSize += nLen; } /// immediately write buffer into mxOutputStream and clear void flush() { - mxOutputStream->writeBytes( css::uno::Sequence<sal_Int8>(mpCache, mnCacheWrittenSize) ); + // resize the Sequence to written size + pSeq->nElements = mnCacheWrittenSize; + mxOutputStream->writeBytes( mpCache ); // and next time write to the beginning mnCacheWrittenSize = 0; } commit 630396b5a20ffb383aafb9879f18dcefdf1d05eb Author: Matúš Kukan <matus.ku...@collabora.com> Date: Fri Oct 3 10:41:18 2014 +0200 FastSerializer: Use -1 for unknown string length Change-Id: I3920caf9d95f20992b7961873f1668468d797e8e diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx index d885768..3876609 100644 --- a/sax/source/tools/fastserializer.cxx +++ b/sax/source/tools/fastserializer.cxx @@ -113,7 +113,7 @@ namespace sax_fastparser { void FastSaxSerializer::write( const char* pStr, sal_Int32 nLen, bool bEscape ) { - if (nLen == 0) + if (nLen == -1) nLen = strlen(pStr); if (!bEscape) @@ -251,7 +251,7 @@ namespace sax_fastparser { writeBytes(sEqualSignAndQuote, N_CHARS(sEqualSignAndQuote)); - write(maTokenValues[j].pValue, 0, true); + write(maTokenValues[j].pValue, -1, true); writeBytes(sQuote, N_CHARS(sQuote)); } diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx index e0ed751..801be10 100644 --- a/sax/source/tools/fshelper.cxx +++ b/sax/source/tools/fshelper.cxx @@ -102,7 +102,7 @@ void FastSerializerHelper::singleElement(sal_Int32 elementTokenId, XFastAttribut FastSerializerHelper* FastSerializerHelper::write(const char* value) { - mpSerializer->write(value, 0, false); + mpSerializer->write(value, -1, false); return this; } @@ -132,13 +132,14 @@ FastSerializerHelper* FastSerializerHelper::write(double value) FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value) { - mpSerializer->write(value, 0, true); + mpSerializer->write(value, -1, true); return this; } FastSerializerHelper* FastSerializerHelper::writeEscaped(const OUString& value) { - mpSerializer->write(value, true); + if (!value.isEmpty()) + mpSerializer->write(value, true); return this; } commit 58ed9ce779cb345a114440ab25d33536d38484a1 Author: Matúš Kukan <matus.ku...@collabora.com> Date: Fri Oct 3 11:16:39 2014 +0200 Remove few pointless OUString::number() and one method Change-Id: I3e9a302a7513eebfeff07402f71fc3dde22e4cc2 diff --git a/include/sax/fshelper.hxx b/include/sax/fshelper.hxx index 1f3b1b8..50248ce 100644 --- a/include/sax/fshelper.hxx +++ b/include/sax/fshelper.hxx @@ -124,7 +124,6 @@ public: FastSerializerHelper* write(const char* value); FastSerializerHelper* write(const OUString& value); - FastSerializerHelper* write(const OString& value); FastSerializerHelper* write(sal_Int32 value); FastSerializerHelper* write(sal_Int64 value); FastSerializerHelper* write(double value); diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx index 001c9db..07fd4df 100644 --- a/oox/source/core/xmlfilterbase.cxx +++ b/oox/source/core/xmlfilterbase.cxx @@ -524,7 +524,7 @@ static void writeElement( FSHelperPtr pDoc, sal_Int32 nXmlElement, const sal_Int32 nValue ) { pDoc->startElement( nXmlElement, FSEND ); - pDoc->write( OUString::number( nValue ) ); + pDoc->write( nValue ); pDoc->endElement( nXmlElement ); } @@ -677,7 +677,7 @@ writeAppProperties( XmlFilterBase& rSelf, Reference< XDocumentProperties > xProp { sal_Int32 nValue = 0; if (it->second >>= nValue) - writeElement(pAppProps, XML_Paragraphs, OUString::number(nValue)); + writeElement(pAppProps, XML_Paragraphs, nValue); } uno::Reference<beans::XPropertyAccess> xUserDefinedProperties(xProperties->getUserDefinedProperties(), uno::UNO_QUERY); @@ -719,10 +719,9 @@ writeCustomProperties( XmlFilterBase& rSelf, Reference< XDocumentProperties > xP OString aName = OUStringToOString( aprop[n].Name, RTL_TEXTENCODING_ASCII_US ); // pid starts from 2 not from 1 as MS supports pid from 2 - OString pid = OUStringToOString( OUString::number(n + 2), RTL_TEXTENCODING_ASCII_US ); pAppProps->startElement( XML_property , XML_fmtid, "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", - XML_pid, pid, + XML_pid, OString::number(n + 2), XML_name, aName, FSEND); diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx index 55be646..e0ed751 100644 --- a/sax/source/tools/fshelper.cxx +++ b/sax/source/tools/fshelper.cxx @@ -112,25 +112,22 @@ FastSerializerHelper* FastSerializerHelper::write(const OUString& value) return this; } -FastSerializerHelper* FastSerializerHelper::write(const OString& value) -{ - mpSerializer->write(value); - return this; -} - FastSerializerHelper* FastSerializerHelper::write(sal_Int32 value) { - return write(OString::number(value)); + mpSerializer->write(OString::number(value)); + return this; } FastSerializerHelper* FastSerializerHelper::write(sal_Int64 value) { - return write(OString::number(value)); + mpSerializer->write(OString::number(value)); + return this; } FastSerializerHelper* FastSerializerHelper::write(double value) { - return write(OString::number(value)); + mpSerializer->write(OString::number(value)); + return this; } FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value) commit 4124dc81aa7b86c73e14684cfa8324c2a1d26281 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Thu Oct 2 15:24:46 2014 -0400 Make the coding style consistent with the rest of Calc code. I just ran SlickEdit's 'beautify' command with some follow-up manual editing. Change-Id: I402e782e7d147c4c95ebaa8ffcc40b50a0c565a7 diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index c8dbcce..cb2efa8 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -3260,11 +3260,19 @@ public: DynamicKernelSoPArguments>(mpRoot, new OpNop); std::stringstream decl; +<<<<<<< HEAD if (OpenCLDevice::gpuEnv.mnKhrFp64Flag) { decl << "#pragma OPENCL EXTENSION cl_khr_fp64: enable\n"; } else if (OpenCLDevice::gpuEnv.mnAmdFp64Flag) +======= + if (OpenclDevice::gpuEnv.mnKhrFp64Flag) + { + decl << "#pragma OPENCL EXTENSION cl_khr_fp64: enable\n"; + } + else if (OpenclDevice::gpuEnv.mnAmdFp64Flag) +>>>>>>> Make the coding style consistent with the rest of Calc code. { decl << "#pragma OPENCL EXTENSION cl_amd_fp64: enable\n"; } @@ -3388,7 +3396,11 @@ void DynamicKernel::CreateKernel() // Compile kernel here!!! // Obtain cl context KernelEnv kEnv; +<<<<<<< HEAD OpenCLDevice::setKernelEnv(&kEnv); +======= + OpenclDevice::setKernelEnv(&kEnv); +>>>>>>> Make the coding style consistent with the rest of Calc code. const char* src = mFullProgramSrc.c_str(); static std::string lastOneKernelHash = ""; static std::string lastSecondKernelHash = ""; @@ -3410,11 +3422,19 @@ void DynamicKernel::CreateKernel() { clReleaseProgram(lastSecondProgram); } +<<<<<<< HEAD if (OpenCLDevice::buildProgramFromBinary("", &OpenCLDevice::gpuEnv, KernelHash.c_str(), 0)) { mpProgram = OpenCLDevice::gpuEnv.mpArryPrograms[0]; OpenCLDevice::gpuEnv.mpArryPrograms[0] = NULL; +======= + if (OpenclDevice::buildProgramFromBinary("", + &OpenclDevice::gpuEnv, KernelHash.c_str(), 0)) + { + mpProgram = OpenclDevice::gpuEnv.mpArryPrograms[0]; + OpenclDevice::gpuEnv.mpArryPrograms[0] = NULL; +>>>>>>> Make the coding style consistent with the rest of Calc code. } else { @@ -3423,7 +3443,11 @@ void DynamicKernel::CreateKernel() if (err != CL_SUCCESS) throw OpenCLError(err, __FILE__, __LINE__); err = clBuildProgram(mpProgram, 1, +<<<<<<< HEAD OpenCLDevice::gpuEnv.mpArryDevsID, "", NULL, NULL); +======= + OpenclDevice::gpuEnv.mpArryDevsID, "", NULL, NULL); +>>>>>>> Make the coding style consistent with the rest of Calc code. if (err != CL_SUCCESS) { #if OSL_DEBUG_LEVEL > 0 @@ -3431,7 +3455,11 @@ void DynamicKernel::CreateKernel() { cl_build_status stat; cl_int e = clGetProgramBuildInfo( +<<<<<<< HEAD mpProgram, OpenCLDevice::gpuEnv.mpArryDevsID[0], +======= + mpProgram, OpenclDevice::gpuEnv.mpArryDevsID[0], +>>>>>>> Make the coding style consistent with the rest of Calc code. CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &stat, 0); SAL_WARN_IF( @@ -3473,7 +3501,11 @@ void DynamicKernel::CreateKernel() throw OpenCLError(err, __FILE__, __LINE__); } // Generate binary out of compiled kernel. +<<<<<<< HEAD OpenCLDevice::generatBinFromKernelSource(mpProgram, +======= + OpenclDevice::generatBinFromKernelSource(mpProgram, +>>>>>>> Make the coding style consistent with the rest of Calc code. (mKernelSignature + GetMD5()).c_str()); } lastSecondKernelHash = lastOneKernelHash; @@ -3681,7 +3713,11 @@ bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc, } catch (const UnhandledToken& ut) { +<<<<<<< HEAD std::cerr << "\nDynamic formula compiler: unhandled token: "; +======= + std::cerr << "\nDynamic formual compiler: unhandled token: "; +>>>>>>> Make the coding style consistent with the rest of Calc code. std::cerr << ut.mMessage << "\n"; #ifdef NO_FALLBACK_TO_SWINTERP assert(false); @@ -3744,16 +3780,26 @@ SAL_DLLPUBLIC_EXPORT size_t getOpenCLPlatformCount() } SAL_DLLPUBLIC_EXPORT void SAL_CALL fillOpenCLInfo( +<<<<<<< HEAD sc::OpenCLPlatformInfo* pInfos, size_t nInfoSize ) { const std::vector<sc::OpenCLPlatformInfo>& rPlatforms = +======= + sc::OpenclPlatformInfo* pInfos, size_t nInfoSize ) +{ + const std::vector<sc::OpenclPlatformInfo>& rPlatforms = +>>>>>>> Make the coding style consistent with the rest of Calc code. sc::opencl::fillOpenCLInfo(); size_t n = std::min(rPlatforms.size(), nInfoSize); for (size_t i = 0; i < n; ++i) pInfos[i] = rPlatforms[i]; } +<<<<<<< HEAD SAL_DLLPUBLIC_EXPORT bool SAL_CALL switchOpenCLDevice( +======= +SAL_DLLPUBLIC_EXPORT bool SAL_CALL switchOpenClDevice( +>>>>>>> Make the coding style consistent with the rest of Calc code. const OUString* pDeviceId, bool bAutoSelect, ... etc. - the rest is truncated
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits