Skip to content

Commit e5011ae

Browse files
N-Dekkerhjmjohnson
authored andcommitted
PERF: Use std::move inside itkSetMacro, declare parameter non-const
Avoids an unnecessary copy (possibly involving memory allocation) of the argument of a Set member function. Note that `itkSetMacro` calls that define a Set member function which passes the argument by const-reference must explicitly specify the `const` keyword now.
1 parent da9ecbb commit e5011ae

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Modules/Core/Common/include/itkMacro.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,17 +966,17 @@ compilers.
966966
itkSetDecoratedObjectInputMacro(name, type); \
967967
itkGetDecoratedObjectInputMacro(name, type)
968968
969-
/** Set built-in type. Creates member Set"name"() (e.g., SetVisibility()); */
969+
/** Set built-in type or regular C++ type. Creates member Set"name"() (e.g., SetVisibility()); */
970970
// clang-format off
971971
#define itkSetMacro(name, type) \
972-
virtual void Set##name(const type _arg) \
972+
virtual void Set##name(type _arg) \
973973
{ \
974974
itkDebugMacro("setting " #name " to " << _arg); \
975975
CLANG_PRAGMA_PUSH \
976976
CLANG_SUPPRESS_Wfloat_equal \
977977
if (this->m_##name != _arg) \
978978
{ \
979-
this->m_##name = _arg; \
979+
this->m_##name = std::move(_arg); \
980980
this->Modified(); \
981981
} \
982982
CLANG_PRAGMA_POP \

Modules/IO/XML/include/itkDOMNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ class ITKIOXML_EXPORT DOMNode : public Object
9393
GetParent() const;
9494

9595
/** Retrieve the tag name of this node. */
96-
itkSetMacro(Name, std::string &);
96+
itkSetMacro(Name, const std::string &);
9797
itkGetConstReferenceMacro(Name, std::string);
9898

9999
/** Retrieve the special attribute "id" of this node. */
100-
itkSetMacro(ID, std::string &);
100+
itkSetMacro(ID, const std::string &);
101101
itkGetConstReferenceMacro(ID, std::string);
102102

103103
/** Retrieve an attribute by key (return an empty string if not found). */

Modules/IO/XML/include/itkDOMTextNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DOMTextNode : public DOMNode
5555
itkTypeMacro(DOMTextNode, DOMNode);
5656

5757
/** Functions to set/get the enclosed text of this node. */
58-
itkSetMacro(Text, std::string &);
58+
itkSetMacro(Text, const std::string &);
5959
itkGetConstReferenceMacro(Text, std::string);
6060

6161
protected:

0 commit comments

Comments
 (0)