From 227af34e24ba362ed9f72a9fca0a914e034d709b Mon Sep 17 00:00:00 2001 From: John Stiles Date: Thu, 3 Mar 2022 15:50:23 -0500 Subject: [PATCH] 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 Commit-Queue: John Stiles Auto-Submit: John Stiles --- src/sksl/SkSLDSLParser.cpp | 12 ++++++------ src/sksl/SkSLDSLParser.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sksl/SkSLDSLParser.cpp b/src/sksl/SkSLDSLParser.cpp index 8c44c8493d..9a5f4c1e27 100644 --- a/src/sksl/SkSLDSLParser.cpp +++ b/src/sksl/SkSLDSLParser.cpp @@ -78,11 +78,11 @@ public: } }; -std::unordered_map* DSLParser::layoutTokens; +SkTHashMap* DSLParser::sLayoutTokens; void DSLParser::InitLayoutMap() { - layoutTokens = new std::unordered_map; - #define TOKEN(name, text) (*layoutTokens)[text] = LayoutToken::name + sLayoutTokens = new SkTHashMap; + #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; diff --git a/src/sksl/SkSLDSLParser.h b/src/sksl/SkSLDSLParser.h index f8af04c438..3765ff576c 100644 --- a/src/sksl/SkSLDSLParser.h +++ b/src/sksl/SkSLDSLParser.h @@ -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 #include #include -#include namespace SkSL { @@ -325,7 +325,7 @@ private: bool fOldEncounteredFatalError; }; - static std::unordered_map* layoutTokens; + static SkTHashMap* sLayoutTokens; Compiler& fCompiler; ProgramSettings fSettings;