Store symbol names as a ImmutableString
This will enable compile-time initialization of built-in symbols as
well as reducing copying strings.
Most of the code that deals with names is changed to use
ImmutableString where it makes sense to avoid conversions.
The lexer/parser now allocate const char pointers into pool memory
instead of allocating TStrings. These are then converted to
ImmutableString upon entering TParseContext.
BUG=angleproject:2267
TEST=angle_unittests, angle_end2end_tests
Change-Id: I244d6271ea1ecf7150d4f89dfa388a7745a1150c
Reviewed-on: https://chromium-review.googlesource.com/881561
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index 55c57c9..6f59129 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -371,7 +371,8 @@
if (mappedStruct.blockDeclarator->variable().symbolType() != SymbolType::Empty)
{
- const TString &instanceName = mappedStruct.blockDeclarator->variable().name();
+ const ImmutableString &instanceName =
+ mappedStruct.blockDeclarator->variable().name();
unsigned int instanceStringArrayIndex = GL_INVALID_INDEX;
if (isInstanceArray)
instanceStringArrayIndex = instanceArrayIndex;
@@ -415,7 +416,7 @@
for (const auto &varying : mReferencedVaryings)
{
const TType &type = varying.second->getType();
- const TString &name = varying.second->name();
+ const ImmutableString &name = varying.second->name();
// Program linking depends on this exact format
varyings += "static " + InterpolationString(type.getQualifier()) + " " + TypeString(type) +
@@ -426,7 +427,7 @@
for (const auto &attribute : mReferencedAttributes)
{
const TType &type = attribute.second->getType();
- const TString &name = attribute.second->name();
+ const ImmutableString &name = attribute.second->name();
attributes += "static " + TypeString(type) + " " + Decorate(name) + ArrayString(type) +
" = " + zeroInitializer(type) + ";\n";
@@ -498,12 +499,11 @@
{
for (const auto &outputVariable : mReferencedOutputVariables)
{
- const TString &variableName = outputVariable.second->name();
+ const ImmutableString &variableName = outputVariable.second->name();
const TType &variableType = outputVariable.second->getType();
- out << "static " + TypeString(variableType) + " out_" + variableName +
- ArrayString(variableType) + " = " + zeroInitializer(variableType) +
- ";\n";
+ out << "static " << TypeString(variableType) << " out_" << variableName
+ << ArrayString(variableType) << " = " << zeroInitializer(variableType) << ";\n";
}
}
else
@@ -883,7 +883,7 @@
out << "map";
}
- const TString &name = variable.name();
+ const ImmutableString &name = variable.name();
const TSymbolUniqueId &uniqueId = variable.uniqueId();
if (name == "gl_DepthRange")
@@ -1314,11 +1314,11 @@
{
if (indexingReturnsSampler)
{
- out << "_" + field->name();
+ out << "_" << field->name();
}
else
{
- out << "." + DecorateField(field->name(), *structure);
+ out << "." << DecorateField(field->name(), *structure);
}
return false;
@@ -1661,7 +1661,7 @@
return true;
}
-TString OutputHLSL::samplerNamePrefixFromStruct(TIntermTyped *node)
+ImmutableString OutputHLSL::samplerNamePrefixFromStruct(TIntermTyped *node)
{
if (node->getAsSymbolNode())
{
@@ -1675,9 +1675,9 @@
{
int index = nodeBinary->getRight()->getAsConstantUnion()->getIConst(0);
- TInfoSinkBase prefixSink;
+ std::stringstream prefixSink;
prefixSink << samplerNamePrefixFromStruct(nodeBinary->getLeft()) << "_" << index;
- return TString(prefixSink.c_str());
+ return ImmutableString(prefixSink.str());
}
case EOpIndexDirectStruct:
{
@@ -1685,14 +1685,14 @@
int index = nodeBinary->getRight()->getAsConstantUnion()->getIConst(0);
const TField *field = s->fields()[index];
- TInfoSinkBase prefixSink;
+ std::stringstream prefixSink;
prefixSink << samplerNamePrefixFromStruct(nodeBinary->getLeft()) << "_"
<< field->name();
- return TString(prefixSink.c_str());
+ return ImmutableString(prefixSink.str());
}
default:
UNREACHABLE();
- return TString("");
+ return ImmutableString("");
}
}
@@ -1951,16 +1951,16 @@
}
else if (node->getFunction()->isImageFunction())
{
- const TString &name = node->getFunction()->name();
+ const ImmutableString &name = node->getFunction()->name();
TType type = (*arguments)[0]->getAsTyped()->getType();
- TString imageFunctionName = mImageFunctionHLSL->useImageFunction(
+ TString imageFunctionName = mImageFunctionHLSL->useImageFunction(
name, type.getBasicType(), type.getLayoutQualifier().imageInternalFormat,
type.getMemoryQualifier().readonly);
out << imageFunctionName << "(";
}
else
{
- const TString &name = node->getFunction()->name();
+ const ImmutableString &name = node->getFunction()->name();
TBasicType samplerType = (*arguments)[0]->getAsTyped()->getType().getBasicType();
int coords = 0; // textureSize(gsampler2DMS) doesn't have a second argument.
if (arguments->size() > 1)
@@ -1988,8 +1988,10 @@
{
const TType &argType = typedArg->getType();
TVector<const TVariable *> samplerSymbols;
- TString structName = samplerNamePrefixFromStruct(typedArg);
- argType.createSamplerSymbols("angle_" + structName, "", &samplerSymbols,
+ ImmutableString structName = samplerNamePrefixFromStruct(typedArg);
+ std::string namePrefix = "angle_";
+ namePrefix += structName.data();
+ argType.createSamplerSymbols(ImmutableString(namePrefix), "", &samplerSymbols,
nullptr, mSymbolTable);
for (const TVariable *sampler : samplerSymbols)
{
@@ -2002,7 +2004,7 @@
{
// In case of HLSL 4.1+, this symbol is the sampler index, and in case
// of D3D9, it's the sampler variable.
- out << ", " + sampler->name();
+ out << ", " << sampler->name();
}
}
}
@@ -2683,7 +2685,10 @@
{
ASSERT(qualifier != EvqOut && qualifier != EvqInOut);
TVector<const TVariable *> samplerSymbols;
- type.createSamplerSymbols("angle" + nameStr, "", &samplerSymbols, nullptr, mSymbolTable);
+ std::string namePrefix = "angle";
+ namePrefix += nameStr.c_str();
+ type.createSamplerSymbols(ImmutableString(namePrefix), "", &samplerSymbols, nullptr,
+ mSymbolTable);
for (const TVariable *sampler : samplerSymbols)
{
const TType &samplerType = sampler->getType();