Commit f05e1455 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #19522 Add cleaner implementation

This removes the memory leak and adds a move method to PeaksWorkspace
parent 6f6c5afe
......@@ -15,6 +15,7 @@
#include "MantidDataObjects/PeakShapeEllipsoidFactory.h"
#include "MantidDataObjects/PeakShapeSphericalFactory.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidDataObjects/Peak.h"
#include "MantidDataObjects/RebinnedOutput.h"
#include "MantidGeometry/Instrument/Goniometer.h"
#include "MantidKernel/ArrayProperty.h"
......@@ -1068,12 +1069,12 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
// below this one) is set before QLabFrame as this causes Peak to ray trace
// to find the location of the detector, which significantly increases
// loading times.
Geometry::IPeak *peak = new Peak();
const auto goniometer = peakWS->run().getGoniometer();
peak->setInstrument(peakWS->getInstrument());
peak->setGoniometerMatrix(goniometer.getR());
peak->setRunNumber(peakWS->getRunNumber());
peakWS->addPeak(*peak);
Peak peak;
peak.setInstrument(peakWS->getInstrument());
peak.setGoniometerMatrix(goniometer.getR());
peak.setRunNumber(peakWS->getRunNumber());
peakWS->addPeak(std::move(peak));
}
for (const auto &str : columnNames) {
......
......@@ -94,6 +94,8 @@ public:
std::string getConvention() const override;
void removePeak(int peakNum) override;
void addPeak(const Geometry::IPeak &ipeak) override;
/// Move a peak object into this peaks workspace
void addPeak(Peak &&ipeak);
Peak &getPeak(int peakNum) override;
const Peak &getPeak(int peakNum) const override;
......
......@@ -161,6 +161,14 @@ void PeaksWorkspace::addPeak(const Geometry::IPeak &ipeak) {
}
}
//---------------------------------------------------------------------------------------------
/** Add a peak to the list
* @param ipeak :: Peak object to add (move) into this.
*/
void PeaksWorkspace::addPeak(Peak &&ipeak) {
peaks.push_back(ipeak);
}
//---------------------------------------------------------------------------------------------
/** Return a reference to the Peak
* @param peakNum :: index of the peak to get.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment