summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-04-09 14:35:12 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-04-10 08:43:18 +0200
commite8cb751f3bf816dc721115a5dc27da9eefaeb886 (patch)
tree9ca199ad26ebe7725c99fca4b94a7e42be865fe4
parent45e1b44247c6b8af449fbf078068939140bd9dbb (diff)
loplugin:useuniqueptr in DataStream
Change-Id: I05a22f05a7d41aa06539e05a1969f9520cc3ab31 Reviewed-on: https://gerrit.libreoffice.org/52649 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sc/source/ui/docshell/datastream.cxx50
-rw-r--r--sc/source/ui/inc/datastream.hxx2
2 files changed, 18 insertions, 34 deletions
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;