improved performance of parsing SkSLLayout flags

BUG=skia:

Change-Id: Ib0e1393fb44f5f934ad2f88fed638ef7a0fa7393
Reviewed-on: https://skia-review.googlesource.com/8463
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2017-02-15 12:33:30 -05:00 committed by Skia Commit-Bot
parent 169f37f6c5
commit 3614d9adb3
2 changed files with 73 additions and 23 deletions

View File

@ -111,6 +111,18 @@ Parser::Parser(SkString text, SymbolTable& types, ErrorReporter& errors)
// avoid unused warning
yyunput(0, nullptr, fScanner);
}
fLayoutKeys[SkString("location")] = kLocation_LayoutKey;
fLayoutKeys[SkString("offset")] = kOffset_LayoutKey;
fLayoutKeys[SkString("binding")] = kBinding_LayoutKey;
fLayoutKeys[SkString("index")] = kIndex_LayoutKey;
fLayoutKeys[SkString("set")] = kSet_LayoutKey;
fLayoutKeys[SkString("builtin")] = kBuiltin_LayoutKey;
fLayoutKeys[SkString("input_attachment_index")] = kInputAttachmentIndex_LayoutKey;
fLayoutKeys[SkString("origin_upper_left")] = kOriginUpperLeft_LayoutKey;
fLayoutKeys[SkString("override_coverage")] = kOverrideCoverage_LayoutKey;
fLayoutKeys[SkString("blend_support_all_equations")] = kBlendSupportAllEquations_LayoutKey;
fLayoutKeys[SkString("push_constant")] = kPushConstant_LayoutKey;
}
Parser::~Parser() {
@ -167,6 +179,9 @@ Token Parser::nextToken() {
text = SkString(skslget_text(fScanner));
break;
default:
#ifdef SK_DEBUG
text = SkString(skslget_text(fScanner));
#endif
break;
}
return Token(Position(skslget_lineno(fScanner), -1), (Token::Kind) token, text);
@ -195,7 +210,12 @@ bool Parser::expect(Token::Kind kind, SkString expected, Token* result) {
}
return true;
} else {
this->error(next.fPosition, "expected " + expected + ", but found '" + next.fText + "'");
if (next.fText.size()) {
this->error(next.fPosition, "expected " + expected + ", but found '" + next.fText +
"'");
} else {
this->error(next.fPosition, "parse error, recompile in debug mode for details");
}
return false;
}
}
@ -559,30 +579,45 @@ Layout Parser::layout() {
}
for (;;) {
Token t = this->nextToken();
if (t.fText == "location") {
auto found = fLayoutKeys.find(t.fText);
if (found != fLayoutKeys.end()) {
switch (found->second) {
case kLocation_LayoutKey:
location = this->layoutInt();
} else if (t.fText == "offset") {
break;
case kOffset_LayoutKey:
offset = this->layoutInt();
} else if (t.fText == "binding") {
break;
case kBinding_LayoutKey:
binding = this->layoutInt();
} else if (t.fText == "index") {
break;
case kIndex_LayoutKey:
index = this->layoutInt();
} else if (t.fText == "set") {
break;
case kSet_LayoutKey:
set = this->layoutInt();
} else if (t.fText == "builtin") {
break;
case kBuiltin_LayoutKey:
builtin = this->layoutInt();
} else if (t.fText == "input_attachment_index") {
break;
case kInputAttachmentIndex_LayoutKey:
inputAttachmentIndex = this->layoutInt();
} else if (t.fText == "origin_upper_left") {
break;
case kOriginUpperLeft_LayoutKey:
originUpperLeft = true;
} else if (t.fText == "override_coverage") {
break;
case kOverrideCoverage_LayoutKey:
overrideCoverage = true;
} else if (t.fText == "blend_support_all_equations") {
break;
case kBlendSupportAllEquations_LayoutKey:
blendSupportAllEquations = true;
break;
case kPushConstant_LayoutKey:
pushConstant = true;
break;
}
} else if (Layout::ReadFormat(t.fText, &format)) {
// AST::ReadFormat stored the result in 'format'.
} else if (t.fText == "push_constant") {
pushConstant = true;
} else {
this->error(t.fPosition, ("'" + t.fText +
"' is not a valid layout qualifier").c_str());

View File

@ -10,6 +10,7 @@
#include <vector>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include "SkSLErrorReporter.h"
#include "SkSLToken.h"
@ -206,6 +207,20 @@ private:
Token fPushback;
SymbolTable& fTypes;
ErrorReporter& fErrors;
enum LayoutKey {
kLocation_LayoutKey,
kOffset_LayoutKey,
kBinding_LayoutKey,
kIndex_LayoutKey,
kSet_LayoutKey,
kBuiltin_LayoutKey,
kInputAttachmentIndex_LayoutKey,
kOriginUpperLeft_LayoutKey,
kOverrideCoverage_LayoutKey,
kBlendSupportAllEquations_LayoutKey,
kPushConstant_LayoutKey
};
std::unordered_map<SkString, LayoutKey> fLayoutKeys;
friend class AutoDepth;
};