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

Noel Grandin noel.grandin at collabora.co.uk
Mon May 7 06:31:15 UTC 2018


 connectivity/source/drivers/dbase/DTable.cxx      |   19 +++++++++----------
 connectivity/source/drivers/file/FTable.cxx       |    9 +--------
 connectivity/source/drivers/mork/MQueryHelper.cxx |   21 +++++++--------------
 connectivity/source/drivers/mork/MQueryHelper.hxx |    4 ++--
 connectivity/source/inc/file/FTable.hxx           |    2 +-
 5 files changed, 20 insertions(+), 35 deletions(-)

New commits:
commit 0ce677434f5eb1ff388d0f33306b9dba9b5beaab
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu May 3 13:50:52 2018 +0200

    loplugin:useuniqueptr in MQueryHelper
    
    Change-Id: Ic76213b5bfa31310d8633ac7a8db7e4cc9020710
    Reviewed-on: https://gerrit.libreoffice.org/53864
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/connectivity/source/drivers/mork/MQueryHelper.cxx b/connectivity/source/drivers/mork/MQueryHelper.cxx
index ffa7a2082e9a..0c0027c13733 100644
--- a/connectivity/source/drivers/mork/MQueryHelper.cxx
+++ b/connectivity/source/drivers/mork/MQueryHelper.cxx
@@ -88,17 +88,14 @@ void MQueryHelper::setAddressbook(OUString const &ab)
     m_aAddressbook = ab;
 }
 
-void MQueryHelper::append(MQueryHelperResultEntry* resEnt)
+void MQueryHelper::append(std::unique_ptr<MQueryHelperResultEntry> resEnt)
 {
-    if ( resEnt != nullptr ) {
-        m_aResults.push_back( resEnt );
-    }
+   assert(resEnt);
+   m_aResults.push_back( std::move(resEnt) );
 }
 
 void MQueryHelper::clear_results()
 {
-    for (auto const& result : m_aResults)
-        delete result;
     m_aResults.clear();
 }
 
@@ -116,7 +113,7 @@ MQueryHelper::getByIndex(sal_uInt32 nRow)
     if ( nRow < 1 ) {
         return nullptr;
     }
-    return m_aResults[nRow -1];
+    return m_aResults[nRow -1].get();
 }
 
 sal_Int32 MQueryHelper::getResultCount() const
@@ -225,7 +222,7 @@ sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection, MQueryExpression
                     }
                 }
 
-                MQueryHelperResultEntry* entry = new MQueryHelperResultEntry();
+                std::unique_ptr<MQueryHelperResultEntry> entry(new MQueryHelperResultEntry());
                 for (auto const& cell : row.second)
                 {
                     std::string column = pMork->getColumn(cell.first);
@@ -236,17 +233,13 @@ sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection, MQueryExpression
                     entry->setValue(key, valueOUString);
                 }
                 bool result = true;
-                for (auto const& elem : entryMatchedByExpression(this, &expr, entry))
+                for (auto const& elem : entryMatchedByExpression(this, &expr, entry.get()))
                 {
                     result = result && elem;
                 }
                 if (result)
                 {
-                    append(entry);
-                }
-                else
-                {
-                    delete entry;
+                    append(std::move(entry));
                 }
             }
         }
diff --git a/connectivity/source/drivers/mork/MQueryHelper.hxx b/connectivity/source/drivers/mork/MQueryHelper.hxx
index 75db029ae4a7..cc240d36b0f3 100644
--- a/connectivity/source/drivers/mork/MQueryHelper.hxx
+++ b/connectivity/source/drivers/mork/MQueryHelper.hxx
@@ -159,11 +159,11 @@ namespace connectivity
         class MQueryHelper final
         {
         private:
-            typedef std::vector< MQueryHelperResultEntry* > resultsArray;
+            typedef std::vector< std::unique_ptr<MQueryHelperResultEntry> > resultsArray;
 
             mutable ::osl::Mutex        m_aMutex;
             resultsArray        m_aResults;
-            void            append(MQueryHelperResultEntry* resEnt );
+            void            append(std::unique_ptr<MQueryHelperResultEntry> resEnt );
             void            clear_results();
             OColumnAlias        m_rColumnAlias;
             ErrorDescriptor     m_aError;
commit 7baed0c028df4b5215557e8410467277d068021b
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu May 3 13:48:14 2018 +0200

    loplugin:useuniqueptr in OFileTable
    
    Change-Id: I74f21220b71703a18d1ae85f5f50397355304153
    Reviewed-on: https://gerrit.libreoffice.org/53863
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx
index 87be422f133c..815d45ba4635 100644
--- a/connectivity/source/drivers/dbase/DTable.cxx
+++ b/connectivity/source/drivers/dbase/DTable.cxx
@@ -812,7 +812,7 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool
         if ( ( nByteOffset + nLen) > m_nBufferSize )
             break; // length doesn't match buffer size.
 
-        char *pData = reinterpret_cast<char *>(m_pBuffer + nByteOffset);
+        char *pData = reinterpret_cast<char *>(m_pBuffer.get() + nByteOffset);
 
         if (nType == DataType::CHAR || nType == DataType::VARCHAR)
         {
@@ -1458,7 +1458,7 @@ bool ODbaseTable::InsertRow(OValueRefVector& rRow, const Reference<XIndexAccess>
     if (!AllocBuffer())
         return false;
 
-    memset(m_pBuffer, 0, m_aHeader.recordLength);
+    memset(m_pBuffer.get(), 0, m_aHeader.recordLength);
     m_pBuffer[0] = ' ';
 
     // Copy new row completely:
@@ -1518,7 +1518,7 @@ bool ODbaseTable::UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow, const
     // position on desired record:
     std::size_t nPos = m_aHeader.headerLength + static_cast<long>(m_nFilePos-1) * m_aHeader.recordLength;
     m_pFileStream->Seek(nPos);
-    m_pFileStream->ReadBytes(m_pBuffer, m_aHeader.recordLength);
+    m_pFileStream->ReadBytes(m_pBuffer.get(), m_aHeader.recordLength);
 
     std::size_t nMemoFileSize( 0 );
     if (HasMemoFields() && m_pMemoStream)
@@ -1793,7 +1793,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo
                 pIndex->Insert(m_nFilePos, thisColVal);
         }
 
-        char* pData = reinterpret_cast<char *>(m_pBuffer + nByteOffset);
+        char* pData = reinterpret_cast<char *>(m_pBuffer.get() + nByteOffset);
         if (thisColIsNull)
         {
             if ( bSetZero )
@@ -2591,7 +2591,7 @@ bool ODbaseTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32
         if (m_pFileStream->GetError() != ERRCODE_NONE)
             goto Error;
 
-        std::size_t nRead = m_pFileStream->ReadBytes(m_pBuffer, nEntryLen);
+        std::size_t nRead = m_pFileStream->ReadBytes(m_pBuffer.get(), nEntryLen);
         if (nRead != nEntryLen)
         {
             SAL_WARN("connectivity.drivers", "ODbaseTable::seekRow: short read!");
@@ -2710,15 +2710,14 @@ bool ODbaseTable::AllocBuffer()
 
     if (m_nBufferSize != nSize)
     {
-        delete m_pBuffer;
-        m_pBuffer = nullptr;
+        m_pBuffer.reset();
     }
 
     // if there is no buffer available: allocate:
-    if (m_pBuffer == nullptr && nSize > 0)
+    if (!m_pBuffer && nSize > 0)
     {
         m_nBufferSize = nSize;
-        m_pBuffer = new sal_uInt8[m_nBufferSize+1];
+        m_pBuffer.reset(new sal_uInt8[m_nBufferSize+1]);
     }
 
     return m_pBuffer != nullptr;
@@ -2731,7 +2730,7 @@ bool ODbaseTable::WriteBuffer()
     // position on desired record:
     std::size_t nPos = m_aHeader.headerLength + static_cast<long>(m_nFilePos-1) * m_aHeader.recordLength;
     m_pFileStream->Seek(nPos);
-    return m_pFileStream->WriteBytes(m_pBuffer, m_aHeader.recordLength) > 0;
+    return m_pFileStream->WriteBytes(m_pBuffer.get(), m_aHeader.recordLength) > 0;
 }
 
 sal_Int32 ODbaseTable::getCurrentLastPos() const
diff --git a/connectivity/source/drivers/file/FTable.cxx b/connectivity/source/drivers/file/FTable.cxx
index 6358874f93f7..e583e20db9af 100644
--- a/connectivity/source/drivers/file/FTable.cxx
+++ b/connectivity/source/drivers/file/FTable.cxx
@@ -40,7 +40,6 @@ OFileTable::OFileTable(sdbcx::OCollection* _pTables,OConnection* _pConnection)
                 ,m_pConnection(_pConnection)
                 ,m_pFileStream(nullptr)
                 ,m_nFilePos(0)
-                ,m_pBuffer(nullptr)
                 ,m_nBufferSize(0)
                 ,m_bWriteable(false)
 {
@@ -63,7 +62,6 @@ OFileTable::OFileTable( sdbcx::OCollection* _pTables,OConnection* _pConnection,
     , m_pConnection(_pConnection)
     , m_pFileStream(nullptr)
     , m_nFilePos(0)
-    , m_pBuffer(nullptr)
     , m_nBufferSize(0)
     , m_bWriteable(false)
 {
@@ -156,12 +154,7 @@ void OFileTable::FileClose()
         m_pFileStream->Flush();
 
     m_pFileStream.reset();
-
-    if (m_pBuffer)
-    {
-        delete[] m_pBuffer;
-        m_pBuffer = nullptr;
-    }
+    m_pBuffer.reset();
 }
 
 bool OFileTable::InsertRow(OValueRefVector& /*rRow*/, const css::uno::Reference< css::container::XIndexAccess>& /*_xCols*/)
diff --git a/connectivity/source/inc/file/FTable.hxx b/connectivity/source/inc/file/FTable.hxx
index 3495c79c24c9..bd12eca69eee 100644
--- a/connectivity/source/inc/file/FTable.hxx
+++ b/connectivity/source/inc/file/FTable.hxx
@@ -42,7 +42,7 @@ namespace connectivity
             std::unique_ptr<SvStream>                           m_pFileStream;
             ::rtl::Reference<OSQLColumns>                           m_aColumns;
             sal_Int32                                           m_nFilePos;                 // current IResultSetHelper::Movement
-            sal_uInt8*                                          m_pBuffer;
+            std::unique_ptr<sal_uInt8[]>                        m_pBuffer;
             sal_uInt16                                          m_nBufferSize;  // size of the ReadBuffer, if pBuffer != NULL
             bool                                            m_bWriteable;   // svstream can't say if we are writeable
                                                                                 // so we have to


More information about the Libreoffice-commits mailing list