Skip to content

STYLE: Remove private ObjectFactoryBase member RegisterInternal()#4228

Merged
dzenanz merged 2 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:Remove-ObjectFactoryBase-RegisterInternal
Oct 4, 2023
Merged

STYLE: Remove private ObjectFactoryBase member RegisterInternal()#4228
dzenanz merged 2 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:Remove-ObjectFactoryBase-RegisterInternal

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

@N-Dekker N-Dekker commented Sep 25, 2023

ObjectFactoryBase::RegisterInternal() was only called by Initialize() anyway.

Avoided a redundant itkInitGlobalsMacro(PimplGlobals) call, and replaced clear and push_back calls by a simple assignment to m_RegisteredFactories.

@github-actions github-actions Bot added the area:Core Issues affecting the Core module label Sep 25, 2023
@N-Dekker N-Dekker force-pushed the Remove-ObjectFactoryBase-RegisterInternal branch from 7819efe to 9aecafd Compare September 27, 2023 10:30
@N-Dekker N-Dekker changed the title WIP: STYLE: Remove private ObjectFactoryBase member RegisterInternal() STYLE: Remove private ObjectFactoryBase member RegisterInternal() Sep 27, 2023
@N-Dekker N-Dekker marked this pull request as ready for review September 27, 2023 12:39
@thewtex thewtex requested a review from blowekamp September 29, 2023 01:32
Replaced `clear` and `push_back` calls with a simple `std::list` assignment to
`m_RegisteredFactories`.
`ObjectFactoryBase::RegisterInternal()` was only called by `Initialize()`
anyway.

Moved the code from `RegisterInternal()` into `Initialize()`, except from an
`itkInitGlobalsMacro(PimplGlobals)` call which is no longer necessary.
@N-Dekker N-Dekker force-pushed the Remove-ObjectFactoryBase-RegisterInternal branch from 9aecafd to d86e2f9 Compare October 3, 2023 11:07
@github-actions github-actions Bot added the type:Style Style changes: no logic impact (indentation, comments, naming) label Oct 3, 2023
@N-Dekker
Copy link
Copy Markdown
Contributor Author

N-Dekker commented Oct 3, 2023

FYI, the last force-push has just split the changes from one commit to two, hoping to ease further processing.

@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Oct 3, 2023

@blowekamp could you also review?

{
ObjectFactoryBase::RegisterInternal();
// Guarantee that no internal factories have already been registered.
itkAssertInDebugAndIgnoreInReleaseMacro(m_PimplGlobals->m_RegisteredFactories.empty());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only be guaranteed in debug, and will be ignored in release. Perhaps we should create a warning if it's not empty and then clear the registered factories? I generally assume there was a reason for line being there rather and it should be preserved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comment, Bradley. This PR is intended to only propose a style improvement, so I'd rather not change the behavior (in release). But I did have a look. The following commit made the assertion "debug-only": 302d53c "BUG: Prevent ObjectFactoryBase from possibly throwing an exception" by Brian Helba (@brianhelba) January 8, 2014. I wouldn't mind leaving it like this at the moment. 🤷

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if you want to keep the original behavior I'd keep the clear.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if you want to keep the original behavior I'd keep the clear.

Why? Please look at the original code again:

m_PimplGlobals->m_RegisteredFactories.clear();
// Register all factories registered by the
// "RegisterFactoryInternal" method
for (auto & internalFactory : m_PimplGlobals->m_InternalFactories)
{
m_PimplGlobals->m_RegisteredFactories.push_back(internalFactory);
}

m_PimplGlobals->m_RegisteredFactories.clear(); 
 
for (auto & internalFactory : m_PimplGlobals->m_InternalFactories) 
{ 
  m_PimplGlobals->m_RegisteredFactories.push_back(internalFactory); 
} 

Why not just doing a single std::list assignment instead, m_PimplGlobals->m_RegisteredFactories = m_PimplGlobals->m_InternalFactories?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point they are quite similar. This was incorrect justification for why I didn't think this PR was a refactor and not a style change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blowekamp Cool, thanks for explaining! 👍 And thanks for double-checking!

Copy link
Copy Markdown
Member

@blowekamp blowekamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a reasonable refactor.

@dzenanz dzenanz merged commit 427972e into InsightSoftwareConsortium:master Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Style Style changes: no logic impact (indentation, comments, naming)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants