From 5fc954e4a39c050995569541461800339bc92bfb Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Fri, 27 Dec 2024 13:50:14 -0600 Subject: [PATCH] PERF: Prefer default initialization for std::string Return {} may be the fastest, because it just calls the default-constructor of std::string. (return { "" } and return "" may be slightly slower because they convert a literal string to an std::string. This probably does not have a substantive impact on the current uses, but implementing to keep the style consistent. --- Modules/Core/Common/src/itkBuildInformation.cxx.in | 4 ++-- .../SpatialObjects/include/itkDTITubeSpatialObjectPoint.hxx | 2 +- .../src/itkPolygonGroupSpatialObjectXMLFile.cxx | 2 +- Modules/Numerics/Optimizers/src/itkLBFGSOptimizer.cxx | 2 +- Modules/Numerics/Optimizersv4/src/itkLBFGSOptimizerv4Base.cxx | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/Core/Common/src/itkBuildInformation.cxx.in b/Modules/Core/Common/src/itkBuildInformation.cxx.in index ad4cf9026df..6e70541cd56 100644 --- a/Modules/Core/Common/src/itkBuildInformation.cxx.in +++ b/Modules/Core/Common/src/itkBuildInformation.cxx.in @@ -87,7 +87,7 @@ BuildInformation::GetValue(const MapKeyType & key) { return it->second.m_Value; } - return {""}; + return {};; } const BuildInformation::MapValueDescriptionType @@ -100,7 +100,7 @@ BuildInformation::GetDescription(const MapKeyType & key) { return it->second.m_Description; } - return {""}; + return {};; } const std::vector< BuildInformation::MapKeyType > diff --git a/Modules/Core/SpatialObjects/include/itkDTITubeSpatialObjectPoint.hxx b/Modules/Core/SpatialObjects/include/itkDTITubeSpatialObjectPoint.hxx index 60275eca396..22a5e2ce9f3 100644 --- a/Modules/Core/SpatialObjects/include/itkDTITubeSpatialObjectPoint.hxx +++ b/Modules/Core/SpatialObjects/include/itkDTITubeSpatialObjectPoint.hxx @@ -64,7 +64,7 @@ DTITubeSpatialObjectPoint::TranslateEnumToChar(DTITubeSpatialOb // Just fall through. break; } - return { "" }; + return {}; } template diff --git a/Modules/IO/SpatialObjects/src/itkPolygonGroupSpatialObjectXMLFile.cxx b/Modules/IO/SpatialObjects/src/itkPolygonGroupSpatialObjectXMLFile.cxx index 766526e7330..4a4e5b557df 100644 --- a/Modules/IO/SpatialObjects/src/itkPolygonGroupSpatialObjectXMLFile.cxx +++ b/Modules/IO/SpatialObjects/src/itkPolygonGroupSpatialObjectXMLFile.cxx @@ -165,7 +165,7 @@ class NumericTraits static std::string ZeroValue() { - return { "" }; + return {}; } }; diff --git a/Modules/Numerics/Optimizers/src/itkLBFGSOptimizer.cxx b/Modules/Numerics/Optimizers/src/itkLBFGSOptimizer.cxx index deced1e046c..ea8366221b3 100644 --- a/Modules/Numerics/Optimizers/src/itkLBFGSOptimizer.cxx +++ b/Modules/Numerics/Optimizers/src/itkLBFGSOptimizer.cxx @@ -315,6 +315,6 @@ LBFGSOptimizer::GetStopConditionDescription() const return m_StopConditionDescription.str(); } - return { "" }; + return {}; } } // end namespace itk diff --git a/Modules/Numerics/Optimizersv4/src/itkLBFGSOptimizerv4Base.cxx b/Modules/Numerics/Optimizersv4/src/itkLBFGSOptimizerv4Base.cxx index 5d8eb92ac89..e4130368bac 100644 --- a/Modules/Numerics/Optimizersv4/src/itkLBFGSOptimizerv4Base.cxx +++ b/Modules/Numerics/Optimizersv4/src/itkLBFGSOptimizerv4Base.cxx @@ -213,7 +213,7 @@ LBFGSOptimizerBasev4::GetStopConditionDescription() c return m_StopConditionDescription.str(); } - return { "" }; + return {}; } template class ITKOptimizersv4_EXPORT LBFGSOptimizerBasev4;