Skip to content

Commit 04623af

Browse files
[ADT] Use try_emplace in SCCIterator.h (NFC) (#164187)
This patch replaces an unidiomatic operator[] usage with try_emplace to ensure in-place NodeInfo construction and correct Group field initialization. This patch also clarifies the comment. In particular, "insertion operation" by itself isn't clear whether it's referring to insert() or all of insertion operations like insert(), insert_or_assign(), try_emplace(), etc.
1 parent 550a708 commit 04623af

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

llvm/include/llvm/ADT/SCCIterator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ scc_member_iterator<GraphT, GT>::scc_member_iterator(
313313
// Initialize auxilary node information.
314314
NodeInfoMap.clear();
315315
for (auto *Node : InputNodes) {
316-
// This is specifically used to construct a `NodeInfo` object in place. An
317-
// insert operation will involve a copy construction which invalidate the
318-
// initial value of the `Group` field which should be `this`.
319-
(void)NodeInfoMap[Node].Group;
316+
// Construct a `NodeInfo` object in place. `insert()` would involve a copy
317+
// construction, invalidating the initial value of the `Group` field, which
318+
// should be `this`.
319+
NodeInfoMap.try_emplace(Node);
320320
}
321321

322322
// Sort edges by weights.

0 commit comments

Comments
 (0)