[Libreoffice-commits] core.git: unotools/source

Noel Grandin noelgrandin at gmail.com
Mon Apr 4 09:18:00 UTC 2016


 unotools/source/streaming/streamhelper.cxx |    5 +++--
 unotools/source/streaming/streamwrap.cxx   |    5 +++--
 unotools/source/ucbhelper/xtempfile.cxx    |    5 +++--
 3 files changed, 9 insertions(+), 6 deletions(-)

New commits:
commit f13e80b8a596ef3215a53cd39c9d0fac3e0375b7
Author: Noel Grandin <noelgrandin at gmail.com>
Date:   Sun Apr 3 17:36:42 2016 +0200

    reduce unnecessary reallocing
    
    Change-Id: I62368cf733ca6397099a843f3bbae3da08552798
    Reviewed-on: https://gerrit.libreoffice.org/23761
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/unotools/source/streaming/streamhelper.cxx b/unotools/source/streaming/streamhelper.cxx
index 40bc066..25137c6 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 05d3d93..7356fad 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 e0afe6b..5193dd8 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 )


More information about the Libreoffice-commits mailing list