Skip to content

Meta data dictionary move and copy on write#455

Merged
blowekamp merged 5 commits intoInsightSoftwareConsortium:masterfrom
blowekamp:MetaDataDictionaryMove
Feb 1, 2019
Merged

Meta data dictionary move and copy on write#455
blowekamp merged 5 commits intoInsightSoftwareConsortium:masterfrom
blowekamp:MetaDataDictionaryMove

Conversation

@blowekamp
Copy link
Copy Markdown
Member

No description provided.

@blowekamp
Copy link
Copy Markdown
Member Author

The is a revival of #98

@blowekamp
Copy link
Copy Markdown
Member Author

As noted by @N-Dekker the operator[](const std::string & key) const method was and is more problematically a violation of a constant interface because if key is not in the dictionary it may add a default value at the specified key.

I can not think of a good option to fix this interface.

MetaDataDictionary
::Clear()
{
MakeUnique();
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.

Will this create a copy, only to be erased by the next line?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I’ll look into that

@blowekamp
Copy link
Copy Markdown
Member Author

This should be a WIP

@phcerdan phcerdan changed the title Meta data dictionary move WIP: Meta data dictionary move Jan 29, 2019
The default behavior when reading a Image in ITK is to create 3 copies
of the MetaDataDictionary for the ImageIO, ImageFileReader, and Image
object. These are usually not modified, not shared and created by a
deep copy. The internal std::map is shared via a std::share_ptr with a
reference count. If the dictionaries are modified a deep copy is
performed.
Cover basic usage of the interface along with checking that a
copy-on-write occurs at the proper time.
The constant implementation of MetaDataDictionary::operator[] might
add an default initialized key if the key did not exist already.
Use Find and the resulting iterator to query existence and get value,
instead of two separate searches.
@blowekamp blowekamp force-pushed the MetaDataDictionaryMove branch from 25ae222 to acd5e0d Compare January 30, 2019 19:47
{
MetaDataObjectBase::Pointer entry = ( *m_Dictionary )[key];
const MetaDataObjectBase * constentry = entry.GetPointer();
auto iter = m_Dictionary->find(key);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@N-Dekker I pondered deprecating this method, but instead I have just made it return a nullptr, and not modify the std::map when not does not exist. This const method does not exist in the std container, and the behavior is different than the non-constant method.

@blowekamp blowekamp changed the title WIP: Meta data dictionary move Meta data dictionary move and copy on write Jan 30, 2019
Copy link
Copy Markdown
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

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

Cool!

@blowekamp blowekamp merged commit 34bccb5 into InsightSoftwareConsortium:master Feb 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants