Reduce duplication in MCSymbol Name handling. NFC>
[oota-llvm.git] / include / llvm / MC / MCSymbol.h
index 544cf8abe60eef3ce24b96604bd2fd803b214a67..78b7c516e8347a4610599c89fa860a6fa8b27247 100644 (file)
@@ -136,7 +136,7 @@ protected: // MCContext creates and uniques these.
         Kind(Kind) {
     Offset = 0;
     if (Name)
-      getNameEntryPtr().NameEntry = Name;
+      getNameEntryPtr() = Name;
   }
 
   // Provide custom new/delete as we will only allocate space for a name
@@ -169,15 +169,13 @@ private:
   }
 
   /// \brief Get a reference to the name field.  Requires that we have a name
-  NameEntryStorageTy &getNameEntryPtr() {
+  const StringMapEntry<bool> *&getNameEntryPtr() {
     assert(HasName && "Name is required");
     NameEntryStorageTy *Name = reinterpret_cast<NameEntryStorageTy *>(this);
-    return *(Name - 1);
+    return (*(Name - 1)).NameEntry;
   }
-  const NameEntryStorageTy &getNameEntryPtr() const {
-    assert(HasName && "Name is required");
-    const auto *Name = reinterpret_cast<const NameEntryStorageTy *>(this);
-    return *(Name - 1);
+  const StringMapEntry<bool> *&getNameEntryPtr() const {
+    return const_cast<MCSymbol*>(this)->getNameEntryPtr();
   }
 
 public:
@@ -186,7 +184,7 @@ public:
     if (!HasName)
       return StringRef();
 
-    return getNameEntryPtr().NameEntry->first();
+    return getNameEntryPtr()->first();
   }
 
   bool isRegistered() const { return IsRegistered; }