summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2016-04-03 17:36:42 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-04-04 09:17:35 +0000
commitf13e80b8a596ef3215a53cd39c9d0fac3e0375b7 (patch)
treeee27db439fce884136d4b8817e27e2b73a11f1da /unotools
parent21eef3b4b0e7a1a1b1b3ce8a63eb6352f5eb6e62 (diff)
reduce unnecessary reallocing
Change-Id: I62368cf733ca6397099a843f3bbae3da08552798 Reviewed-on: https://gerrit.libreoffice.org/23761 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/streaming/streamhelper.cxx5
-rw-r--r--unotools/source/streaming/streamwrap.cxx5
-rw-r--r--unotools/source/ucbhelper/xtempfile.cxx5
3 files changed, 9 insertions, 6 deletions
diff --git a/unotools/source/streaming/streamhelper.cxx b/unotools/source/streaming/streamhelper.cxx
index 40bc0664f73b..25137c66081f 100644
--- a/unotools/source/streaming/streamhelper.cxx
+++ b/unotools/source/streaming/streamhelper.cxx
@@ -42,7 +42,8 @@ sal_Int32 SAL_CALL OInputStreamHelper::readBytes(css::uno::Sequence< sal_Int8 >&
throw css::io::BufferSizeExceededException(OUString(), static_cast<css::uno::XWeak*>(this));
::osl::MutexGuard aGuard( m_aMutex );
- aData.realloc(nBytesToRead);
+ if (aData.getLength() < nBytesToRead)
+ aData.realloc(nBytesToRead);
sal_Size nRead(0);
ErrCode nError = m_xLockBytes->ReadAt(m_nActPos, static_cast<void*>(aData.getArray()), nBytesToRead, &nRead);
@@ -52,7 +53,7 @@ sal_Int32 SAL_CALL OInputStreamHelper::readBytes(css::uno::Sequence< sal_Int8 >&
throw css::io::IOException(OUString(), static_cast<css::uno::XWeak*>(this));
// adjust sequence if data read is lower than the desired data
- if (nRead < (sal_uInt32)nBytesToRead)
+ if (nRead < (sal_Size)aData.getLength())
aData.realloc( nRead );
return nRead;
diff --git a/unotools/source/streaming/streamwrap.cxx b/unotools/source/streaming/streamwrap.cxx
index 05d3d93daec8..7356fad4c863 100644
--- a/unotools/source/streaming/streamwrap.cxx
+++ b/unotools/source/streaming/streamwrap.cxx
@@ -55,13 +55,14 @@ sal_Int32 SAL_CALL OInputStreamWrapper::readBytes(css::uno::Sequence< sal_Int8 >
::osl::MutexGuard aGuard( m_aMutex );
- aData.realloc(nBytesToRead);
+ if (aData.getLength() < nBytesToRead)
+ aData.realloc(nBytesToRead);
sal_uInt32 nRead = m_pSvStream->Read(static_cast<void*>(aData.getArray()), nBytesToRead);
checkError();
// Wenn gelesene Zeichen < MaxLength, css::uno::Sequence anpassen
- if (nRead < (sal_uInt32)nBytesToRead)
+ if (nRead < (sal_Size)aData.getLength())
aData.realloc( nRead );
return nRead;
diff --git a/unotools/source/ucbhelper/xtempfile.cxx b/unotools/source/ucbhelper/xtempfile.cxx
index e0afe6b107e5..5193dd814819 100644
--- a/unotools/source/ucbhelper/xtempfile.cxx
+++ b/unotools/source/ucbhelper/xtempfile.cxx
@@ -162,12 +162,13 @@ throw (css::io::NotConnectedException, css::io::BufferSizeExceededException, css
if (nBytesToRead < 0)
throw css::io::BufferSizeExceededException( OUString(), static_cast< css::uno::XWeak * >(this));
- aData.realloc(nBytesToRead);
+ if (aData.getLength() < nBytesToRead)
+ aData.realloc(nBytesToRead);
sal_uInt32 nRead = mpStream->Read(static_cast < void* > ( aData.getArray() ), nBytesToRead);
checkError();
- if (nRead < static_cast < sal_uInt32 > ( nBytesToRead ) )
+ if (nRead < (sal_Size)aData.getLength())
aData.realloc( nRead );
if ( sal::static_int_cast<sal_uInt32>(nBytesToRead) > nRead )