Removed name string field from SkSLType

This field wasn't really necessary, and was just bloating Type and
causing a lot of extra String creation. This one change reduces the
size of a new Compiler by ~2.4KB.

Change-Id: Ie90c565d669d2caaa61056015ea2119fe61c1844
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/423298
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index fbb3962..093e3dd 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -1041,7 +1041,7 @@
         }
     }
     const Type* type = old->takeOwnershipOfSymbol(Type::MakeStructType(intf.fOffset,
-                                                                       String(id.fTypeName),
+                                                                       id.fTypeName,
                                                                        fields));
     int arraySize = 0;
     if (id.fIsArray) {
diff --git a/src/sksl/SkSLParser.cpp b/src/sksl/SkSLParser.cpp
index 114b287..9936d25 100644
--- a/src/sksl/SkSLParser.cpp
+++ b/src/sksl/SkSLParser.cpp
@@ -494,8 +494,7 @@
                     "struct '" + this->text(name) + "' must contain at least one field");
         return ASTNode::ID::Invalid();
     }
-    std::unique_ptr<Type> newType = Type::MakeStructType(name.fOffset, String(this->text(name)),
-                                                         fields);
+    std::unique_ptr<Type> newType = Type::MakeStructType(name.fOffset, this->text(name), fields);
     if (struct_is_too_deeply_nested(*newType, kMaxStructDepth)) {
         this->error(name.fOffset, "struct '" + this->text(name) + "' is too deeply nested");
         return ASTNode::ID::Invalid();
diff --git a/src/sksl/SkSLRehydrator.cpp b/src/sksl/SkSLRehydrator.cpp
index cd74ca2..c4679ef 100644
--- a/src/sksl/SkSLRehydrator.cpp
+++ b/src/sksl/SkSLRehydrator.cpp
@@ -153,8 +153,9 @@
             } else {
                 name += "[" + to_string(count) + "]";
             }
+            skstd::string_view nameChars(*fSymbolTable->takeOwnershipOfString(std::move(name)));
             const Type* result = fSymbolTable->takeOwnershipOfSymbol(
-                    Type::MakeArrayType(name, *componentType, count));
+                    Type::MakeArrayType(nameChars, *componentType, count));
             this->addSymbol(id, result);
             return result;
         }
@@ -199,8 +200,9 @@
                 const Type* type = this->type();
                 fields.emplace_back(m, fieldName, type);
             }
+            skstd::string_view nameChars(*fSymbolTable->takeOwnershipOfString(std::move(name)));
             const Type* result = fSymbolTable->takeOwnershipOfSymbol(
-                    Type::MakeStructType(/*offset=*/-1, name, std::move(fields)));
+                    Type::MakeStructType(/*offset=*/-1, nameChars, std::move(fields)));
             this->addSymbol(id, result);
             return result;
         }
diff --git a/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp b/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp
index cc3b978..d3d785d 100644
--- a/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp
@@ -3056,7 +3056,7 @@
             fProgram.fPool->attachToThread();
         }
         const Type* rtFlipStructType = fProgram.fSymbols->takeOwnershipOfSymbol(
-                Type::MakeStructType(type.fOffset, String(type.name()), std::move(fields)));
+                Type::MakeStructType(type.fOffset, type.name(), std::move(fields)));
         const Variable* modifiedVar = fProgram.fSymbols->takeOwnershipOfSymbol(
                 std::make_unique<Variable>(intfVar.fOffset,
                                            &intfVar.modifiers(),
@@ -3589,7 +3589,7 @@
                                   /*flags=*/0),
                         SKSL_RTFLIP_NAME,
                         fContext.fTypes.fFloat2.get());
-    String name("sksl_synthetic_uniforms");
+    skstd::string_view name = "sksl_synthetic_uniforms";
     const Type* intfStruct =
             fSynthetics.takeOwnershipOfSymbol(Type::MakeStructType(/*offset=*/-1, name, fields));
     int binding = fProgram.fConfig->fSettings.fRTFlipBinding;
@@ -3637,7 +3637,7 @@
     }
     InterfaceBlock intf(/*offset=*/-1,
                         intfVar,
-                        name,
+                        String(name),
                         /*instanceName=*/"",
                         /*arraySize=*/0,
                         std::make_shared<SymbolTable>(&fErrors, /*builtin=*/false));
diff --git a/src/sksl/dsl/DSLType.cpp b/src/sksl/dsl/DSLType.cpp
index 7a24797..cd62870 100644
--- a/src/sksl/dsl/DSLType.cpp
+++ b/src/sksl/dsl/DSLType.cpp
@@ -204,7 +204,7 @@
         skslFields.emplace_back(field.fModifiers.fModifiers, field.fName, &field.fType.skslType());
     }
     const SkSL::Type* result = DSLWriter::SymbolTable()->add(Type::MakeStructType(/*offset=*/-1,
-                                                                                  String(name),
+                                                                                  name,
                                                                                   skslFields));
     DSLWriter::ProgramElements().push_back(std::make_unique<SkSL::StructDefinition>(/*offset=*/-1,
                                                                                     *result));
diff --git a/src/sksl/ir/SkSLSymbolTable.cpp b/src/sksl/ir/SkSLSymbolTable.cpp
index 9d6dccc..57d1d46 100644
--- a/src/sksl/ir/SkSLSymbolTable.cpp
+++ b/src/sksl/ir/SkSLSymbolTable.cpp
@@ -127,8 +127,12 @@
         String arrayName = (arraySize != Type::kUnsizedArray)
                                    ? String::printf("%s[%d]", baseName.c_str(), arraySize)
                                    : String::printf("%s[]", baseName.c_str());
-        type = this->takeOwnershipOfSymbol(Type::MakeArrayType(std::move(arrayName),
-                                                               *type, arraySize));
+        SymbolTable* owner = this;
+        while (owner->fParent && !owner->fParent->fBuiltin) {
+            owner = owner->fParent.get();
+        }
+        skstd::string_view nameChars(*owner->takeOwnershipOfString(std::move(arrayName)));
+        type = this->takeOwnershipOfSymbol(Type::MakeArrayType(nameChars, *type, arraySize));
     }
     return type;
 }
diff --git a/src/sksl/ir/SkSLType.cpp b/src/sksl/ir/SkSLType.cpp
index 223945e..895db43 100644
--- a/src/sksl/ir/SkSLType.cpp
+++ b/src/sksl/ir/SkSLType.cpp
@@ -23,8 +23,8 @@
 public:
     static constexpr TypeKind kTypeKind = TypeKind::kArray;
 
-    ArrayType(String name, const char* abbrev, const Type& componentType, int count)
-        : INHERITED(std::move(name), abbrev, kTypeKind)
+    ArrayType(skstd::string_view name, const char* abbrev, const Type& componentType, int count)
+        : INHERITED(name, abbrev, kTypeKind)
         , fComponentType(componentType)
         , fCount(count) {
         // Allow either explicitly-sized or unsized arrays.
@@ -170,9 +170,9 @@
 public:
     static constexpr TypeKind kTypeKind = TypeKind::kMatrix;
 
-    MatrixType(String name, const char* abbrev, const Type& componentType, int8_t columns,
-               int8_t rows)
-        : INHERITED(std::move(name), abbrev, kTypeKind)
+    MatrixType(skstd::string_view name, const char* abbrev, const Type& componentType,
+               int8_t columns, int8_t rows)
+        : INHERITED(name, abbrev, kTypeKind)
         , fComponentType(componentType.as<ScalarType>())
         , fColumns(columns)
         , fRows(rows) {
@@ -293,7 +293,7 @@
 public:
     static constexpr TypeKind kTypeKind = TypeKind::kStruct;
 
-    StructType(int offset, String name, std::vector<Field> fields)
+    StructType(int offset, skstd::string_view name, std::vector<Field> fields)
         : INHERITED(std::move(name), "S", kTypeKind, offset)
         , fFields(std::move(fields)) {}
 
@@ -315,8 +315,9 @@
 public:
     static constexpr TypeKind kTypeKind = TypeKind::kVector;
 
-    VectorType(String name, const char* abbrev, const Type& componentType, int8_t columns)
-        : INHERITED(std::move(name), abbrev, kTypeKind)
+    VectorType(skstd::string_view name, const char* abbrev, const Type& componentType,
+               int8_t columns)
+        : INHERITED(name, abbrev, kTypeKind)
         , fComponentType(componentType.as<ScalarType>())
         , fColumns(columns) {
         SkASSERT(columns >= 2 && columns <= 4);
@@ -349,7 +350,8 @@
     int8_t fColumns;
 };
 
-std::unique_ptr<Type> Type::MakeArrayType(String name, const Type& componentType, int columns) {
+std::unique_ptr<Type> Type::MakeArrayType(skstd::string_view name, const Type& componentType,
+                                          int columns) {
     return std::make_unique<ArrayType>(std::move(name), componentType.abbreviatedName(),
                                        componentType, columns);
 }
@@ -384,7 +386,8 @@
 
 }
 
-std::unique_ptr<Type> Type::MakeStructType(int offset, String name, std::vector<Field> fields) {
+std::unique_ptr<Type> Type::MakeStructType(int offset, skstd::string_view name,
+                                           std::vector<Field> fields) {
     return std::make_unique<StructType>(offset, std::move(name), std::move(fields));
 }
 
@@ -589,12 +592,12 @@
     // This type actually needs to be cloned into the destination SymbolTable.
     switch (this->typeKind()) {
         case TypeKind::kArray:
-            return symbolTable->add(Type::MakeArrayType(String(this->name()), this->componentType(),
-                                                               this->columns()));
+            return symbolTable->add(Type::MakeArrayType(this->name(), this->componentType(),
+                                                        this->columns()));
 
         case TypeKind::kStruct:
             return symbolTable->add(std::make_unique<StructType>(this->fOffset,
-                                                                 String(this->name()),
+                                                                 this->name(),
                                                                  this->fields()));
 
         default:
diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h
index be05dcf..1c64c00 100644
--- a/src/sksl/ir/SkSLType.h
+++ b/src/sksl/ir/SkSLType.h
@@ -8,6 +8,7 @@
 #ifndef SKSL_TYPE
 #define SKSL_TYPE
 
+#include "include/core/SkStringView.h"
 #include "include/private/SkSLModifiers.h"
 #include "include/private/SkSLSymbol.h"
 #include "src/sksl/SkSLPosition.h"
@@ -106,7 +107,8 @@
 
     /** Creates an array type. */
     static constexpr int kUnsizedArray = -1;
-    static std::unique_ptr<Type> MakeArrayType(String name, const Type& componentType, int columns);
+    static std::unique_ptr<Type> MakeArrayType(skstd::string_view name, const Type& componentType,
+                                               int columns);
 
     /**
      * Create a generic type which maps to the listed types--e.g. $genType is a generic type which
@@ -138,7 +140,8 @@
                                                  Type::TypeKind typeKind);
 
     /** Creates a struct type with the given fields. */
-    static std::unique_ptr<Type> MakeStructType(int offset, String name, std::vector<Field> fields);
+    static std::unique_ptr<Type> MakeStructType(int offset, skstd::string_view name,
+                                                std::vector<Field> fields);
 
     /** Create a texture type. */
     static std::unique_ptr<Type> MakeTextureType(const char* name, SpvDim_ dimensions,
@@ -518,11 +521,9 @@
     bool checkForOutOfRangeLiteral(const Context& context, const Expression& expr) const;
 
 protected:
-    Type(String name, const char* abbrev, TypeKind kind, int offset = -1)
-        : INHERITED(offset, kSymbolKind, /*name=*/"")
-        , fNameString(std::move(name))
+    Type(skstd::string_view name, const char* abbrev, TypeKind kind, int offset = -1)
+        : INHERITED(offset, kSymbolKind, name)
         , fTypeKind(kind) {
-        fName = fNameString;
         SkASSERT(strlen(abbrev) <= kMaxAbbrevLength);
         strcpy(fAbbreviatedName, abbrev);
     }
@@ -532,7 +533,6 @@
 
     using INHERITED = Symbol;
 
-    String fNameString;
     char fAbbreviatedName[kMaxAbbrevLength + 1] = {};
     TypeKind fTypeKind;
 };