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

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Fri Sep 10 04:23:46 UTC 2021


 connectivity/source/drivers/firebird/Blob.cxx |   12 ++++++------
 connectivity/source/drivers/firebird/Blob.hxx |    4 +++-
 connectivity/source/drivers/firebird/Clob.cxx |   17 +++++------------
 3 files changed, 14 insertions(+), 19 deletions(-)

New commits:
commit 627e8ac6313330eae892195a62d07db5b7d85a1b
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Fri Sep 10 00:53:58 2021 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri Sep 10 06:23:13 2021 +0200

    Use std::vector instead of css::uno::Sequence
    
    This allows to avoid multiple reallocations during successive reads
    
    Change-Id: I74102d21c5dc4d1e92e27ede3490e9ed07bd568e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121873
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/connectivity/source/drivers/firebird/Blob.cxx b/connectivity/source/drivers/firebird/Blob.cxx
index edcc0d233989..33ab36b8d33e 100644
--- a/connectivity/source/drivers/firebird/Blob.cxx
+++ b/connectivity/source/drivers/firebird/Blob.cxx
@@ -122,22 +122,22 @@ sal_uInt16 Blob::getMaximumSegmentSize()
     return m_nMaxSegmentSize;
 }
 
-bool Blob::readOneSegment(uno::Sequence< sal_Int8 >& rDataOut)
+bool Blob::readOneSegment(std::vector<char>& rDataOut)
 {
     checkDisposed(Blob_BASE::rBHelper.bDisposed);
     ensureBlobIsOpened();
 
     sal_uInt16 nMaxSize = getMaximumSegmentSize();
 
-    if(rDataOut.getLength() < nMaxSize)
-        rDataOut.realloc(nMaxSize);
+    if(rDataOut.size() < nMaxSize)
+        rDataOut.resize(nMaxSize);
 
     sal_uInt16 nActualSize = 0;
     ISC_STATUS aRet = isc_get_segment(m_statusVector,
             &m_blobHandle,
             &nActualSize,
             nMaxSize,
-            reinterpret_cast<char*>(rDataOut.getArray()) );
+            rDataOut.data() );
 
     if (aRet && aRet != isc_segstr_eof && IndicatesError(m_statusVector))
     {
@@ -145,8 +145,8 @@ bool Blob::readOneSegment(uno::Sequence< sal_Int8 >& rDataOut)
         throw IOException(sError, *this);
     }
 
-    if (rDataOut.getLength() > nActualSize)
-        rDataOut.realloc(nActualSize);
+    if (rDataOut.size() > nActualSize)
+        rDataOut.resize(nActualSize);
     m_nBlobPosition += nActualSize;
     return aRet == isc_segstr_eof;  // last segment read
 }
diff --git a/connectivity/source/drivers/firebird/Blob.hxx b/connectivity/source/drivers/firebird/Blob.hxx
index 322649762c71..990108934bf2 100644
--- a/connectivity/source/drivers/firebird/Blob.hxx
+++ b/connectivity/source/drivers/firebird/Blob.hxx
@@ -16,6 +16,8 @@
 #include <com/sun/star/io/XInputStream.hpp>
 #include <com/sun/star/sdbc/XBlob.hpp>
 
+#include <vector>
+
 namespace connectivity::firebird
     {
         typedef ::cppu::WeakComponentImplHelper< css::sdbc::XBlob,
@@ -59,7 +61,7 @@ namespace connectivity::firebird
                  isc_tr_handle* pTransactionHandle,
                  ISC_QUAD const & aBlobID);
 
-            bool readOneSegment(css::uno::Sequence< sal_Int8 >& rDataOut);
+            bool readOneSegment(std::vector<char>& rDataOut);
 
             // ---- XBlob ----------------------------------------------------
             virtual sal_Int64 SAL_CALL
diff --git a/connectivity/source/drivers/firebird/Clob.cxx b/connectivity/source/drivers/firebird/Clob.cxx
index 3ed83a9b19d2..47e3e9dc9b3b 100644
--- a/connectivity/source/drivers/firebird/Clob.cxx
+++ b/connectivity/source/drivers/firebird/Clob.cxx
@@ -54,13 +54,11 @@ sal_Int64 SAL_CALL Clob::length()
     // Read each segment, and calculate it's size by interpreting it as a
     // character stream. Assume that no characters are split by the segments.
     bool bLastSegmRead = false;
+    std::vector<char> aSegmentBytes;
     do
     {
-        uno::Sequence < sal_Int8 > aSegmentBytes;
         bLastSegmRead = m_aBlob->readOneSegment( aSegmentBytes );
-        OUString sSegment ( reinterpret_cast< const char *>( aSegmentBytes.getConstArray() ),
-                            aSegmentBytes.getLength(),
-                            RTL_TEXTENCODING_UTF8 );
+        OUString sSegment(aSegmentBytes.data(), aSegmentBytes.size(), RTL_TEXTENCODING_UTF8);
 
         if( !bLastSegmRead)
             m_nCharCount += sSegment.getLength();
@@ -81,18 +79,16 @@ OUString SAL_CALL Clob::getSubString(sal_Int64 nPosition,
     OUStringBuffer sSegmentBuffer;
     sal_Int64 nActPos = 1;
     sal_Int32 nActLen = 0;
+    std::vector<char> aSegmentBytes;
 
     // skip irrelevant parts
     while( nActPos < nPosition )
     {
-        uno::Sequence < sal_Int8 > aSegmentBytes;
         bool bLastRead = m_aBlob->readOneSegment( aSegmentBytes );
         if( bLastRead )
             throw lang::IllegalArgumentException("nPosition out of range", *this, 0);
 
-        OUString sSegment ( reinterpret_cast< const char *>( aSegmentBytes.getConstArray() ),
-                            aSegmentBytes.getLength(),
-                            RTL_TEXTENCODING_UTF8 );
+        OUString sSegment(aSegmentBytes.data(), aSegmentBytes.size(), RTL_TEXTENCODING_UTF8);
         sal_Int32 nStrLen = sSegment.getLength();
         nActPos += nStrLen;
         if( nActPos > nPosition )
@@ -109,12 +105,9 @@ OUString SAL_CALL Clob::getSubString(sal_Int64 nPosition,
     // read nLength characters
     while( nActLen < nLength )
     {
-        uno::Sequence < sal_Int8 > aSegmentBytes;
         bool bLastRead = m_aBlob->readOneSegment( aSegmentBytes );
 
-        OUString sSegment ( reinterpret_cast< const char *>( aSegmentBytes.getConstArray() ),
-                            aSegmentBytes.getLength(),
-                            RTL_TEXTENCODING_UTF8 );
+        OUString sSegment(aSegmentBytes.data(), aSegmentBytes.size(), RTL_TEXTENCODING_UTF8);
         sal_Int32 nStrLen = sSegment.getLength();
         if( nActLen + nStrLen > nLength )
             sSegmentBuffer.append(sSegment.subView(0, nLength - nActLen));


More information about the Libreoffice-commits mailing list