Add ExpressionArray variants to DSL calls
This allows us to reduce the number of temporary arrays being created by going directly to the final array type. Change-Id: I6161c663f7f69ed1d323ae05b4a92b2d0c1b4c04 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/447194 Reviewed-by: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
parent
d532a9e544
commit
9a1f92e4ff
@ -122,6 +122,9 @@ public:
|
||||
DSLPossibleExpression operator()(SkTArray<DSLWrapper<DSLExpression>> args,
|
||||
PositionInfo pos = PositionInfo::Capture());
|
||||
|
||||
DSLPossibleExpression operator()(ExpressionArray args,
|
||||
PositionInfo pos = PositionInfo::Capture());
|
||||
|
||||
/**
|
||||
* Returns true if this object contains an expression. DSLExpressions which were created with
|
||||
* the empty constructor or which have already been release()ed do not have a value.
|
||||
@ -269,6 +272,9 @@ public:
|
||||
DSLPossibleExpression operator()(SkTArray<DSLWrapper<DSLExpression>> args,
|
||||
PositionInfo pos = PositionInfo::Capture());
|
||||
|
||||
DSLPossibleExpression operator()(ExpressionArray args,
|
||||
PositionInfo pos = PositionInfo::Capture());
|
||||
|
||||
DSLPossibleExpression operator++();
|
||||
|
||||
DSLPossibleExpression operator++(int);
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
*/
|
||||
template<class... Args>
|
||||
DSLExpression operator()(Args&&... args) {
|
||||
SkTArray<DSLWrapper<DSLExpression>> argArray;
|
||||
ExpressionArray argArray;
|
||||
argArray.reserve_back(sizeof...(args));
|
||||
this->collectArgs(argArray, std::forward<Args>(args)...);
|
||||
return this->call(std::move(argArray));
|
||||
@ -84,20 +84,20 @@ public:
|
||||
*/
|
||||
DSLExpression call(SkTArray<DSLWrapper<DSLExpression>> args);
|
||||
|
||||
DSLExpression call(ExpressionArray args);
|
||||
|
||||
private:
|
||||
void collectArgs(SkTArray<DSLWrapper<DSLExpression>>& args) {}
|
||||
void collectArgs(ExpressionArray& args) {}
|
||||
|
||||
template<class... RemainingArgs>
|
||||
void collectArgs(SkTArray<DSLWrapper<DSLExpression>>& args, DSLVar& var,
|
||||
RemainingArgs&&... remaining) {
|
||||
args.push_back(DSLWrapper<DSLExpression>(var));
|
||||
void collectArgs(ExpressionArray& args, DSLVar& var, RemainingArgs&&... remaining) {
|
||||
args.push_back(DSLExpression(var).release());
|
||||
collectArgs(args, std::forward<RemainingArgs>(remaining)...);
|
||||
}
|
||||
|
||||
template<class... RemainingArgs>
|
||||
void collectArgs(SkTArray<DSLWrapper<DSLExpression>>& args, DSLExpression expr,
|
||||
RemainingArgs&&... remaining) {
|
||||
args.push_back(DSLWrapper<DSLExpression>(std::move(expr)));
|
||||
void collectArgs(ExpressionArray& args, DSLExpression expr, RemainingArgs&&... remaining) {
|
||||
args.push_back(expr.release());
|
||||
collectArgs(args, std::forward<RemainingArgs>(remaining)...);
|
||||
}
|
||||
|
||||
|
@ -1577,7 +1577,7 @@ skstd::optional<DSLWrapper<DSLExpression>> DSLParser::swizzle(int offset, DSLExp
|
||||
}
|
||||
|
||||
skstd::optional<dsl::Wrapper<dsl::DSLExpression>> DSLParser::call(int offset,
|
||||
dsl::DSLExpression base, SkTArray<Wrapper<DSLExpression>> args) {
|
||||
dsl::DSLExpression base, ExpressionArray args) {
|
||||
return {{DSLExpression(base(std::move(args), this->position(offset)), this->position(offset))}};
|
||||
}
|
||||
|
||||
@ -1633,14 +1633,14 @@ skstd::optional<DSLWrapper<DSLExpression>> DSLParser::suffix(DSLExpression base)
|
||||
return this->swizzle(next.fOffset, std::move(base), field);
|
||||
}
|
||||
case Token::Kind::TK_LPAREN: {
|
||||
SkTArray<Wrapper<DSLExpression>> args;
|
||||
ExpressionArray args;
|
||||
if (this->peek().fKind != Token::Kind::TK_RPAREN) {
|
||||
for (;;) {
|
||||
skstd::optional<DSLWrapper<DSLExpression>> expr = this->assignmentExpression();
|
||||
if (!expr) {
|
||||
return skstd::nullopt;
|
||||
}
|
||||
args.push_back(std::move(*expr));
|
||||
args.push_back((**expr).release());
|
||||
if (!this->checkNext(Token::Kind::TK_COMMA)) {
|
||||
break;
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ private:
|
||||
skstd::string_view swizzleMask);
|
||||
|
||||
skstd::optional<dsl::Wrapper<dsl::DSLExpression>> call(int offset, dsl::DSLExpression base,
|
||||
SkTArray<dsl::Wrapper<dsl::DSLExpression>> args);
|
||||
ExpressionArray args);
|
||||
|
||||
skstd::optional<dsl::Wrapper<dsl::DSLExpression>> suffix(dsl::DSLExpression base);
|
||||
|
||||
|
@ -185,6 +185,10 @@ DSLPossibleExpression DSLExpression::operator()(SkTArray<DSLWrapper<DSLExpressio
|
||||
return DSLWriter::Call(this->release(), std::move(converted), pos);
|
||||
}
|
||||
|
||||
DSLPossibleExpression DSLExpression::operator()(ExpressionArray args, PositionInfo pos) {
|
||||
return DSLWriter::Call(this->release(), std::move(args), pos);
|
||||
}
|
||||
|
||||
#define OP(op, token) \
|
||||
DSLPossibleExpression operator op(DSLExpression left, DSLExpression right) { \
|
||||
return DSLWriter::ConvertBinary(left.release(), SkSL::Token::Kind::token, right.release()); \
|
||||
@ -353,6 +357,10 @@ DSLPossibleExpression DSLPossibleExpression::operator()(SkTArray<DSLWrapper<DSLE
|
||||
return DSLExpression(this->release())(std::move(args), pos);
|
||||
}
|
||||
|
||||
DSLPossibleExpression DSLPossibleExpression::operator()(ExpressionArray args, PositionInfo pos) {
|
||||
return DSLExpression(this->release())(std::move(args), pos);
|
||||
}
|
||||
|
||||
DSLPossibleExpression DSLPossibleExpression::operator++() {
|
||||
return ++DSLExpression(this->release());
|
||||
}
|
||||
|
@ -113,7 +113,11 @@ DSLExpression DSLFunction::call(SkTArray<DSLWrapper<DSLExpression>> args) {
|
||||
for (DSLWrapper<DSLExpression>& arg : args) {
|
||||
released.push_back(arg->release());
|
||||
}
|
||||
std::unique_ptr<SkSL::Expression> result = DSLWriter::Call(*fDecl, std::move(released));
|
||||
return this->call(std::move(released));
|
||||
}
|
||||
|
||||
DSLExpression DSLFunction::call(ExpressionArray args) {
|
||||
std::unique_ptr<SkSL::Expression> result = DSLWriter::Call(*fDecl, std::move(args));
|
||||
return result ? DSLExpression(std::move(result)) : DSLExpression();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user