[llvm] 0690a42 - [BPF] Avoid repeated map lookups (NFC) (#113247)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 22 07:59:18 PDT 2024


Author: Kazu Hirata
Date: 2024-10-22T07:59:14-07:00
New Revision: 0690a42261a5e228b34409c79e76ed47d1080f21

URL: https://github.com/llvm/llvm-project/commit/0690a42261a5e228b34409c79e76ed47d1080f21
DIFF: https://github.com/llvm/llvm-project/commit/0690a42261a5e228b34409c79e76ed47d1080f21.diff

LOG: [BPF] Avoid repeated map lookups (NFC) (#113247)

Added: 
    

Modified: 
    llvm/lib/Target/BPF/BTFDebug.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
index 9d6dee13ca97a9..a14e9db5f7500d 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/lib/Target/BPF/BTFDebug.cpp
@@ -1499,17 +1499,15 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
       continue;
 
     // Find or create a DataSec
-    if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
-      DataSecEntries[std::string(SecName)] =
-          std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
-    }
+    auto [It, Inserted] = DataSecEntries.try_emplace(std::string(SecName));
+    if (Inserted)
+      It->second = std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
 
     // Calculate symbol size
     const DataLayout &DL = Global.getDataLayout();
     uint32_t Size = DL.getTypeAllocSize(Global.getValueType());
 
-    DataSecEntries[std::string(SecName)]->addDataSecEntry(VarId,
-        Asm->getSymbol(&Global), Size);
+    It->second->addDataSecEntry(VarId, Asm->getSymbol(&Global), Size);
 
     if (Global.hasInitializer())
       processGlobalInitializer(Global.getInitializer());
@@ -1609,14 +1607,12 @@ void BTFDebug::processFuncPrototypes(const Function *F) {
   if (F->hasSection()) {
     StringRef SecName = F->getSection();
 
-    if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
-      DataSecEntries[std::string(SecName)] =
-          std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
-    }
+    auto [It, Inserted] = DataSecEntries.try_emplace(std::string(SecName));
+    if (Inserted)
+      It->second = std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
 
     // We really don't know func size, set it to 0.
-    DataSecEntries[std::string(SecName)]->addDataSecEntry(FuncId,
-        Asm->getSymbol(F), 0);
+    It->second->addDataSecEntry(FuncId, Asm->getSymbol(F), 0);
   }
 }
 


        


More information about the llvm-commits mailing list