reduce unnecessary reallocing

Change-Id: I01880cfecdab4addb358c74cbcdc02c98c0d6224
Reviewed-on: https://gerrit.libreoffice.org/23764
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
Noel Grandin
2016-04-03 18:02:42 +02:00
parent 06c6832e5a
commit a31840be01

View File

@@ -84,19 +84,20 @@ XInputStream_impl::readBytes(
if( ! m_bIsOpen )
throw io::IOException();
aData.realloc(nBytesToRead);
if (aData.getLength() < nBytesToRead)
aData.realloc(nBytesToRead);
//TODO! translate memory exhaustion (if it were detectable...) into
// io::BufferSizeExceededException
sal_uInt64 nrc;
m_aFile.read( aData.getArray(),sal_uInt64(nBytesToRead),nrc );
sal_uInt64 nBytesRead;
m_aFile.read( aData.getArray(), sal_uInt64(nBytesToRead), nBytesRead );
// Shrink aData in case we read less than nBytesToRead (XInputStream
// documentation does not tell whether this is required, and I do not know
// if any code relies on this, so be conservative---SB):
if (nrc != sal::static_int_cast<sal_uInt64>( nBytesToRead) )
aData.realloc(sal_Int32(nrc));
return ( sal_Int32 ) nrc;
if (nBytesRead != sal::static_int_cast<sal_uInt64>(nBytesToRead) )
aData.realloc(sal_Int32(nBytesRead));
return ( sal_Int32 ) nBytesRead;
}
sal_Int32 SAL_CALL