From 0af436fe2b644e5cc2ca68d5f54668e8e6f43dc5 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 22 May 2024 13:49:33 +0200 Subject: [PATCH] PERF: Make `ImageRegion` trivially copyable (LEGACY_REMOVE) 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 https://github.com/InsightSoftwareConsortium/ITK/pull/4344 commit 1f3bbb658698556ff0d437c4effb9c1e42acc7c2 --- Modules/Core/Common/include/itkImageRegion.h | 16 ++++++++-------- Modules/Core/Common/test/itkImageRegionGTest.cxx | 8 +++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Modules/Core/Common/include/itkImageRegion.h b/Modules/Core/Common/include/itkImageRegion.h index 7fbb997a430..7c9b8858e43 100644 --- a/Modules/Core/Common/include/itkImageRegion.h +++ b/Modules/Core/Common/include/itkImageRegion.h @@ -36,11 +36,11 @@ #include // For conditional and integral_constant. #include // 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 @@ -78,8 +78,8 @@ class ITK_TEMPLATE_EXPORT ImageBase; */ template 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 { @@ -87,7 +87,7 @@ class ITK_TEMPLATE_EXPORT ImageRegion final /** Standard class type aliases. */ using Self = ImageRegion; -#ifndef ITK_FUTURE_LEGACY_REMOVE +#ifndef ITK_LEGACY_REMOVE using Superclass = Region; #endif diff --git a/Modules/Core/Common/test/itkImageRegionGTest.cxx b/Modules/Core/Common/test/itkImageRegionGTest.cxx index 66e727e5f4a..5f89e210303 100644 --- a/Modules/Core/Common/test/itkImageRegionGTest.cxx +++ b/Modules/Core/Common/test/itkImageRegionGTest.cxx @@ -32,11 +32,13 @@ CheckTrivialCopyabilityOfImageRegion() { constexpr bool isImageRegionTriviallyCopyable{ std::is_trivially_copyable_v> }; -#ifdef ITK_FUTURE_LEGACY_REMOVE - static_assert(isImageRegionTriviallyCopyable, "In the future, ImageRegion should be trivially copyable."); +#ifdef ITK_LEGACY_REMOVE + static_assert(isImageRegionTriviallyCopyable, + "When legacy support is removed, ImageRegion should be trivially copyable."); return isImageRegionTriviallyCopyable; #else - static_assert(!isImageRegionTriviallyCopyable, "ImageRegion should *not* be trivially copyable."); + static_assert(!isImageRegionTriviallyCopyable, + "When legacy support is enabled, ImageRegion should *not* be trivially copyable."); return !isImageRegionTriviallyCopyable; #endif }