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

Noel Grandin noel.grandin at collabora.co.uk
Tue Apr 10 06:43:41 UTC 2018


 sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx |   21 +++----
 sc/source/ui/docshell/datastream.cxx                 |   50 ++++++-------------
 sc/source/ui/inc/AccessibleSpreadsheet.hxx           |    2 
 sc/source/ui/inc/datastream.hxx                      |    2 
 4 files changed, 29 insertions(+), 46 deletions(-)

New commits:
commit 3edfbb0885f8f9b18074d42e16539436077631ef
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Apr 9 14:35:41 2018 +0200

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

diff --git a/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx b/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx
index 09b7f6153865..380da8fc4505 100644
--- a/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx
+++ b/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx
@@ -269,7 +269,7 @@ ScAccessibleSpreadsheet::ScAccessibleSpreadsheet(
 
 ScAccessibleSpreadsheet::~ScAccessibleSpreadsheet()
 {
-    delete mpMarkedRanges;
+    mpMarkedRanges.reset();
     if (mpViewShell)
         mpViewShell->RemoveAccessibilityObject(*this);
 }
@@ -323,8 +323,7 @@ void ScAccessibleSpreadsheet::CompleteSelectionChanged(bool bNewState)
     {
         return ;
     }
-    if (mpMarkedRanges)
-        DELETEZ(mpMarkedRanges);
+    mpMarkedRanges.reset();
 
     AccessibleEventObject aEvent;
     aEvent.EventId = AccessibleEventId::STATE_CHANGED;
@@ -534,9 +533,9 @@ void ScAccessibleSpreadsheet::Notify( SfxBroadcaster& rBC, const SfxHint& rHint
                 }
                 if (!mpMarkedRanges)
                 {
-                    mpMarkedRanges = new ScRangeList();
+                    mpMarkedRanges.reset(new ScRangeList());
                 }
-                refScMarkData.FillRangeListWithMarks(mpMarkedRanges, true);
+                refScMarkData.FillRangeListWithMarks(mpMarkedRanges.get(), true);
 
                 //For Whole Col Row
                 bool bWholeRow = ::labs(aMarkRange.aStart.Row() - aMarkRange.aEnd.Row()) == MAXROW ;
@@ -615,7 +614,7 @@ void ScAccessibleSpreadsheet::Notify( SfxBroadcaster& rBC, const SfxHint& rHint
                             CommitFocusCell(aNewCell);
                         }
                         VEC_MYADDR vecNew;
-                        if(CalcScRangeListDifferenceMax(mpMarkedRanges,&m_LastMarkedRanges,10,vecNew))
+                        if(CalcScRangeListDifferenceMax(mpMarkedRanges.get(), &m_LastMarkedRanges,10,vecNew))
                         {
                             aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_WITHIN;
                             aEvent.NewValue.clear();
@@ -1113,9 +1112,9 @@ sal_Int32 SAL_CALL
         {
             if (!mpMarkedRanges)
             {
-                mpMarkedRanges = new ScRangeList();
+                mpMarkedRanges.reset(new ScRangeList());
                 ScMarkData aMarkData(mpViewShell->GetViewData().GetMarkData());
-                aMarkData.FillRangeListWithMarks(mpMarkedRanges, false);
+                aMarkData.FillRangeListWithMarks(mpMarkedRanges.get(), false);
             }
             // is possible, because there shouldn't be overlapped ranges in it
             if (mpMarkedRanges)
@@ -1144,8 +1143,8 @@ uno::Reference<XAccessible > SAL_CALL
     {
         if (!mpMarkedRanges)
         {
-            mpMarkedRanges = new ScRangeList();
-            mpViewShell->GetViewData().GetMarkData().FillRangeListWithMarks(mpMarkedRanges, false);
+            mpMarkedRanges.reset(new ScRangeList());
+            mpViewShell->GetViewData().GetMarkData().FillRangeListWithMarks(mpMarkedRanges.get(), false);
         }
         if (mpMarkedRanges)
         {
@@ -1154,7 +1153,7 @@ uno::Reference<XAccessible > SAL_CALL
             {
                 throw lang::IndexOutOfBoundsException();
             }
-            ScMyAddress addr = CalcScAddressFromRangeList(mpMarkedRanges,nSelectedChildIndex);
+            ScMyAddress addr = CalcScAddressFromRangeList(mpMarkedRanges.get(),nSelectedChildIndex);
             if( m_mapSelectionSend.find(addr) != m_mapSelectionSend.end() )
                 xAccessible = m_mapSelectionSend[addr];
             else
diff --git a/sc/source/ui/inc/AccessibleSpreadsheet.hxx b/sc/source/ui/inc/AccessibleSpreadsheet.hxx
index ade94b07a24b..613d749f3376 100644
--- a/sc/source/ui/inc/AccessibleSpreadsheet.hxx
+++ b/sc/source/ui/inc/AccessibleSpreadsheet.hxx
@@ -214,7 +214,7 @@ private:
     virtual tools::Rectangle GetBoundingBox() const override;
 
     ScTabViewShell* mpViewShell;
-    ScRangeList*    mpMarkedRanges;
+    std::unique_ptr<ScRangeList>  mpMarkedRanges;
     ScAccessibleDocument* mpAccDoc;
     rtl::Reference<ScAccessibleCell> mpAccCell;
     tools::Rectangle       maVisCells;
commit e8cb751f3bf816dc721115a5dc27da9eefaeb886
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Apr 9 14:35:12 2018 +0200

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

diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx
index eea81a1f41ae..08f882812d9e 100644
--- a/sc/source/ui/docshell/datastream.cxx
+++ b/sc/source/ui/docshell/datastream.cxx
@@ -93,24 +93,15 @@ public:
 
 namespace datastreams {
 
-void emptyLineQueue( std::queue<DataStream::LinesType*>& rQueue )
-{
-    while (!rQueue.empty())
-    {
-        delete rQueue.front();
-        rQueue.pop();
-    }
-}
-
 class ReaderThread : public salhelper::Thread
 {
-    SvStream *mpStream;
+    std::unique_ptr<SvStream> mpStream;
     size_t mnColCount;
     bool mbTerminate;
     osl::Mutex maMtxTerminate;
 
-    std::queue<DataStream::LinesType*> maPendingLines;
-    std::queue<DataStream::LinesType*> maUsedLines;
+    std::queue<std::unique_ptr<DataStream::LinesType>> maPendingLines;
+    std::queue<std::unique_ptr<DataStream::LinesType>> maUsedLines;
     osl::Mutex maMtxLines;
 
     osl::Condition maCondReadStream;
@@ -120,9 +111,9 @@ class ReaderThread : public salhelper::Thread
 
 public:
 
-    ReaderThread(SvStream *pData, size_t nColCount):
+    ReaderThread(std::unique_ptr<SvStream> pData, size_t nColCount):
         Thread("ReaderThread"),
-        mpStream(pData),
+        mpStream(std::move(pData)),
         mnColCount(nColCount),
         mbTerminate(false)
     {
@@ -130,13 +121,6 @@ public:
         maConfig.text_qualifier = '"';
     }
 
-    virtual ~ReaderThread() override
-    {
-        delete mpStream;
-        emptyLineQueue(maPendingLines);
-        emptyLineQueue(maUsedLines);
-    }
-
     bool isTerminateRequested()
     {
         osl::MutexGuard aGuard(maMtxTerminate);
@@ -161,9 +145,9 @@ public:
         maCondConsume.reset();
     }
 
-    DataStream::LinesType* popNewLines()
+    std::unique_ptr<DataStream::LinesType> popNewLines()
     {
-        DataStream::LinesType* pLines = maPendingLines.front();
+        auto pLines = std::move(maPendingLines.front());
         maPendingLines.pop();
         return pLines;
     }
@@ -179,9 +163,9 @@ public:
         return !maPendingLines.empty();
     }
 
-    void pushUsedLines( DataStream::LinesType* pLines )
+    void pushUsedLines( std::unique_ptr<DataStream::LinesType> pLines )
     {
-        maUsedLines.push(pLines);
+        maUsedLines.push(std::move(pLines));
     }
 
     osl::Mutex& getLinesMutex()
@@ -194,20 +178,20 @@ private:
     {
         while (!isTerminateRequested())
         {
-            DataStream::LinesType* pLines = nullptr;
+            std::unique_ptr<DataStream::LinesType> pLines;
             osl::ResettableMutexGuard aGuard(maMtxLines);
 
             if (!maUsedLines.empty())
             {
                 // Re-use lines from previous runs.
-                pLines = maUsedLines.front();
+                pLines = std::move(maUsedLines.front());
                 maUsedLines.pop();
                 aGuard.clear(); // unlock
             }
             else
             {
                 aGuard.clear(); // unlock
-                pLines = new DataStream::LinesType(10);
+                pLines.reset(new DataStream::LinesType(10));
             }
 
             // Read & store new lines from stream.
@@ -229,7 +213,7 @@ private:
                 maCondReadStream.reset();
                 aGuard.reset(); // lock
             }
-            maPendingLines.push(pLines);
+            maPendingLines.push(std::move(pLines));
             maCondConsume.set();
             if (!mpStream->good())
                 requestTerminate();
@@ -320,7 +304,7 @@ DataStream::~DataStream()
         mxReaderThread->endThread();
         mxReaderThread->join();
     }
-    delete mpLines;
+    mpLines.reset();
 }
 
 DataStream::Line DataStream::ConsumeLine()
@@ -333,7 +317,7 @@ DataStream::Line DataStream::ConsumeLine()
 
         osl::ResettableMutexGuard aGuard(mxReaderThread->getLinesMutex());
         if (mpLines)
-            mxReaderThread->pushUsedLines(mpLines);
+            mxReaderThread->pushUsedLines(std::move(mpLines));
 
         while (!mxReaderThread->hasNewLines())
         {
@@ -397,8 +381,8 @@ void DataStream::StartImport()
 
     if (!mxReaderThread.is())
     {
-        SvStream *pStream = new SvFileStream(msURL, StreamMode::READ);
-        mxReaderThread = new datastreams::ReaderThread(pStream, maStartRange.aEnd.Col() - maStartRange.aStart.Col() + 1);
+        std::unique_ptr<SvStream> pStream(new SvFileStream(msURL, StreamMode::READ));
+        mxReaderThread = new datastreams::ReaderThread(std::move(pStream), maStartRange.aEnd.Col() - maStartRange.aStart.Col() + 1);
         mxReaderThread->launch();
     }
     mbRunning = true;
diff --git a/sc/source/ui/inc/datastream.hxx b/sc/source/ui/inc/datastream.hxx
index b60de3fb852e..d71ddce79855 100644
--- a/sc/source/ui/inc/datastream.hxx
+++ b/sc/source/ui/inc/datastream.hxx
@@ -111,7 +111,7 @@ private:
     bool mbRunning;
     bool mbValuesInLine;
     bool mbRefreshOnEmptyLine;
-    LinesType* mpLines;
+    std::unique_ptr<LinesType> mpLines;
     size_t mnLinesCount;
     size_t mnLinesSinceRefresh;
     double mfLastRefreshTime;


More information about the Libreoffice-commits mailing list