Removed SkSL::StringFragment in favor of string_view
This CL preserves the "StringFragment" name as an alias for
string_view to reduce the impact. The StringFragment alias
will be removed in a followup CL.
Change-Id: I89209bc626b0be0d0190823b6217f4c83cafe1bc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/416736
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/codegen/SkSLMetalCodeGenerator.cpp b/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
index c818374..c8bc3b2 100644
--- a/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
@@ -38,14 +38,14 @@
class MetalCodeGenerator::GlobalStructVisitor {
public:
virtual ~GlobalStructVisitor() = default;
- virtual void visitInterfaceBlock(const InterfaceBlock& block, const String& blockName) = 0;
- virtual void visitTexture(const Type& type, const String& name) = 0;
- virtual void visitSampler(const Type& type, const String& name) = 0;
+ virtual void visitInterfaceBlock(const InterfaceBlock& block, StringFragment blockName) = 0;
+ virtual void visitTexture(const Type& type, StringFragment name) = 0;
+ virtual void visitSampler(const Type& type, StringFragment name) = 0;
virtual void visitVariable(const Variable& var, const Expression* value) = 0;
};
-void MetalCodeGenerator::write(const char* s) {
- if (!s[0]) {
+void MetalCodeGenerator::write(StringFragment s) {
+ if (s.empty()) {
return;
}
if (fAtLineStart) {
@@ -53,24 +53,12 @@
fOut->writeText(" ");
}
}
- fOut->writeText(s);
+ fOut->writeText(String(s).c_str());
fAtLineStart = false;
}
-void MetalCodeGenerator::writeLine(const char* s) {
+void MetalCodeGenerator::writeLine(StringFragment s) {
this->write(s);
- this->writeLine();
-}
-
-void MetalCodeGenerator::write(const String& s) {
- this->write(s.c_str());
-}
-
-void MetalCodeGenerator::writeLine(const String& s) {
- this->writeLine(s.c_str());
-}
-
-void MetalCodeGenerator::writeLine() {
fOut->writeText(fLineEnding);
fAtLineStart = true;
}
@@ -108,9 +96,9 @@
default:
if (type == *fContext.fTypes.fHalf) {
// FIXME - Currently only supporting floats in MSL to avoid type coercion issues.
- return fContext.fTypes.fFloat->name();
+ return String(fContext.fTypes.fFloat->name());
} else {
- return type.name();
+ return String(type.name());
}
}
}
@@ -1872,7 +1860,7 @@
this->writeExpression(value, Precedence::kTopLevel);
}
-void MetalCodeGenerator::writeName(const String& name) {
+void MetalCodeGenerator::writeName(StringFragment name) {
if (fReservedWords.find(name) != fReservedWords.end()) {
this->write("_"); // adding underscore before name to avoid conflict with reserved words
}
@@ -2207,7 +2195,7 @@
if (var.type().typeKind() == Type::TypeKind::kSampler) {
// Samplers are represented as a "texture/sampler" duo in the global struct.
visitor->visitTexture(var.type(), var.name());
- visitor->visitSampler(var.type(), String(var.name()) + SAMPLER_SUFFIX);
+ visitor->visitSampler(var.type(), var.name() + SAMPLER_SUFFIX);
continue;
}
@@ -2222,7 +2210,7 @@
void MetalCodeGenerator::writeGlobalStruct() {
class : public GlobalStructVisitor {
public:
- void visitInterfaceBlock(const InterfaceBlock& block, const String& blockName) override {
+ void visitInterfaceBlock(const InterfaceBlock& block, StringFragment blockName) override {
this->addElement();
fCodeGen->write(" constant ");
fCodeGen->write(block.typeName());
@@ -2230,7 +2218,7 @@
fCodeGen->writeName(blockName);
fCodeGen->write(";\n");
}
- void visitTexture(const Type& type, const String& name) override {
+ void visitTexture(const Type& type, StringFragment name) override {
this->addElement();
fCodeGen->write(" ");
fCodeGen->writeType(type);
@@ -2238,7 +2226,7 @@
fCodeGen->writeName(name);
fCodeGen->write(";\n");
}
- void visitSampler(const Type&, const String& name) override {
+ void visitSampler(const Type&, StringFragment name) override {
this->addElement();
fCodeGen->write(" sampler ");
fCodeGen->writeName(name);
@@ -2279,16 +2267,16 @@
class : public GlobalStructVisitor {
public:
void visitInterfaceBlock(const InterfaceBlock& blockType,
- const String& blockName) override {
+ StringFragment blockName) override {
this->addElement();
fCodeGen->write("&");
fCodeGen->writeName(blockName);
}
- void visitTexture(const Type&, const String& name) override {
+ void visitTexture(const Type&, StringFragment name) override {
this->addElement();
fCodeGen->writeName(name);
}
- void visitSampler(const Type&, const String& name) override {
+ void visitSampler(const Type&, StringFragment name) override {
this->addElement();
fCodeGen->writeName(name);
}