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/RemoveDynamicIndexing.cpp b/src/compiler/translator/RemoveDynamicIndexing.cpp
index 184c711..155e3d1 100644
--- a/src/compiler/translator/RemoveDynamicIndexing.cpp
+++ b/src/compiler/translator/RemoveDynamicIndexing.cpp
@@ -25,6 +25,10 @@
const TType *kIndexType = StaticType::Get<EbtInt, EbpHigh, EvqIn, 1, 1>();
+constexpr const ImmutableString kBaseName("base");
+constexpr const ImmutableString kIndexName("index");
+constexpr const ImmutableString kValueName("value");
+
std::string GetIndexFunctionName(const TType &type, bool write)
{
TInfoSinkBase nameSink;
@@ -291,10 +295,6 @@
bool mRemoveIndexSideEffectsInSubtree;
PerformanceDiagnostics *mPerfDiagnostics;
-
- const TString *mBaseName;
- const TString *mIndexName;
- const TString *mValueName;
};
RemoveDynamicIndexingTraverser::RemoveDynamicIndexingTraverser(
@@ -303,10 +303,7 @@
: TLValueTrackingTraverser(true, false, false, symbolTable),
mUsedTreeInsertion(false),
mRemoveIndexSideEffectsInSubtree(false),
- mPerfDiagnostics(perfDiagnostics),
- mBaseName(NewPoolTString("base")),
- mIndexName(NewPoolTString("index")),
- mValueName(NewPoolTString("value"))
+ mPerfDiagnostics(perfDiagnostics)
{
}
@@ -404,8 +401,7 @@
#endif
const TType &type = node->getLeft()->getType();
- TString *indexingFunctionName =
- NewPoolTString(GetIndexFunctionName(type, false).c_str());
+ ImmutableString indexingFunctionName(GetIndexFunctionName(type, false));
TFunction *indexingFunction = nullptr;
if (mIndexedVecAndMatrixTypes.find(type) == mIndexedVecAndMatrixTypes.end())
{
@@ -413,8 +409,8 @@
new TFunction(mSymbolTable, indexingFunctionName, GetFieldType(type),
SymbolType::AngleInternal, true);
indexingFunction->addParameter(
- TConstParameter(mBaseName, GetBaseType(type, false)));
- indexingFunction->addParameter(TConstParameter(mIndexName, kIndexType));
+ TConstParameter(kBaseName, GetBaseType(type, false)));
+ indexingFunction->addParameter(TConstParameter(kIndexName, kIndexType));
mIndexedVecAndMatrixTypes[type] = indexingFunction;
}
else
@@ -457,18 +453,18 @@
TFunction *indexedWriteFunction = nullptr;
if (mWrittenVecAndMatrixTypes.find(type) == mWrittenVecAndMatrixTypes.end())
{
- TString *functionName = NewPoolTString(
- GetIndexFunctionName(node->getLeft()->getType(), true).c_str());
+ ImmutableString functionName(
+ GetIndexFunctionName(node->getLeft()->getType(), true));
indexedWriteFunction =
new TFunction(mSymbolTable, functionName, StaticType::GetBasic<EbtVoid>(),
SymbolType::AngleInternal, false);
indexedWriteFunction->addParameter(
- TConstParameter(mBaseName, GetBaseType(type, true)));
- indexedWriteFunction->addParameter(TConstParameter(mIndexName, kIndexType));
+ TConstParameter(kBaseName, GetBaseType(type, true)));
+ indexedWriteFunction->addParameter(TConstParameter(kIndexName, kIndexType));
TType *valueType = GetFieldType(type);
valueType->setQualifier(EvqIn);
indexedWriteFunction->addParameter(
- TConstParameter(mValueName, static_cast<const TType *>(valueType)));
+ TConstParameter(kValueName, static_cast<const TType *>(valueType)));
mWrittenVecAndMatrixTypes[type] = indexedWriteFunction;
}
else