Switched SkSLSetting over to using StringFragment

Change-Id: Ic089c867f292e47f5f5835f5a90c61d42e50ba07
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/417197
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2021-06-09 14:02:52 -04:00 committed by Skia Commit-Bot
parent d2b8ba3369
commit b60356169b
4 changed files with 10 additions and 8 deletions

View File

@ -534,7 +534,8 @@ void CPPCodeGenerator::writeFunction(const FunctionDefinition& f) {
}
void CPPCodeGenerator::writeSetting(const Setting& s) {
this->writef("sk_Caps.%s", s.name().c_str());
this->write("sk_Caps.");
this->write(s.name());
}
bool CPPCodeGenerator::writeSection(const char* name, const char* prefix) {

View File

@ -842,7 +842,8 @@ void DSLCPPCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
}
void DSLCPPCodeGenerator::writeSetting(const Setting& s) {
this->writef("sk_Caps.%s", s.name().c_str());
this->write("sk_Caps.");
this->write(s.name());
}
bool DSLCPPCodeGenerator::writeSection(const char* name, const char* prefix) {

View File

@ -112,7 +112,7 @@ static const Type* get_type(const Context& context, int offset, const String& na
}
static std::unique_ptr<Expression> get_value(const Context& context, int offset,
const String& name) {
const StringFragment& name) {
if (const CapsLookupMethod* caps = caps_lookup_table().lookup(name)) {
return caps->value(context);
}
@ -122,7 +122,7 @@ static std::unique_ptr<Expression> get_value(const Context& context, int offset,
}
std::unique_ptr<Expression> Setting::Convert(const Context& context, int offset,
const String& name) {
const StringFragment& name) {
SkASSERT(context.fConfig);
if (context.fConfig->fSettings.fReplaceSettings) {

View File

@ -22,7 +22,7 @@ class Setting final : public Expression {
public:
static constexpr Kind kExpressionKind = Kind::kSetting;
Setting(int offset, String name, const Type* type)
Setting(int offset, StringFragment name, const Type* type)
: INHERITED(offset, kExpressionKind, type)
, fName(std::move(name)) {}
@ -31,13 +31,13 @@ public:
// (There's no failsafe Make equivalent, because there really isn't a good fallback expression
// to produce when the `name` lookup fails. We wouldn't even know the expected type.)
static std::unique_ptr<Expression> Convert(const Context& context, int offset,
const String& name);
const StringFragment& name);
std::unique_ptr<Expression> clone() const override {
return std::make_unique<Setting>(fOffset, this->name(), &this->type());
}
const String& name() const {
const StringFragment& name() const {
return fName;
}
@ -50,7 +50,7 @@ public:
}
private:
String fName;
StringFragment fName;
using INHERITED = Expression;
};