Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eliminate find of "find + emplace/insert" sequence #10969

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rockeet
Copy link
Contributor

@rockeet rockeet commented Nov 21, 2022

auto iter = map.find(key);
if (iter == map.end()) { // not found
  map.emplace(...); // or insert
} else {
  // found, handle dup
}

can be optimized to:

auto [iter, success] = map.emplace(key_value); // or insert
if (!success) {
  // found, handle dup
}

The optimized code eliminated the redundant calling to find.

@rockeet rockeet changed the title utilities/transaction: eliminate find of "find + emplace/insert" sequence eliminate find of "find + emplace/insert" sequence Nov 21, 2022
@rockeet rockeet force-pushed the utilities-transaction-find-insert branch from 2f61523 to 6a36e97 Compare November 21, 2022 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants