Skip to content

Commit

Permalink
PERF: Prefer default initialization for std::string
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hjmjohnson committed Dec 27, 2024
1 parent 8676b86 commit 5fc954e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Modules/Core/Common/src/itkBuildInformation.cxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ BuildInformation::GetValue(const MapKeyType & key)
{
return it->second.m_Value;
}
return {""};
return {};;
}

const BuildInformation::MapValueDescriptionType
Expand All @@ -100,7 +100,7 @@ BuildInformation::GetDescription(const MapKeyType & key)
{
return it->second.m_Description;
}
return {""};
return {};;
}

const std::vector< BuildInformation::MapKeyType >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ DTITubeSpatialObjectPoint<TPointDimension>::TranslateEnumToChar(DTITubeSpatialOb
// Just fall through.
break;
}
return { "" };
return {};
}

template <unsigned int TPointDimension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class NumericTraits<std::string>
static std::string
ZeroValue()
{
return { "" };
return {};
}
};

Expand Down
2 changes: 1 addition & 1 deletion Modules/Numerics/Optimizers/src/itkLBFGSOptimizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,6 @@ LBFGSOptimizer::GetStopConditionDescription() const
return m_StopConditionDescription.str();
}

return { "" };
return {};
}
} // end namespace itk
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ LBFGSOptimizerBasev4<TInternalVnlOptimizerType>::GetStopConditionDescription() c
return m_StopConditionDescription.str();
}

return { "" };
return {};
}

template class ITKOptimizersv4_EXPORT LBFGSOptimizerBasev4<vnl_lbfgs>;
Expand Down

0 comments on commit 5fc954e

Please sign in to comment.