Update `nameVariable` to return the variable name directly.
Previously, the generated name was passed back in a SkString-pointer
output parameter. Directly returning the SkString simplified nearly
every call site, and made none of them worse.
Change-Id: Ied57adcf8fb087a301641adad437d8a68f8d3297
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/329622
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index 31e5408..87b5c2e 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -288,19 +288,20 @@
}
#endif
-void GrGLSLProgramBuilder::nameVariable(SkString* out, char prefix, const char* name, bool mangle) {
+SkString GrGLSLProgramBuilder::nameVariable(char prefix, const char* name, bool mangle) {
+ SkString out;
if ('\0' == prefix) {
- *out = name;
+ out = name;
} else {
- out->printf("%c%s", prefix, name);
+ out.printf("%c%s", prefix, name);
}
if (mangle) {
- if (out->endsWith('_')) {
- // Names containing "__" are reserved.
- out->append("x");
- }
- out->appendf("_Stage%d%s", fStageIndex, fFS.getMangleString().c_str());
+ // Names containing "__" are reserved; add "x" if needed to avoid consecutive underscores.
+ const char *underscoreSplitter = out.endsWith('_') ? "x" : "";
+
+ out.appendf("%s_Stage%d%s", underscoreSplitter, fStageIndex, fFS.getMangleString().c_str());
}
+ return out;
}
void GrGLSLProgramBuilder::nameExpression(SkString* output, const char* baseName) {
@@ -311,7 +312,7 @@
if (output->size()) {
outName = output->c_str();
} else {
- this->nameVariable(&outName, '\0', baseName);
+ outName = this->nameVariable(/*prefix=*/'\0', baseName);
}
fFS.codeAppendf("half4 %s;", outName.c_str());
*output = outName;