Skip to content

[clang-tidy] Use DenseMap::insert_range (NFC) #133844

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

Conversation

kazutakahirata
Copy link
Contributor

We can safely switch to insert_range here because
SyntheticStmtSourceMap starts out empty in the constructor. Also
TheCFG->synthetic_stmts() comes from DenseMap, so we know that the
keys are unique. That is, operator[] and insert are equivalent in
this particular case.

We can safely switch to insert_range here because
SyntheticStmtSourceMap starts out empty in the constructor.  Also
TheCFG->synthetic_stmts() comes from DenseMap, so we know that the
keys are unique.  That is, operator[] and insert are equivalent in
this particular case.
@llvmbot
Copy link
Member

llvmbot commented Apr 1, 2025

@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Kazu Hirata (kazutakahirata)

Changes

We can safely switch to insert_range here because
SyntheticStmtSourceMap starts out empty in the constructor. Also
TheCFG->synthetic_stmts() comes from DenseMap, so we know that the
keys are unique. That is, operator[] and insert are equivalent in
this particular case.


Full diff: https://github.com/llvm/llvm-project/pull/133844.diff

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/utils/ExprSequence.cpp (+1-3)
diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
index 145a5fe378b3e..685277d8bfbca 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -84,9 +84,7 @@ getAllInitListForms(const InitListExpr *InitList) {
 ExprSequence::ExprSequence(const CFG *TheCFG, const Stmt *Root,
                            ASTContext *TheContext)
     : Context(TheContext), Root(Root) {
-  for (const auto &SyntheticStmt : TheCFG->synthetic_stmts()) {
-    SyntheticStmtSourceMap[SyntheticStmt.first] = SyntheticStmt.second;
-  }
+  SyntheticStmtSourceMap.insert_range(TheCFG->synthetic_stmts());
 }
 
 bool ExprSequence::inSequence(const Stmt *Before, const Stmt *After) const {

@kazutakahirata kazutakahirata merged commit ee3c892 into llvm:main Apr 1, 2025
14 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_map_range_DenseMap_clang_tidy branch April 1, 2025 05:11
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.

3 participants