-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang] [NFC] explicitly check if ParentMap contains key #121736
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 1 commit
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 |
|---|---|---|
|
|
@@ -34,13 +34,13 @@ static void BuildParentMap(MapTy& M, Stmt* S, | |
| case Stmt::PseudoObjectExprClass: { | ||
| PseudoObjectExpr *POE = cast<PseudoObjectExpr>(S); | ||
|
|
||
| if (OVMode == OV_Opaque && M[POE->getSyntacticForm()]) | ||
| if (OVMode == OV_Opaque && M.contains(POE->getSyntacticForm())) | ||
| break; | ||
|
|
||
| // If we are rebuilding the map, clear out any existing state. | ||
| if (M[POE->getSyntacticForm()]) | ||
| if (M.contains(POE->getSyntacticForm())) | ||
| for (Stmt *SubStmt : S->children()) | ||
| M[SubStmt] = nullptr; | ||
| M.erase(SubStmt); | ||
|
|
||
| M[POE->getSyntacticForm()] = S; | ||
| BuildParentMap(M, POE->getSyntacticForm(), OV_Transparent); | ||
|
|
@@ -78,7 +78,7 @@ static void BuildParentMap(MapTy& M, Stmt* S, | |
| // The right thing to do is to give the OpaqueValueExpr its syntactic | ||
| // parent, then not reassign that when traversing the semantic expressions. | ||
| OpaqueValueExpr *OVE = cast<OpaqueValueExpr>(S); | ||
| if (OVMode == OV_Transparent || !M[OVE->getSourceExpr()]) { | ||
| if (OVMode == OV_Transparent || !M.contains(OVE->getSourceExpr())) { | ||
| M[OVE->getSourceExpr()] = S; | ||
|
||
| BuildParentMap(M, OVE->getSourceExpr(), OV_Transparent); | ||
| } | ||
|
|
||
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.
Could put this and the next
ifinside one bigif (M.contains)check to avoid a duplicated map lookup.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.
Fixed with try_emplace() to avoid the second lookup as well, which inserts when the key is already present.