Skip to content
Snippets Groups Projects
Commit 2660ff38 authored by Gerhard Raven's avatar Gerhard Raven
Browse files

Avoid heap-allocation of ParticleDataTable

- prefer `optional` over `unique_ptr` to create a 'nullable' object
  avoiding the explicit heap allocation for ParticleDataTable
parent 8d59d401
No related branches found
No related tags found
1 merge request!490Avoid heap-allocation of ParticleDataTable
......@@ -136,7 +136,7 @@ StatusCode PartPropSvc::createTable()
m_upid_local = true;
}
m_pdt.reset( new HepPDT::ParticleDataTable( m_upid_name, m_upid ) );
m_pdt.emplace( m_upid_name, m_upid );
HepPDT::TableBuilder tb( *m_pdt );
......@@ -166,11 +166,11 @@ HepPDT::ParticleDataTable* PartPropSvc::PDT()
debug() << "creating ParticleDataTable" << endmsg;
if ( createTable().isFailure() ) {
fatal() << "Could not create ParticleDataTable" << endmsg;
m_pdt.reset( nullptr );
m_pdt.reset();
}
}
return m_pdt.get();
return m_pdt.get_ptr();
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
......
......@@ -6,8 +6,9 @@
#include "HepPDT/ParticleDataTable.hh"
#include "HepPDT/TableBuilder.hh"
#include "boost/optional.hpp"
#include <iostream>
#include <memory>
#include <string>
#include <utility>
#include <vector>
......@@ -38,9 +39,6 @@ public:
void setUnknownParticleHandler( HepPDT::ProcessUnknownID*, const std::string& ) override;
// Destructor.
~PartPropSvc() override = default;
private:
using inputFunPtr = bool ( * )( std::istream&, HepPDT::TableBuilder& );
......@@ -52,7 +50,7 @@ private:
HepPDT::ProcessUnknownID* m_upid = nullptr;
std::string m_upid_name;
std::unique_ptr<HepPDT::ParticleDataTable> m_pdt;
boost::optional<HepPDT::ParticleDataTable> m_pdt;
inputFunPtr parseTableType( const std::string& );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment