Use SkTHashMap for parser layout tokens.

It seems to reduce code size by about 1K every time we remove an
unordered map.

Change-Id: I120aa6130b4283c7d41b9db5bfeec3c2eb99bcd4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/515545
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2022-03-03 15:50:23 -05:00 committed by SkCQ
parent 3bf76ab829
commit 227af34e24
2 changed files with 8 additions and 8 deletions

View File

@ -78,11 +78,11 @@ public:
}
};
std::unordered_map<std::string_view, DSLParser::LayoutToken>* DSLParser::layoutTokens;
SkTHashMap<std::string_view, DSLParser::LayoutToken>* DSLParser::sLayoutTokens;
void DSLParser::InitLayoutMap() {
layoutTokens = new std::unordered_map<std::string_view, LayoutToken>;
#define TOKEN(name, text) (*layoutTokens)[text] = LayoutToken::name
sLayoutTokens = new SkTHashMap<std::string_view, LayoutToken>;
#define TOKEN(name, text) sLayoutTokens->set(text, LayoutToken::name)
TOKEN(LOCATION, "location");
TOKEN(OFFSET, "offset");
TOKEN(BINDING, "binding");
@ -757,9 +757,9 @@ DSLLayout DSLParser::layout() {
for (;;) {
Token t = this->nextToken();
std::string text(this->text(t));
auto found = layoutTokens->find(text);
if (found != layoutTokens->end()) {
switch (found->second) {
LayoutToken* found = sLayoutTokens->find(text);
if (found != nullptr) {
switch (*found) {
case LayoutToken::ORIGIN_UPPER_LEFT:
result.originUpperLeft(this->position(t));
break;

View File

@ -9,6 +9,7 @@
#define SKSL_DSLPARSER
#include "include/private/SkSLProgramKind.h"
#include "include/private/SkTHash.h"
#include "include/sksl/DSL.h"
#include "include/sksl/DSLSymbols.h"
#include "src/sksl/SkSLLexer.h"
@ -17,7 +18,6 @@
#include <memory>
#include <optional>
#include <string_view>
#include <unordered_map>
namespace SkSL {
@ -325,7 +325,7 @@ private:
bool fOldEncounteredFatalError;
};
static std::unordered_map<std::string_view, LayoutToken>* layoutTokens;
static SkTHashMap<std::string_view, LayoutToken>* sLayoutTokens;
Compiler& fCompiler;
ProgramSettings fSettings;