From e7ddd307d90225f9543f45881e9ed50bfd308de3 Mon Sep 17 00:00:00 2001 From: abarton <Adam.Edward.Barton@cern.ch> Date: Sun, 16 Aug 2020 17:34:39 +0100 Subject: [PATCH] Class trait optimization --- .../CaloConditions/CaloBadChannel.h | 9 +-- .../CaloConditions/CaloLocalHadCoeff.h | 23 ++++-- .../CaloConditions/src/CaloLocalHadCoeff.cxx | 76 +------------------ .../DetDescrConditions/DetStatus.h | 6 +- .../RegSelLUT/RegSelLUT/RegSelRoI.h | 2 +- 5 files changed, 24 insertions(+), 92 deletions(-) diff --git a/Calorimeter/CaloConditions/CaloConditions/CaloBadChannel.h b/Calorimeter/CaloConditions/CaloConditions/CaloBadChannel.h index 07d639d1239..130c0664afe 100644 --- a/Calorimeter/CaloConditions/CaloConditions/CaloBadChannel.h +++ b/Calorimeter/CaloConditions/CaloConditions/CaloBadChannel.h @@ -16,14 +16,9 @@ class CaloBadChannel { CaloBadChannel( BitWord rawStatus) : m_word(rawStatus) {} CaloBadChannel() : m_word(0) {} - CaloBadChannel(const CaloBadChannel& rBad) {m_word=rBad.m_word;} + CaloBadChannel(const CaloBadChannel& rBad) = default; CaloBadChannel(const CaloBadChannel* pBad) {m_word=pBad->m_word;} - CaloBadChannel& operator= (const CaloBadChannel& rBad) { - if (this != &rBad) { - m_word = rBad.m_word; - } - return *this; - } + CaloBadChannel& operator= (const CaloBadChannel& rBad) = default; bool statusOK( ProblemType pb) const { BitWord mask = 1 << (PosType) pb; diff --git a/Calorimeter/CaloConditions/CaloConditions/CaloLocalHadCoeff.h b/Calorimeter/CaloConditions/CaloConditions/CaloLocalHadCoeff.h index 9ebc8e53b6d..4ee43eaa910 100644 --- a/Calorimeter/CaloConditions/CaloConditions/CaloLocalHadCoeff.h +++ b/Calorimeter/CaloConditions/CaloConditions/CaloLocalHadCoeff.h @@ -82,9 +82,13 @@ class CaloLocalHadCoeff { /** * @brief Copy constructor */ - LocalHadDimension(const LocalHadDimension &other); - LocalHadDimension& operator= (const LocalHadDimension &other); - + LocalHadDimension(const LocalHadDimension &other) = default; + LocalHadDimension& operator= (const LocalHadDimension &other) = default; + /** + * @brief Move constructor + */ + LocalHadDimension( LocalHadDimension &&) noexcept = default; + LocalHadDimension& operator= ( LocalHadDimension &&) noexcept = default; // access methods /// return dimension type @@ -157,8 +161,10 @@ class CaloLocalHadCoeff { /** * @brief Copy constructor */ - LocalHadArea(const LocalHadArea &other); - LocalHadArea& operator= (const LocalHadArea &other); + LocalHadArea(const LocalHadArea &other) = default; + LocalHadArea& operator= (const LocalHadArea &other) = default; + LocalHadArea( LocalHadArea &&other) noexcept = default; + LocalHadArea& operator= ( LocalHadArea &&other) noexcept = default; /// return area type inline unsigned int getType() const { return m_type; } @@ -220,8 +226,11 @@ class CaloLocalHadCoeff { /** * @brief Copy constructor. */ - CaloLocalHadCoeff(const CaloLocalHadCoeff &other); - CaloLocalHadCoeff& operator= (const CaloLocalHadCoeff &other); + CaloLocalHadCoeff(const CaloLocalHadCoeff &other) = default; + CaloLocalHadCoeff& operator= (const CaloLocalHadCoeff &other) = default; + //Move operators + CaloLocalHadCoeff(CaloLocalHadCoeff &&) noexcept = default; + CaloLocalHadCoeff& operator= (CaloLocalHadCoeff &&) noexcept = default; // // general access methods diff --git a/Calorimeter/CaloConditions/src/CaloLocalHadCoeff.cxx b/Calorimeter/CaloConditions/src/CaloLocalHadCoeff.cxx index 7b855389c18..79982946416 100644 --- a/Calorimeter/CaloConditions/src/CaloLocalHadCoeff.cxx +++ b/Calorimeter/CaloConditions/src/CaloLocalHadCoeff.cxx @@ -21,32 +21,6 @@ LocalHadDimension -> *************************************************************************** */ -// copy constructor -CaloLocalHadCoeff::LocalHadDimension::LocalHadDimension(const CaloLocalHadCoeff::LocalHadDimension &other) - : m_title (other.m_title), - m_type (other.m_type), - m_nbins (other.m_nbins), - m_xmin (other.m_xmin), - m_xmax (other.m_xmax), - m_dx (other.m_dx), - m_xbins (other.m_xbins) -{ -} - -CaloLocalHadCoeff::LocalHadDimension& -CaloLocalHadCoeff::LocalHadDimension::operator= (const CaloLocalHadCoeff::LocalHadDimension &other) -{ - if (this != &other) { - m_title = other.m_title; - m_type = other.m_type; - m_nbins = other.m_nbins; - m_xmin = other.m_xmin; - m_xmax = other.m_xmax; - m_dx = other.m_dx; - m_xbins = other.m_xbins; - } - return *this; -} // return bin number for cluster variable int CaloLocalHadCoeff::LocalHadDimension::getBin(float &x) const @@ -157,32 +131,6 @@ bool CaloLocalHadCoeff::isFilled(const int bin) const /* *************************************************************************** LocalHadArea -> *************************************************************************** */ -// copy constructor -CaloLocalHadCoeff::LocalHadArea::LocalHadArea(const CaloLocalHadCoeff::LocalHadArea &other) - : m_title (other.m_title), - m_type (other.m_type), - m_npars (other.m_npars), - m_offset (other.m_offset), - m_length (other.m_length), - m_dims (other.m_dims), - m_dims_loc (other.m_dims_loc) -{ -} - -CaloLocalHadCoeff::LocalHadArea& -CaloLocalHadCoeff::LocalHadArea::operator=(const CaloLocalHadCoeff::LocalHadArea &other) -{ - if (this != &other) { - m_title = other.m_title; - m_type = other.m_type; - m_npars = other.m_npars; - m_offset = other.m_offset; - m_length = other.m_length; - m_dims = other.m_dims; - m_dims_loc = other.m_dims_loc; - } - return *this; -} // add new dimension to the area void CaloLocalHadCoeff::LocalHadArea::addDimension(CaloLocalHadCoeff::LocalHadDimension &dim) @@ -214,27 +162,9 @@ CaloLocalHadCoeff // default constructor CaloLocalHadCoeff::CaloLocalHadCoeff() { - -} - -// copy constructor -CaloLocalHadCoeff::CaloLocalHadCoeff(const CaloLocalHadCoeff &other) - : m_title (other.m_title), - m_CoeffSet (other.m_CoeffSet), - m_AreaSet (other.m_AreaSet) -{ -} - - - -CaloLocalHadCoeff& CaloLocalHadCoeff::operator=(const CaloLocalHadCoeff &other) -{ - if (this != &other) { - m_AreaSet = other.m_AreaSet; - m_CoeffSet = other.m_CoeffSet; - m_title = other.m_title; - } - return *this; + static_assert(std::is_nothrow_move_constructible<CaloLocalHadCoeff>::value); + static_assert(std::is_nothrow_move_constructible<LocalHadArea>::value); + static_assert(std::is_nothrow_move_constructible<LocalHadDimension>::value); } diff --git a/DetectorDescription/DetDescrCond/DetDescrConditions/DetDescrConditions/DetStatus.h b/DetectorDescription/DetDescrCond/DetDescrConditions/DetDescrConditions/DetStatus.h index dc690b6f0e4..412fb1d7a14 100755 --- a/DetectorDescription/DetDescrCond/DetDescrConditions/DetDescrConditions/DetStatus.h +++ b/DetectorDescription/DetDescrCond/DetDescrConditions/DetDescrConditions/DetStatus.h @@ -9,14 +9,14 @@ #include<string> -class DetStatus { +class DetStatus final { public: DetStatus(); // constructor with parameters DetStatus(const int fullcode, const float deadfrac, const float deadthrust); - virtual ~DetStatus(); + ~DetStatus() = default; // access functions int code() const; @@ -31,8 +31,6 @@ class DetStatus { float m_deadthrust; }; -inline DetStatus::~DetStatus() {} - inline int DetStatus::code() const { return m_code<0 ? m_code : m_code & 3; } inline int DetStatus::fullCode() const { return m_code; } inline float DetStatus::deadFrac() const { return m_deadfrac;} diff --git a/DetectorDescription/RegSelLUT/RegSelLUT/RegSelRoI.h b/DetectorDescription/RegSelLUT/RegSelLUT/RegSelRoI.h index de67d3f6772..b454784d6eb 100644 --- a/DetectorDescription/RegSelLUT/RegSelLUT/RegSelRoI.h +++ b/DetectorDescription/RegSelLUT/RegSelLUT/RegSelRoI.h @@ -39,7 +39,7 @@ public: double phiMin, double phiMax, double etaMin, double etaMax); - ~RegSelRoI() { } + ~RegSelRoI() = default; double getzMin() const { return m_zMin; } double getzMax() const { return m_zMax; } -- GitLab