Skip to content

[clang] Default-construct values with DenseMap::try_emplace (NFC) #141373

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

Merged

Conversation

kazutakahirata
Copy link
Contributor

try_emplace can default-construct values, so we do not need to do so
on our own.

try_emplace can default-construct values, so we do not need to do so
on our own.
@llvmbot
Copy link
Member

llvmbot commented May 24, 2025

@llvm/pr-subscribers-clangd

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

Author: Kazu Hirata (kazutakahirata)

Changes

try_emplace can default-construct values, so we do not need to do so
on our own.


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

1 Files Affected:

  • (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+2-2)
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 3f5633357073d..6bdb1080fb294 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -1201,7 +1201,7 @@ void SymbolCollector::addRef(SymbolID ID, const SymbolRef &SR) {
 }
 
 SymbolID SymbolCollector::getSymbolIDCached(const Decl *D) {
-  auto It = DeclToIDCache.try_emplace(D, SymbolID{});
+  auto It = DeclToIDCache.try_emplace(D);
   if (It.second)
     It.first->second = getSymbolID(D);
   return It.first->second;
@@ -1210,7 +1210,7 @@ SymbolID SymbolCollector::getSymbolIDCached(const Decl *D) {
 SymbolID SymbolCollector::getSymbolIDCached(const llvm::StringRef MacroName,
                                             const MacroInfo *MI,
                                             const SourceManager &SM) {
-  auto It = MacroToIDCache.try_emplace(MI, SymbolID{});
+  auto It = MacroToIDCache.try_emplace(MI);
   if (It.second)
     It.first->second = getSymbolID(MacroName, MI, SM);
   return It.first->second;

@kazutakahirata kazutakahirata merged commit 4eb91b9 into llvm:main May 24, 2025
14 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250524_try_emplace_clangd branch May 24, 2025 21:47
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
…vm#141373)

try_emplace can default-construct values, so we do not need to do so
on our own.
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