Skip to content

Commit

Permalink
PERF: Avoid redundant searches for a data element in a gdcm::DataSet
Browse files Browse the repository at this point in the history
The original code requested `gdcm::DataSet` to search for one and the same data
element three times in a row, by calling both FindDataElement and GetDataElement
for the very same tag. With this commit, the search is only performed once.

Issue found by Mihail Isakov:
InsightSoftwareConsortium#4636 (comment)
  • Loading branch information
N-Dekker committed May 8, 2024
1 parent 28de861 commit 8b96d1e
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions Modules/IO/GDCM/src/itkGDCMImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,8 @@ GDCMImageIO::InternalReadImageInformation()
{
std::vector<double> sp;
gdcm::Tag spacingTag(0x0028, 0x0030);
if (ds.FindDataElement(spacingTag) && !ds.GetDataElement(spacingTag).IsEmpty())
if (const gdcm::DataElement & de = ds.GetDataElement(spacingTag); !de.IsEmpty())
{
gdcm::DataElement de = ds.GetDataElement(spacingTag);
std::stringstream m_Ss;
gdcm::Element<gdcm::VR::DS, gdcm::VM::VM1_n> m_El;
const gdcm::ByteValue * bv = de.GetByteValue();
Expand Down

0 comments on commit 8b96d1e

Please sign in to comment.