Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clang/lib/AST/ParentMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Copy link
Contributor

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 if inside one big if (M.contains) check to avoid a duplicated map lookup.

Copy link
Collaborator Author

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.

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);
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use M.find to avoid the duplicated lookup here?

Copy link
Collaborator Author

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.

BuildParentMap(M, OVE->getSourceExpr(), OV_Transparent);
}
Expand Down
Loading