Make Angle code 40 KB smaller by using string literals directly.
The implicit conversion of hundreds of string literals
to TString generated a lot of machine code. By keeping them
as string literals all the way the code will be smaller and faster.
This is the change with clang for x64 (note VisitUnary in particular):
Total change: -41392 bytes
==========================
2 added, totalling +469 bytes across 1 sources
2 removed, totalling -472 bytes across 1 sources
5 shrunk, for a net change of -41389 bytes (54126 bytes before, 12737 bytes after) across 1 sources
279692 unchanged, totalling 51433327 bytes
------------------------------------------------------------------------------------------------------------------------------------
-41392 - Source: /home/bratell/src/chromium/src/third_party/angle/src/compiler/translator/OutputHLSL.cpp - (gained 469, lost 41861)
------------------------------------------------------------------------------------------------------------------------------------
New symbols:
+328: sh::OutputHLSL::outputConstructor(Visit, TType const&, char const*, TVector<TIntermNode*> const*) type=t, size=328 bytes
+141: sh::OutputHLSL::outputTriplet(Visit, char const*, char const*, char const*) type=t, size=141 bytes
Removed symbols:
-133: sh::OutputHLSL::outputTriplet(Visit, std::basic_string<char, std::char_traits<char>, pool_allocator<char> > const&, std::basic_string<char, std::char_traits<char>, pool_allocator<char> > const&, std::basic_string<char, std::char_traits<char>, pool_allocator<char> > const&) type=t, size=133 bytes
-339: sh::OutputHLSL::outputConstructor(Visit, TType const&, std::basic_string<char, std::char_traits<char>, pool_allocator<char> > const&, TVector<TIntermNode*> const*) type=t, size=339 bytes
Shrunk symbols:
-388: sh::OutputHLSL::writeEmulatedFunctionTriplet(Visit, char const*) type=t, (was 628 bytes, now 240 bytes)
-714: sh::OutputHLSL::visitBranch(Visit, TIntermBranch*) type=t, (was 1017 bytes, now 303 bytes)
-9738: sh::OutputHLSL::visitAggregate(Visit, TIntermAggregate*) type=t, (was 17609 bytes, now 7871 bytes)
-14132: sh::OutputHLSL::visitBinary(Visit, TIntermBinary*) type=t, (was 17627 bytes, now 3495 bytes)
-16417: sh::OutputHLSL::visitUnary(Visit, TIntermUnary*) type=t, (was 17245 bytes, now 828 bytes)
Change-Id: Id0f87d72f6d7f1ab7b543f0d28d5a8b7c7db9ec7
Reviewed-on: https://chromium-review.googlesource.com/251090
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: bratell at Opera <bratell@opera.com>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index 2a2c97c..2811a50 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -1558,7 +1558,7 @@
{
const TStructure &structure = *node->getLeft()->getType().getStruct();
const TString &functionName = addStructEqualityFunction(structure);
- outputTriplet(visit, functionName + "(", ", ", ")");
+ outputTriplet(visit, (functionName + "(").c_str(), ", ", ")");
}
else
{
@@ -2126,7 +2126,7 @@
{
const TString &structName = StructNameString(*node->getType().getStruct());
mStructureHLSL->addConstructor(node->getType(), structName, node->getSequence());
- outputTriplet(visit, structName + "_ctor(", ", ", ")");
+ outputTriplet(visit, (structName + "_ctor(").c_str(), ", ", ")");
}
break;
case EOpLessThan: outputTriplet(visit, "(", " < ", ")"); break;
@@ -2637,7 +2637,7 @@
return false; // Not handled as an excessive loop
}
-void OutputHLSL::outputTriplet(Visit visit, const TString &preString, const TString &inString, const TString &postString)
+void OutputHLSL::outputTriplet(Visit visit, const char *preString, const char *inString, const char *postString)
{
TInfoSinkBase &out = getInfoSink();
@@ -2715,7 +2715,7 @@
return "{" + string + "}";
}
-void OutputHLSL::outputConstructor(Visit visit, const TType &type, const TString &name, const TIntermSequence *parameters)
+void OutputHLSL::outputConstructor(Visit visit, const TType &type, const char *name, const TIntermSequence *parameters)
{
TInfoSinkBase &out = getInfoSink();
@@ -2723,7 +2723,7 @@
{
mStructureHLSL->addConstructor(type, name, parameters);
- out << name + "(";
+ out << name << "(";
}
else if (visit == InVisit)
{