Skip to content

Commit

Permalink
STYLE: Updated comments and variable in ImportImageContainer
Browse files Browse the repository at this point in the history
Comments are variable name describe the behavior of the
ImportImageContainer better.
Closes InsightSoftwareConsortium#4359
  • Loading branch information
issakomi committed Dec 3, 2023
1 parent 8a4ab31 commit 74afe13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
12 changes: 5 additions & 7 deletions Modules/Core/Common/include/itkImportImageContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,11 @@ class ITK_TEMPLATE_EXPORT ImportImageContainer : public Object
* container. However, in this particular case, Reserve as a Resize
* semantics that is kept for backward compatibility reasons.
*
* If UseDefaultConstructor is true, then * the default constructor is used
* to initialize each element. POD date types initialize to zero.
* If UseInitValue is true, then POD types will be zero-initialized.
*
* \sa SetImportPointer() */
void
Reserve(ElementIdentifier size, const bool UseDefaultConstructor = false);
Reserve(ElementIdentifier size, const bool UseInitValue = false);

/** Tell the container to try to minimize its memory usage for
* storage of the current number of elements. If new memory is
Expand Down Expand Up @@ -162,12 +161,11 @@ class ITK_TEMPLATE_EXPORT ImportImageContainer : public Object
PrintSelf(std::ostream & os, Indent indent) const override;

/**
* Allocates elements of the array. If UseDefaultConstructor is true, then
* the default constructor is used to initialize each element. POD date types
* initialize to zero.
* Allocates elements of the array. If UseInitValue is true, then POD
* types will be zero-initialized.
*/
virtual TElement *
AllocateElements(ElementIdentifier size, bool UseDefaultConstructor = false) const;
AllocateElements(ElementIdentifier size, bool UseInitValue = false) const;

virtual void
DeallocateManagedMemory();
Expand Down
18 changes: 7 additions & 11 deletions Modules/Core/Common/include/itkImportImageContainer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ImportImageContainer<TElementIdentifier, TElement>::~ImportImageContainer()
*/
template <typename TElementIdentifier, typename TElement>
void
ImportImageContainer<TElementIdentifier, TElement>::Reserve(ElementIdentifier size, const bool UseDefaultConstructor)
ImportImageContainer<TElementIdentifier, TElement>::Reserve(ElementIdentifier size, const bool UseInitValue)
{
// Reserve has a Resize semantics. We keep it that way for
// backwards compatibility .
Expand All @@ -53,7 +53,7 @@ ImportImageContainer<TElementIdentifier, TElement>::Reserve(ElementIdentifier si
{
if (size > m_Capacity)
{
TElement * temp = this->AllocateElements(size, UseDefaultConstructor);
TElement * temp = this->AllocateElements(size, UseInitValue);
// only copy the portion of the data used in the old buffer
std::copy_n(m_ImportPointer, m_Size, temp);

Expand All @@ -73,7 +73,7 @@ ImportImageContainer<TElementIdentifier, TElement>::Reserve(ElementIdentifier si
}
else
{
m_ImportPointer = this->AllocateElements(size, UseDefaultConstructor);
m_ImportPointer = this->AllocateElements(size, UseInitValue);
m_Capacity = size;
m_Size = size;
m_ContainerManageMemory = true;
Expand Down Expand Up @@ -152,23 +152,19 @@ ImportImageContainer<TElementIdentifier, TElement>::SetImportPointer(TElement *

template <typename TElementIdentifier, typename TElement>
TElement *
ImportImageContainer<TElementIdentifier, TElement>::AllocateElements(ElementIdentifier size,
bool UseDefaultConstructor) const
ImportImageContainer<TElementIdentifier, TElement>::AllocateElements(ElementIdentifier size, bool UseInitValue) const
{
// Encapsulate all image memory allocation here to throw an
// exception when memory allocation fails even when the compiler
// does not do this by default.
TElement * data;

try
{
if (UseDefaultConstructor)
if (UseInitValue)
{
data = new TElement[size](); // POD types initialized to 0, others use default constructor.
data = new TElement[size]();
}
else
{
data = new TElement[size]; // Faster but uninitialized
data = new TElement[size];
}
}
catch (...)
Expand Down

0 comments on commit 74afe13

Please sign in to comment.