Take ownership of Strings (not String pointers) in the symbol table.

Every caller of SymbolTable::takeOwnershipOfString was allocating a
unique_ptr<String> instead of just moving the String object directly.
This was important, as the SymbolTable needed to return a stable String
pointer to the caller, and vector<String> is allowed to move its
elements around when it is resized.

On the other hand, deque<String> promises pointer stability even after a
resize. Replacing the vector with a deque lets us avoid allocating an
extra String object every time we call takeOwnershipOfString.

Change-Id: I8947c0900fd355c940b046a52a4c1762465b55d3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/386596
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLInliner.cpp b/src/sksl/SkSLInliner.cpp
index 6246c74..dbe5783 100644
--- a/src/sksl/SkSLInliner.cpp
+++ b/src/sksl/SkSLInliner.cpp
@@ -492,13 +492,12 @@
             // We assign unique names to inlined variables--scopes hide most of the problems in this
             // regard, but see `InlinerAvoidsVariableNameOverlap` for a counterexample where unique
             // names are important.
-            auto name = std::make_unique<String>(fMangler.uniqueName(variable.name(),
-                                                                     symbolTableForStatement));
-            const String* namePtr = symbolTableForStatement->takeOwnershipOfString(std::move(name));
+            const String* name = symbolTableForStatement->takeOwnershipOfString(
+                    fMangler.uniqueName(variable.name(), symbolTableForStatement));
             auto clonedVar = std::make_unique<Variable>(
                                                      offset,
                                                      &variable.modifiers(),
-                                                     namePtr->c_str(),
+                                                     name->c_str(),
                                                      variable.type().clone(symbolTableForStatement),
                                                      isBuiltinCode,
                                                      variable.storage());
@@ -535,15 +534,14 @@
     SkASSERT(!(modifiers.fFlags & Modifiers::kOut_Flag));
 
     // Provide our new variable with a unique name, and add it to our symbol table.
-    const String* namePtr = symbolTable->takeOwnershipOfString(
-            std::make_unique<String>(fMangler.uniqueName(baseName, symbolTable)));
-    StringFragment nameFrag{namePtr->c_str(), namePtr->length()};
+    const String* name =
+            symbolTable->takeOwnershipOfString(fMangler.uniqueName(baseName, symbolTable));
 
     // Create our new variable and add it to the symbol table.
     InlineVariable result;
     auto var = std::make_unique<Variable>(/*offset=*/-1,
                                           fModifiers->addToPool(Modifiers()),
-                                          nameFrag,
+                                          name->c_str(),
                                           type,
                                           isBuiltinCode,
                                           Variable::Storage::kLocal);