[Libreoffice-commits] core.git: Branch 'feature/perfwork4' - 2 commits - filter/source include/package package/inc package/source

Matúš Kukan matus.kukan at collabora.com
Mon Oct 27 11:06:37 PDT 2014


 filter/source/xsltfilter/OleHandler.cxx        |    2 -
 include/package/Deflater.hxx                   |    2 -
 package/inc/CRC32.hxx                          |    2 -
 package/inc/ZipOutputEntry.hxx                 |    2 -
 package/inc/ZipOutputStream.hxx                |    2 -
 package/source/zipapi/CRC32.cxx                |    7 ++---
 package/source/zipapi/Deflater.cxx             |    8 ++----
 package/source/zipapi/ZipFile.cxx              |    4 +--
 package/source/zipapi/ZipOutputEntry.cxx       |    6 ++---
 package/source/zipapi/ZipOutputStream.cxx      |    7 ++---
 package/source/zippackage/ZipPackage.cxx       |   14 +++++------
 package/source/zippackage/ZipPackageStream.cxx |   30 +++++++++++--------------
 12 files changed, 39 insertions(+), 47 deletions(-)

New commits:
commit ac467076029907da366280f2ab1244bee7067bb0
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Mon Oct 27 14:26:54 2014 +0100

    Simplify input parameters to just take the sequence
    
    Change-Id: Ic2538ca8b0f7261064e1dfbf3884dd452003c797

diff --git a/filter/source/xsltfilter/OleHandler.cxx b/filter/source/xsltfilter/OleHandler.cxx
index 1515174..f1a7ea0 100644
--- a/filter/source/xsltfilter/OleHandler.cxx
+++ b/filter/source/xsltfilter/OleHandler.cxx
@@ -198,7 +198,7 @@ namespace XSLT
         // Compress the bytes
         Sequence<sal_Int8> output(oledata.getLength());
         boost::scoped_ptr< ::ZipUtils::Deflater> compresser(new ::ZipUtils::Deflater((sal_Int32) 3, false));
-        compresser->setInputSegment(oledata, 0, oledata.getLength());
+        compresser->setInputSegment(oledata);
         compresser->finish();
         int compressedDataLength = compresser->doDeflateSegment(output, 0, oledata.getLength());
         compresser.reset();
diff --git a/include/package/Deflater.hxx b/include/package/Deflater.hxx
index ad73f28..665407d 100644
--- a/include/package/Deflater.hxx
+++ b/include/package/Deflater.hxx
@@ -46,7 +46,7 @@ protected:
 public:
     ~Deflater();
     Deflater(sal_Int32 nSetLevel, bool bNowrap);
-    void SAL_CALL setInputSegment( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength );
+    void SAL_CALL setInputSegment( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer );
     void SAL_CALL setLevel( sal_Int32 nNewLevel );
     bool SAL_CALL needsInput(  );
     void SAL_CALL finish(  );
diff --git a/package/inc/CRC32.hxx b/package/inc/CRC32.hxx
index daaf4b5..cfc66c4 100644
--- a/package/inc/CRC32.hxx
+++ b/package/inc/CRC32.hxx
@@ -35,7 +35,7 @@ public:
 
     sal_Int64 SAL_CALL updateStream (::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > & xStream)
         throw(::com::sun::star::uno::RuntimeException);
-    void SAL_CALL updateSegment(const ::com::sun::star::uno::Sequence< sal_Int8 > &b, sal_Int32 off, sal_Int32 len)
+    void SAL_CALL updateSegment(const ::com::sun::star::uno::Sequence< sal_Int8 > &b, sal_Int32 len)
         throw(::com::sun::star::uno::RuntimeException);
     void SAL_CALL update(const ::com::sun::star::uno::Sequence< sal_Int8 > &b)
         throw(::com::sun::star::uno::RuntimeException);
diff --git a/package/inc/ZipOutputEntry.hxx b/package/inc/ZipOutputEntry.hxx
index 9e396ce..26ebb15 100644
--- a/package/inc/ZipOutputEntry.hxx
+++ b/package/inc/ZipOutputEntry.hxx
@@ -59,7 +59,7 @@ public:
     bool isEncrypt() { return m_bEncryptCurrentEntry; }
 
     void closeEntry();
-    void write(const css::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength);
+    void write(const css::uno::Sequence< sal_Int8 >& rBuffer);
 
 private:
     void doDeflate();
diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx
index ddc921d..54638d5 100644
--- a/package/inc/ZipOutputStream.hxx
+++ b/package/inc/ZipOutputStream.hxx
@@ -50,7 +50,7 @@ public:
 
     void writeLOC( ZipEntry *pEntry, bool bEncrypt = false )
         throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
-    void rawWrite( ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
+    void rawWrite( const css::uno::Sequence< sal_Int8 >& rBuffer )
         throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
     void rawCloseEntry( bool bEncrypt = false )
         throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
diff --git a/package/source/zipapi/CRC32.cxx b/package/source/zipapi/CRC32.cxx
index 6aee4d5..39b4f4c 100644
--- a/package/source/zipapi/CRC32.cxx
+++ b/package/source/zipapi/CRC32.cxx
@@ -47,11 +47,10 @@ sal_Int32 SAL_CALL CRC32::getValue()
 }
 /** Update CRC32 with specified sequence of bytes
  */
-void SAL_CALL CRC32::updateSegment(const Sequence< sal_Int8 > &b,
-                                   sal_Int32 off, sal_Int32 len)
+void SAL_CALL CRC32::updateSegment(const Sequence< sal_Int8 > &b, sal_Int32 len)
         throw(RuntimeException)
 {
-    nCRC = rtl_crc32(nCRC, b.getConstArray()+off, len );
+    nCRC = rtl_crc32(nCRC, b.getConstArray(), len );
 }
 /** Update CRC32 with specified sequence of bytes
  */
@@ -70,7 +69,7 @@ sal_Int64 SAL_CALL CRC32::updateStream( Reference < XInputStream > & xStream )
     do
     {
         nLength = xStream->readBytes ( aSeq, n_ConstBufferSize );
-        updateSegment ( aSeq, 0, nLength );
+        updateSegment ( aSeq, nLength );
         nTotal += nLength;
     }
     while ( nLength == n_ConstBufferSize );
diff --git a/package/source/zipapi/Deflater.cxx b/package/source/zipapi/Deflater.cxx
index 96d43fc..a19d181 100644
--- a/package/source/zipapi/Deflater.cxx
+++ b/package/source/zipapi/Deflater.cxx
@@ -126,13 +126,11 @@ sal_Int32 Deflater::doDeflateBytes (uno::Sequence < sal_Int8 > &rBuffer, sal_Int
     }
 }
 
-void SAL_CALL Deflater::setInputSegment( const uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
+void SAL_CALL Deflater::setInputSegment( const uno::Sequence< sal_Int8 >& rBuffer )
 {
-    OSL_ASSERT( !(nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength()));
-
     sInBuffer = rBuffer;
-    nOffset = nNewOffset;
-    nLength = nNewLength;
+    nOffset = 0;
+    nLength = rBuffer.getLength();
 }
 void SAL_CALL Deflater::setLevel( sal_Int32 nNewLevel )
 {
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
index 839a1c4..1fd536f 100644
--- a/package/source/zipapi/ZipFile.cxx
+++ b/package/source/zipapi/ZipFile.cxx
@@ -1073,7 +1073,7 @@ sal_Int32 ZipFile::getCRC( sal_Int64 nOffset, sal_Int64 nSize )
          ++ind)
     {
         sal_Int64 nLen = ::std::min(nBlockSize, nSize - ind * nBlockSize);
-        aCRC.updateSegment(aBuffer, 0, static_cast<sal_Int32>(nLen));
+        aCRC.updateSegment(aBuffer, static_cast<sal_Int32>(nLen));
     }
 
     return aCRC.getValue();
@@ -1102,7 +1102,7 @@ void ZipFile::getSizeAndCRC( sal_Int64 nOffset, sal_Int64 nCompressedSize, sal_I
         do
         {
             nLastInflated = aInflaterLocal.doInflateSegment( aData, 0, nBlockSize );
-            aCRC.updateSegment( aData, 0, nLastInflated );
+            aCRC.updateSegment( aData, nLastInflated );
             nInBlock += nLastInflated;
         } while( !aInflater.finished() && nLastInflated );
 
diff --git a/package/source/zipapi/ZipOutputEntry.cxx b/package/source/zipapi/ZipOutputEntry.cxx
index a5fbe25..54600d59 100644
--- a/package/source/zipapi/ZipOutputEntry.cxx
+++ b/package/source/zipapi/ZipOutputEntry.cxx
@@ -118,15 +118,15 @@ void ZipOutputEntry::closeEntry()
     }
 }
 
-void ZipOutputEntry::write( const Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
+void ZipOutputEntry::write( const Sequence< sal_Int8 >& rBuffer )
 {
     if (!m_aDeflater.finished())
     {
-        m_aDeflater.setInputSegment(rBuffer, nNewOffset, nNewLength);
+        m_aDeflater.setInputSegment(rBuffer);
          while (!m_aDeflater.needsInput())
             doDeflate();
         if (!m_bEncryptCurrentEntry)
-            m_aCRC.updateSegment(rBuffer, nNewOffset, nNewLength);
+            m_aCRC.updateSegment(rBuffer, rBuffer.getLength());
     }
 }
 
diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx
index c191b34..c91b351 100644
--- a/package/source/zipapi/ZipOutputStream.cxx
+++ b/package/source/zipapi/ZipOutputStream.cxx
@@ -71,10 +71,10 @@ void ZipOutputStream::addDeflatingThread( ZipOutputEntry *pEntry, osl::Thread *p
     pThread->create();
 }
 
-void ZipOutputStream::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int32 /*nNewOffset*/, sal_Int32 nNewLength )
+void ZipOutputStream::rawWrite( const Sequence< sal_Int8 >& rBuffer )
     throw(IOException, RuntimeException)
 {
-    m_aChucker.WriteBytes( Sequence< sal_Int8 >(rBuffer.getConstArray(), nNewLength) );
+    m_aChucker.WriteBytes( rBuffer );
 }
 
 void ZipOutputStream::rawCloseEntry( bool bEncrypt )
@@ -105,8 +105,7 @@ void ZipOutputStream::finish()
     for (size_t i = 0; i < m_aEntries.size(); i++)
     {
         writeLOC(m_aEntries[i]->getZipEntry(), m_aEntries[i]->isEncrypt());
-        uno::Sequence< sal_Int8 > aCompressedData = m_aEntries[i]->getData();
-        rawWrite(aCompressedData, 0, aCompressedData.getLength());
+        rawWrite(m_aEntries[i]->getData());
         rawCloseEntry(m_aEntries[i]->isEncrypt());
 
         m_aEntries[i]->getZipPackageStream()->successfullyWritten(m_aEntries[i]->getZipEntry());
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index bc69704..432fe54 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -970,7 +970,7 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut )
     ZipEntry * pEntry = new ZipEntry;
     sal_Int32 nBufferLength = m_pRootFolder->GetMediaType().getLength();
     OString sMediaType = OUStringToOString( m_pRootFolder->GetMediaType(), RTL_TEXTENCODING_ASCII_US );
-    uno::Sequence< sal_Int8 > aType( ( sal_Int8* )sMediaType.getStr(),
+    const uno::Sequence< sal_Int8 > aType( ( sal_Int8* )sMediaType.getStr(),
                                      nBufferLength );
 
     pEntry->sPath = sMime;
@@ -986,7 +986,7 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut )
     {
         ZipOutputStream::setEntry(pEntry);
         aZipOut.writeLOC(pEntry);
-        aZipOut.rawWrite(aType, 0, nBufferLength);
+        aZipOut.rawWrite(aType);
         aZipOut.rawCloseEntry();
     }
     catch ( const ::com::sun::star::io::IOException & r )
@@ -1030,10 +1030,9 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq
     ZipOutputStream::setEntry(pEntry);
     aZipOut.writeLOC(pEntry);
     ZipOutputEntry aZipEntry(m_xContext, *pEntry, NULL);
-    aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength);
+    aZipEntry.write(pBuffer->getSequence());
     aZipEntry.closeEntry();
-    uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData();
-    aZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength());
+    aZipOut.rawWrite(aZipEntry.getData());
     aZipOut.rawCloseEntry();
 }
 
@@ -1085,10 +1084,9 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno:
     ZipOutputStream::setEntry(pEntry);
     aZipOut.writeLOC(pEntry);
     ZipOutputEntry aZipEntry(m_xContext, *pEntry, NULL);
-    aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength);
+    aZipEntry.write(pBuffer->getSequence());
     aZipEntry.closeEntry();
-    uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData();
-    aZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength());
+    aZipOut.rawWrite(aZipEntry.getData());
     aZipOut.rawCloseEntry();
 }
 
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 94d18ea..396b052 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -447,7 +447,10 @@ static void deflateZipEntry(ZipOutputEntry *pZipEntry,
     do
     {
         nLength = xInStream->readBytes(aSeq, n_ConstBufferSize);
-        pZipEntry->write(aSeq, 0, nLength);
+        if (nLength != n_ConstBufferSize)
+            aSeq.realloc(nLength);
+
+        pZipEntry->write(aSeq);
     }
     while (nLength == n_ConstBufferSize);
     pZipEntry->closeEntry();
@@ -722,7 +725,10 @@ bool ZipPackageStream::saveChild(
             do
             {
                 nLength = xStream->readBytes( aSeq, n_ConstBufferSize );
-                rZipOut.rawWrite(aSeq, 0, nLength);
+                if (nLength != n_ConstBufferSize)
+                    aSeq.realloc(nLength);
+
+                rZipOut.rawWrite(aSeq);
             }
             while ( nLength == n_ConstBufferSize );
 
@@ -781,7 +787,10 @@ bool ZipPackageStream::saveChild(
                 do
                 {
                     nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
-                    rZipOut.rawWrite(aSeq, 0, nLength);
+                    if (nLength != n_ConstBufferSize)
+                        aSeq.realloc(nLength);
+
+                    rZipOut.rawWrite(aSeq);
                 }
                 while ( nLength == n_ConstBufferSize );
                 rZipOut.rawCloseEntry(bToBeEncrypted);
@@ -800,8 +809,7 @@ bool ZipPackageStream::saveChild(
                     rZipOut.writeLOC(pTempEntry, bToBeEncrypted);
                     ZipOutputEntry aZipEntry(m_xContext, *pTempEntry, this, bToBeEncrypted);
                     deflateZipEntry(&aZipEntry, xStream);
-                    uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData();
-                    rZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength());
+                    rZipOut.rawWrite(aZipEntry.getData());
                     rZipOut.rawCloseEntry(bToBeEncrypted);
                 }
             }
commit ff12196b07e599ff4b4ad4b21771bc781e642b84
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Mon Oct 27 19:05:07 2014 +0100

    Revert "HACK to avoid expensive and pointless deflating of jpeg files"
    
    This reverts commit 8c10cb5edc6902a96dc265d36faad0a8382b1a4a.

diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 774e8af..94d18ea 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -773,18 +773,8 @@ bool ZipPackageStream::saveChild(
             // the entry is provided to the ZipOutputStream that will delete it
             pAutoTempEntry.release();
 
-            if (pTempEntry->nMethod == STORED || rPath.endsWith(".jpeg"))
+            if (pTempEntry->nMethod == STORED)
             {
-                // Do not try to deflate jpeg files, pretend they are compressed already
-                // Unfortunately we don't know CRC value
-                if (rPath.endsWith(".jpeg"))
-                {
-                    uno::Reference< io::XSeekable > xSeek(xStream, uno::UNO_QUERY);
-                    pTempEntry->nSize = pTempEntry->nCompressedSize = xSeek->getLength();
-                    pTempEntry->nCrc = 0;
-                    pTempEntry->nMethod = STORED;
-                    pTempEntry->nFlag &= ~(pTempEntry->nFlag & 8);
-                }
                 sal_Int32 nLength;
                 uno::Sequence< sal_Int8 > aSeq(n_ConstBufferSize);
                 rZipOut.writeLOC(pTempEntry, bToBeEncrypted);


More information about the Libreoffice-commits mailing list