Make TType store a const char * for mangled name.

We would only ever use the c_str value from the mangled name. This
makes it easier to make constexpr TTypes.

Bug: angleproject:1432
Change-Id: I147b3a85f9b8b2453e2d7f4a713d767b22036cc9
Reviewed-on: https://chromium-review.googlesource.com/776277
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/compiler/translator/SymbolTable.cpp b/src/compiler/translator/SymbolTable.cpp
index b26acc8..6c38461 100644
--- a/src/compiler/translator/SymbolTable.cpp
+++ b/src/compiler/translator/SymbolTable.cpp
@@ -66,7 +66,7 @@
 
     for (const auto &p : parameters)
     {
-        newName += p.type->getMangledName().c_str();
+        newName += p.type->getMangledName();
     }
     return NewPoolTString(newName.c_str());
 }
@@ -79,7 +79,7 @@
 
     for (TIntermNode *argument : arguments)
     {
-        newName += argument->getAsTyped()->getType().getMangledName().c_str();
+        newName += argument->getAsTyped()->getType().getMangledName();
     }
     return *NewPoolTString(newName.c_str());
 }
diff --git a/src/compiler/translator/Types.cpp b/src/compiler/translator/Types.cpp
index a57dd9d..ef743ad 100644
--- a/src/compiler/translator/Types.cpp
+++ b/src/compiler/translator/Types.cpp
@@ -125,7 +125,8 @@
       secondarySize(0),
       mInterfaceBlock(nullptr),
       mStructure(nullptr),
-      mIsStructSpecifier(false)
+      mIsStructSpecifier(false),
+      mMangledName(nullptr)
 {
 }
 
@@ -140,7 +141,8 @@
       secondarySize(ss),
       mInterfaceBlock(0),
       mStructure(0),
-      mIsStructSpecifier(false)
+      mIsStructSpecifier(false),
+      mMangledName(nullptr)
 {
 }
 
@@ -155,7 +157,8 @@
       secondarySize(ss),
       mInterfaceBlock(0),
       mStructure(0),
-      mIsStructSpecifier(false)
+      mIsStructSpecifier(false),
+      mMangledName(nullptr)
 {
 }
 
@@ -170,7 +173,8 @@
       secondarySize(p.getSecondarySize()),
       mInterfaceBlock(nullptr),
       mStructure(nullptr),
-      mIsStructSpecifier(false)
+      mIsStructSpecifier(false),
+      mMangledName(nullptr)
 {
     ASSERT(primarySize <= 4);
     ASSERT(secondarySize <= 4);
@@ -196,7 +200,8 @@
       secondarySize(1),
       mInterfaceBlock(nullptr),
       mStructure(userDef),
-      mIsStructSpecifier(false)
+      mIsStructSpecifier(false),
+      mMangledName(nullptr)
 {
 }
 
@@ -213,7 +218,8 @@
       secondarySize(1),
       mInterfaceBlock(interfaceBlockIn),
       mStructure(0),
-      mIsStructSpecifier(false)
+      mIsStructSpecifier(false),
+      mMangledName(nullptr)
 {
 }
 
@@ -375,7 +381,7 @@
 //
 // Recursively generate mangled names.
 //
-TString TType::buildMangledName() const
+const char *TType::buildMangledName() const
 {
     TString mangledName;
     if (isMatrix())
@@ -532,7 +538,12 @@
         mangledName += buf;
         mangledName += ']';
     }
-    return mangledName;
+
+    mangledName += ';';
+
+    // We allocate with the pool allocator, so it's fine that the TString goes out of scope.
+    TString *temp = new TString(mangledName);
+    return temp->c_str();
 }
 
 size_t TType::getObjectSize() const
@@ -733,12 +744,11 @@
     }
 }
 
-const TString &TType::getMangledName() const
+const char *TType::getMangledName() const
 {
-    if (mMangledName.empty())
+    if (mMangledName == nullptr)
     {
         mMangledName = buildMangledName();
-        mMangledName += ';';
     }
 
     return mMangledName;
@@ -751,7 +761,7 @@
 
 void TType::invalidateMangledName()
 {
-    mMangledName = "";
+    mMangledName = nullptr;
 }
 
 // TStructure implementation.
diff --git a/src/compiler/translator/Types.h b/src/compiler/translator/Types.h
index 7faeab9..6091855 100644
--- a/src/compiler/translator/Types.h
+++ b/src/compiler/translator/Types.h
@@ -279,7 +279,7 @@
     const TStructure *getStruct() const { return mStructure; }
     void setStruct(TStructure *s);
 
-    const TString &getMangledName() const;
+    const char *getMangledName() const;
 
     bool sameNonArrayType(const TType &right) const;
 
@@ -368,7 +368,7 @@
 
   private:
     void invalidateMangledName();
-    TString buildMangledName() const;
+    const char *buildMangledName() const;
 
     TBasicType type;
     TPrecision precision;
@@ -393,7 +393,7 @@
     TStructure *mStructure;
     bool mIsStructSpecifier;
 
-    mutable TString mMangledName;
+    mutable const char *mMangledName;
 };
 
 // TTypeSpecifierNonArray stores all of the necessary fields for type_specifier_nonarray from the