Commit 58832204 by Dmitry Skiba Committed by Jamie Madill

Calculate TFunction::mangledName lazily.

This saves us ~15KiB per compiler instance on 32-bit Android. BUG=492725 Change-Id: I9db2998482941b5ab2eb5cb4925cbd1fb58ab4be Reviewed-on: https://chromium-review.googlesource.com/283584Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 26a10f9d
...@@ -29,6 +29,18 @@ TFunction::~TFunction() ...@@ -29,6 +29,18 @@ TFunction::~TFunction()
delete (*i).type; delete (*i).type;
} }
const TString *TFunction::buildMangledName() const
{
std::string mangledName = mangleName(getName()).c_str();
for (const auto &p : parameters)
{
mangledName += p.type->getMangledName().c_str();
}
return NewPoolTString(mangledName.c_str());
}
// //
// Symbol table levels are a map of pointers to symbols that have to be deleted. // Symbol table levels are a map of pointers to symbols that have to be deleted.
// //
......
...@@ -223,7 +223,7 @@ class TFunction : public TSymbol ...@@ -223,7 +223,7 @@ class TFunction : public TSymbol
TFunction(const TString *name, const TType *retType, TOperator tOp = EOpNull, const char *ext = "") TFunction(const TString *name, const TType *retType, TOperator tOp = EOpNull, const char *ext = "")
: TSymbol(name), : TSymbol(name),
returnType(retType), returnType(retType),
mangledName(TFunction::mangleName(*name)), mangledName(nullptr),
op(tOp), op(tOp),
defined(false) defined(false)
{ {
...@@ -245,14 +245,18 @@ class TFunction : public TSymbol ...@@ -245,14 +245,18 @@ class TFunction : public TSymbol
} }
void addParameter(const TConstParameter &p) void addParameter(const TConstParameter &p)
{ {
parameters.push_back(p); parameters.push_back(p);
mangledName = mangledName + p.type->getMangledName(); mangledName = nullptr;
} }
const TString &getMangledName() const const TString &getMangledName() const
{ {
return mangledName; if (mangledName == nullptr)
{
mangledName = buildMangledName();
}
return *mangledName;
} }
const TType &getReturnType() const const TType &getReturnType() const
{ {
...@@ -283,10 +287,12 @@ class TFunction : public TSymbol ...@@ -283,10 +287,12 @@ class TFunction : public TSymbol
} }
private: private:
const TString *buildMangledName() const;
typedef TVector<TConstParameter> TParamList; typedef TVector<TConstParameter> TParamList;
TParamList parameters; TParamList parameters;
const TType *returnType; const TType *returnType;
TString mangledName; mutable const TString *mangledName;
TOperator op; TOperator op;
bool defined; bool defined;
}; };
......
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