Commit dc7bffd0 by Jamie Madill Committed by Commit Bot

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: 's avatarKai Ninomiya <kainino@chromium.org>
parent 90ed1e49
......@@ -66,7 +66,7 @@ const TString *TFunction::buildMangledName() const
for (const auto &p : parameters)
{
newName += p.type->getMangledName().c_str();
newName += p.type->getMangledName();
}
return NewPoolTString(newName.c_str());
}
......@@ -79,7 +79,7 @@ const TString &TFunction::GetMangledNameFromCall(const TString &functionName,
for (TIntermNode *argument : arguments)
{
newName += argument->getAsTyped()->getType().getMangledName().c_str();
newName += argument->getAsTyped()->getType().getMangledName();
}
return *NewPoolTString(newName.c_str());
}
......
......@@ -125,7 +125,8 @@ TType::TType()
secondarySize(0),
mInterfaceBlock(nullptr),
mStructure(nullptr),
mIsStructSpecifier(false)
mIsStructSpecifier(false),
mMangledName(nullptr)
{
}
......@@ -140,7 +141,8 @@ TType::TType(TBasicType t, unsigned char ps, unsigned char ss)
secondarySize(ss),
mInterfaceBlock(0),
mStructure(0),
mIsStructSpecifier(false)
mIsStructSpecifier(false),
mMangledName(nullptr)
{
}
......@@ -155,7 +157,8 @@ TType::TType(TBasicType t, TPrecision p, TQualifier q, unsigned char ps, unsigne
secondarySize(ss),
mInterfaceBlock(0),
mStructure(0),
mIsStructSpecifier(false)
mIsStructSpecifier(false),
mMangledName(nullptr)
{
}
......@@ -170,7 +173,8 @@ TType::TType(const TPublicType &p)
secondarySize(p.getSecondarySize()),
mInterfaceBlock(nullptr),
mStructure(nullptr),
mIsStructSpecifier(false)
mIsStructSpecifier(false),
mMangledName(nullptr)
{
ASSERT(primarySize <= 4);
ASSERT(secondarySize <= 4);
......@@ -196,7 +200,8 @@ TType::TType(TStructure *userDef)
secondarySize(1),
mInterfaceBlock(nullptr),
mStructure(userDef),
mIsStructSpecifier(false)
mIsStructSpecifier(false),
mMangledName(nullptr)
{
}
......@@ -213,7 +218,8 @@ TType::TType(TInterfaceBlock *interfaceBlockIn,
secondarySize(1),
mInterfaceBlock(interfaceBlockIn),
mStructure(0),
mIsStructSpecifier(false)
mIsStructSpecifier(false),
mMangledName(nullptr)
{
}
......@@ -375,7 +381,7 @@ TString TType::getCompleteString() const
//
// Recursively generate mangled names.
//
TString TType::buildMangledName() const
const char *TType::buildMangledName() const
{
TString mangledName;
if (isMatrix())
......@@ -532,7 +538,12 @@ TString TType::buildMangledName() const
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 @@ void TType::setStruct(TStructure *s)
}
}
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::realize()
void TType::invalidateMangledName()
{
mMangledName = "";
mMangledName = nullptr;
}
// TStructure implementation.
......
......@@ -279,7 +279,7 @@ class TType
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 @@ class TType
private:
void invalidateMangledName();
TString buildMangledName() const;
const char *buildMangledName() const;
TBasicType type;
TPrecision precision;
......@@ -393,7 +393,7 @@ class TType
TStructure *mStructure;
bool mIsStructSpecifier;
mutable TString mMangledName;
mutable const char *mMangledName;
};
// TTypeSpecifierNonArray stores all of the necessary fields for type_specifier_nonarray from the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment