Skip to content

Fix some unnecessary copies of the Node attributes#1763

Merged
skottmckay merged 1 commit intomasterfrom
skottmckay/FixACoupleOfGetAttributesUsages
Sep 6, 2019
Merged

Fix some unnecessary copies of the Node attributes#1763
skottmckay merged 1 commit intomasterfrom
skottmckay/FixACoupleOfGetAttributesUsages

Conversation

@skottmckay
Copy link
Copy Markdown
Contributor

Description:
Update a few places to not copy the Node attributes.

Motivation and Context
Copy is unnecessary expense.

@skottmckay skottmckay requested a review from a team as a code owner September 6, 2019 00:38
if (attr.has_ref_attr_name()) {
if (attr_map.count(attr.ref_attr_name())) {
new_attr_map[attr.name()] = attr_map[attr.ref_attr_name()];
auto entry = attr_map.find(attr.ref_attr_name());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

curious: isn't count() achieving the same thing? (i wish stl had 'contains')

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.

In general, prefer 'find' over 'count' as the former will stop once it finds a match. Depending on the container type that can be a significant different.

Additionally in this case we want to use the entry, so 'count' + operator[] == two lookups vs one for using the iterator returned by 'find'.

@skottmckay skottmckay merged commit e1a12b1 into master Sep 6, 2019
@skottmckay skottmckay deleted the skottmckay/FixACoupleOfGetAttributesUsages branch September 6, 2019 07:00
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.

2 participants