Skip to content

Commit

Permalink
PERF: Make ImageRegion trivially copyable (LEGACY_REMOVE)
Browse files Browse the repository at this point in the history
Replaced `ITK_FUTURE_LEGACY_REMOVE` with `ITK_LEGACY_REMOVE`, regarding its
inheritance from `itk::Region`.

A run-time performance improvement of more than 25% on default-constructing
and destructing a sequence of `ImageRegion` objects was observed.

- Follow-up to pull request InsightSoftwareConsortium#4344
commit 1f3bbb6
  • Loading branch information
N-Dekker committed May 22, 2024
1 parent 8e5abbd commit 0af436f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 8 additions & 8 deletions Modules/Core/Common/include/itkImageRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
#include <type_traits> // For conditional and integral_constant.
#include <utility> // For tuple_element and tuple_size.

// Macro added to each `ImageRegion` member function that overrides a virtual member function of `Region`. In the
// future, `ImageRegion` will no longer inherit from `Region`, so then those `ImageRegion` member functions will no
// longer override.
#ifdef ITK_FUTURE_LEGACY_REMOVE
# define itkRegionOverrideMacro // nothing (in the future)
// Macro added to each `ImageRegion` member function that overrides a virtual member function of `Region`, when legacy
// support is enabled. Without legacy support, `ImageRegion` will no longer inherit from `Region`, so then those
// `ImageRegion` member functions will no longer override.
#ifdef ITK_LEGACY_REMOVE
# define itkRegionOverrideMacro // nothing
#else
# define itkRegionOverrideMacro override
#endif
Expand Down Expand Up @@ -78,16 +78,16 @@ class ITK_TEMPLATE_EXPORT ImageBase;
*/
template <unsigned int VImageDimension>
class ITK_TEMPLATE_EXPORT ImageRegion final
#ifndef ITK_FUTURE_LEGACY_REMOVE
// This inheritance is to be removed in the future.
#ifndef ITK_LEGACY_REMOVE
// This inheritance is only there when legacy support is enabled.
: public Region
#endif
{
public:
/** Standard class type aliases. */
using Self = ImageRegion;

#ifndef ITK_FUTURE_LEGACY_REMOVE
#ifndef ITK_LEGACY_REMOVE
using Superclass = Region;
#endif

Expand Down
8 changes: 5 additions & 3 deletions Modules/Core/Common/test/itkImageRegionGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ CheckTrivialCopyabilityOfImageRegion()
{
constexpr bool isImageRegionTriviallyCopyable{ std::is_trivially_copyable_v<itk::ImageRegion<VDimension>> };

#ifdef ITK_FUTURE_LEGACY_REMOVE
static_assert(isImageRegionTriviallyCopyable, "In the future, ImageRegion<VDimension> should be trivially copyable.");
#ifdef ITK_LEGACY_REMOVE
static_assert(isImageRegionTriviallyCopyable,
"When legacy support is removed, ImageRegion<VDimension> should be trivially copyable.");
return isImageRegionTriviallyCopyable;
#else
static_assert(!isImageRegionTriviallyCopyable, "ImageRegion<VDimension> should *not* be trivially copyable.");
static_assert(!isImageRegionTriviallyCopyable,
"When legacy support is enabled, ImageRegion<VDimension> should *not* be trivially copyable.");
return !isImageRegionTriviallyCopyable;
#endif
}
Expand Down

0 comments on commit 0af436f

Please sign in to comment.