diff options
author | Martin Gallwey <mtg@openoffice.org> | 2000-12-19 20:55:41 +0000 |
---|---|---|
committer | Martin Gallwey <mtg@openoffice.org> | 2000-12-19 20:55:41 +0000 |
commit | 9fc6242d12d2d11dcbb3b84ad0eab1ab4ed8ff8a (patch) | |
tree | 1203b760f561ccb5cec32a3b1afe00eb66b2d73a /package/source/zipapi/ZipOutputStream.cxx | |
parent | 5958a93ed29f582361889e8856a7417d519df445 (diff) |
many optimisations and memory leaks due to circular references fixed! An altogether amazing commit...tell your friends
Diffstat (limited to 'package/source/zipapi/ZipOutputStream.cxx')
-rw-r--r-- | package/source/zipapi/ZipOutputStream.cxx | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx index d167980fd..a41a42a3c 100644 --- a/package/source/zipapi/ZipOutputStream.cxx +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipOutputStream.cxx,v $ * - * $Revision: 1.16 $ + * $Revision: 1.17 $ * - * last change: $Author: mtg $ $Date: 2000-12-13 17:21:40 $ + * last change: $Author: mtg $ $Date: 2000-12-19 21:55:39 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -54,7 +54,7 @@ * * All Rights Reserved. * - * Contributor(s): _______________________________________ + * Contributor(s): Martin Gallwey (gallwey@sun.com) * * ************************************************************************/ @@ -265,12 +265,21 @@ void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) throw(io::IOException, uno::RuntimeException) { sal_Int16 i=0, nCommentLength = static_cast < sal_Int16 > (sComment.getLength()); + static uno::Sequence < sal_Int8 > aSequence (nCommentLength); + static sal_Int8 *pArray = aSequence.getArray(); + static sal_Int16 nOldLength = nCommentLength; + + if (nOldLength != nCommentLength) + { + nOldLength = nCommentLength; + aSequence.realloc (nOldLength); + pArray = aSequence.getArray(); + } const sal_Unicode *pChar = sComment.getStr(); - uno::Sequence < sal_Int8 > aSequence (nCommentLength); for ( ; i < nCommentLength; i++) { VOS_ENSURE (pChar[i] <127, "Non US ASCII character in zipfile comment!"); - aSequence[i] = static_cast < const sal_Int8 > (pChar[i]); + *(pArray+i) = static_cast < const sal_Int8 > (pChar[i]); } aChucker << ENDSIG; aChucker << static_cast < sal_Int16 > ( 0 ); @@ -290,6 +299,9 @@ void ZipOutputStream::writeCEN( const package::ZipEntry &rEntry ) nCommentLength = static_cast < sal_Int16 > ( rEntry.sComment.getLength() ) , nExtraLength = static_cast < sal_Int16 > ( rEntry.extra.getLength() ); sal_Int16 i = 0; + static uno::Sequence < sal_Int8 > aSequence (nNameLength); + static sal_Int8 *pArray = aSequence.getArray(); + static sal_Int16 nOldLength=0; aChucker << CENSIG; aChucker << rEntry.nVersion; @@ -316,11 +328,16 @@ void ZipOutputStream::writeCEN( const package::ZipEntry &rEntry ) aChucker.seek(nCurrent); */ const sal_Unicode *pChar = rEntry.sName.getStr(); - uno::Sequence < sal_Int8 > aSequence (nNameLength); + if (nOldLength != nNameLength) + { + nOldLength = nNameLength; + aSequence.realloc(nOldLength); + pArray = aSequence.getArray(); + } for ( ; i < nNameLength; i++) { VOS_ENSURE (pChar[i] <127, "Non US ASCII character in zipentry name!"); - aSequence[i] = static_cast < const sal_Int8 > (pChar[i]); + *(pArray+i) = static_cast < const sal_Int8 > (pChar[i]); } aChucker.writeBytes( aSequence ); @@ -328,11 +345,16 @@ void ZipOutputStream::writeCEN( const package::ZipEntry &rEntry ) aChucker.writeBytes( rEntry.extra); if (nCommentLength) { - aSequence.realloc (nCommentLength); + if (nOldLength != nCommentLength) + { + nOldLength = nCommentLength; + aSequence.realloc (nOldLength); + pArray = aSequence.getArray(); + } for (i=0, pChar = rEntry.sComment.getStr(); i < nCommentLength; i++) { VOS_ENSURE (pChar[i] <127, "Non US ASCII character in zipentry comment!"); - aSequence[i] = static_cast < const sal_Int8 > (pChar[i]); + *(pArray+i) = static_cast < const sal_Int8 > (pChar[i]); } aChucker.writeBytes( aSequence ); } @@ -350,6 +372,16 @@ void ZipOutputStream::writeLOC( const package::ZipEntry &rEntry ) throw(io::IOException, uno::RuntimeException) { sal_Int16 nNameLength = static_cast < sal_Int16 > (rEntry.sName.getLength()); + + static sal_Int16 nOldLength=nNameLength; + static uno::Sequence < sal_Int8 > aSequence(nNameLength); + static sal_Int8 *pArray = aSequence.getArray(); + if ( nNameLength != nOldLength) + { + nOldLength = nNameLength; + aSequence.realloc(nOldLength); + pArray = aSequence.getArray(); + } sal_Int16 i=0; aChucker << LOCSIG; aChucker << rEntry.nVersion; @@ -372,11 +404,10 @@ void ZipOutputStream::writeLOC( const package::ZipEntry &rEntry ) aChucker << static_cast <sal_Int16 > ( rEntry.extra.getLength()); const sal_Unicode *pChar = rEntry.sName.getStr(); - uno::Sequence < sal_Int8 > aSequence (nNameLength); for ( ; i < nNameLength; i++) { VOS_ENSURE (pChar[i] <127, "Non US ASCII character in zipentry name!"); - aSequence[i] = static_cast < const sal_Int8 > (pChar[i]); + *(pArray+i) = static_cast < const sal_Int8 > (pChar[i]); } aChucker.writeBytes( aSequence ); if (rEntry.extra.getLength() != 0) |