-
Notifications
You must be signed in to change notification settings - Fork 832
Stop using operator[] only for default-insertion into maps #8129
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1344,7 +1344,7 @@ struct Inlining : public Pass { | |
| // fill in info, as we operate on it in parallel (each function to its own | ||
| // entry) | ||
| for (auto& func : module->functions) { | ||
| infos[func->name]; | ||
| infos.try_emplace(func->name); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These will definitely insert (the map is empty before), so perhaps The same might happen in a few other places, but this one is especially clear-cut (we clear the map right before the loop).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I thought about that. The other difference between
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I think it's because
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, sounds good. lgtm |
||
| } | ||
| { | ||
| FunctionInfoScanner scanner(infos); | ||
|
|
@@ -1388,7 +1388,7 @@ struct Inlining : public Pass { | |
| // without iterator invalidation. | ||
| std::vector<Name> funcNames; | ||
| for (auto& func : module->functions) { | ||
| state.actionsForFunction[func->name]; | ||
| state.actionsForFunction.try_emplace(func->name); | ||
| funcNames.push_back(func->name); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
insertinstead oftry_emplacehere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right I wanted to mention that. It's because
mapis actually an instance ofwasm::InsertOrderedMap, (https://github.com/WebAssembly/binaryen/blob/main/src/support/insert_ordered.h#L92) and doesn't have try_emplace. So the other option would be to just fix that instead.