[llvm] r233422 - Add two small structs for readability in place of std::pair and std::tuple. NFC.

Rafael Espindola rafael.espindola at gmail.com
Fri Mar 27 14:34:24 PDT 2015


Author: rafael
Date: Fri Mar 27 16:34:24 2015
New Revision: 233422

URL: http://llvm.org/viewvc/llvm-project?rev=233422&view=rev
Log:
Add two small structs for readability in place of std::pair and std::tuple. NFC.

Modified:
    llvm/trunk/include/llvm/MC/MCContext.h
    llvm/trunk/lib/MC/MCContext.cpp

Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=233422&r1=233421&r2=233422&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Fri Mar 27 16:34:24 2015
@@ -162,12 +162,38 @@ namespace llvm {
     /// The Compile Unit ID that we are currently processing.
     unsigned DwarfCompileUnitID;
 
-    typedef std::pair<std::string, std::string> SectionGroupPair;
-    typedef std::tuple<std::string, std::string, int> SectionGroupTriple;
+    struct ELFSectionKey {
+      std::string SectionName;
+      std::string GroupName;
+      ELFSectionKey(StringRef SectionName, StringRef GroupName)
+          : SectionName(SectionName), GroupName(GroupName) {}
+      bool operator<(const ELFSectionKey &Other) const {
+        if (SectionName < Other.SectionName)
+          return true;
+        return GroupName < Other.GroupName;
+      }
+    };
+
+    struct COFFSectionKey {
+      std::string SectionName;
+      std::string GroupName;
+      int SelectionKey;
+      COFFSectionKey(StringRef SectionName, StringRef GroupName,
+                     int SelectionKey)
+          : SectionName(SectionName), GroupName(GroupName),
+            SelectionKey(SelectionKey) {}
+      bool operator<(const COFFSectionKey &Other) const {
+        if (SectionName < Other.SectionName)
+          return true;
+        if (GroupName < Other.GroupName)
+          return GroupName < Other.GroupName;
+        return SelectionKey < Other.SelectionKey;
+      }
+    };
 
     StringMap<const MCSectionMachO*> MachOUniquingMap;
-    std::map<SectionGroupPair, const MCSectionELF *> ELFUniquingMap;
-    std::map<SectionGroupTriple, const MCSectionCOFF *> COFFUniquingMap;
+    std::map<ELFSectionKey, const MCSectionELF *> ELFUniquingMap;
+    std::map<COFFSectionKey, const MCSectionCOFF *> COFFUniquingMap;
 
     /// Do automatic reset in destructor
     bool AutoReset;

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=233422&r1=233421&r2=233422&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Fri Mar 27 16:34:24 2015
@@ -268,11 +268,10 @@ void MCContext::renameELFSection(const M
   if (const MCSymbol *Group = Section->getGroup())
     GroupName = Group->getName();
 
-  ELFUniquingMap.erase(SectionGroupPair(Section->getSectionName(), GroupName));
-  auto I =
-      ELFUniquingMap.insert(std::make_pair(SectionGroupPair(Name, GroupName),
-                                           Section)).first;
-  StringRef CachedName = I->first.first;
+  ELFUniquingMap.erase(ELFSectionKey{Section->getSectionName(), GroupName});
+  auto I = ELFUniquingMap.insert(std::make_pair(ELFSectionKey{Name, GroupName},
+                                                Section)).first;
+  StringRef CachedName = I->first.SectionName;
   const_cast<MCSectionELF*>(Section)->setSectionName(CachedName);
 }
 
@@ -282,7 +281,7 @@ const MCSectionELF *MCContext::getELFSec
                                              const char *BeginSymName) {
   // Do the lookup, if we have a hit, return it.
   auto IterBool = ELFUniquingMap.insert(
-      std::make_pair(SectionGroupPair(Section, Group), nullptr));
+      std::make_pair(ELFSectionKey{Section, Group}, nullptr));
   auto &Entry = *IterBool.first;
   if (!IterBool.second && !Unique)
     return Entry.second;
@@ -291,7 +290,7 @@ const MCSectionELF *MCContext::getELFSec
   if (!Group.empty())
     GroupSym = GetOrCreateSymbol(Group);
 
-  StringRef CachedName = Entry.first.first;
+  StringRef CachedName = Entry.first.SectionName;
 
   SectionKind Kind;
   if (Flags & ELF::SHF_EXECINSTR)
@@ -331,7 +330,7 @@ MCContext::getCOFFSection(StringRef Sect
                           int Selection, const char *BeginSymName) {
   // Do the lookup, if we have a hit, return it.
 
-  SectionGroupTriple T(Section, COMDATSymName, Selection);
+  COFFSectionKey T{Section, COMDATSymName, Selection};
   auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
   auto Iter = IterBool.first;
   if (!IterBool.second)
@@ -345,7 +344,7 @@ MCContext::getCOFFSection(StringRef Sect
   if (BeginSymName)
     Begin = createTempSymbol(BeginSymName, false);
 
-  StringRef CachedName = std::get<0>(Iter->first);
+  StringRef CachedName = Iter->first.SectionName;
   MCSectionCOFF *Result = new (*this) MCSectionCOFF(
       CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
 
@@ -361,7 +360,7 @@ const MCSectionCOFF *MCContext::getCOFFS
 }
 
 const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) {
-  SectionGroupTriple T(Section, "", 0);
+  COFFSectionKey T{Section, "", 0};
   auto Iter = COFFUniquingMap.find(T);
   if (Iter == COFFUniquingMap.end())
     return nullptr;





More information about the llvm-commits mailing list