Use SkTHashMap for the BuiltinMap.
Change-Id: I6f50d8020c15acf664cdfcb2918c2e547427b838 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/515321 Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
11206c3faf
commit
7957918db3
@ -12,35 +12,35 @@
|
||||
namespace SkSL {
|
||||
|
||||
void BuiltinMap::insertOrDie(std::string key, std::unique_ptr<ProgramElement> element) {
|
||||
SkASSERT(fElements.find(key) == fElements.end());
|
||||
fElements[key] = BuiltinElement{std::move(element), false};
|
||||
SkASSERT(!fElements.find(key));
|
||||
fElements.set(std::move(key), BuiltinElement{std::move(element), /*fAlreadyIncluded=*/false});
|
||||
}
|
||||
|
||||
const ProgramElement* BuiltinMap::find(const std::string& key) {
|
||||
auto iter = fElements.find(key);
|
||||
if (iter == fElements.end()) {
|
||||
BuiltinElement* elem = fElements.find(key);
|
||||
if (!elem) {
|
||||
return fParent ? fParent->find(key) : nullptr;
|
||||
}
|
||||
return iter->second.fElement.get();
|
||||
return elem->fElement.get();
|
||||
}
|
||||
|
||||
// Only returns a builtin element that isn't already marked as included, and then marks it.
|
||||
const ProgramElement* BuiltinMap::findAndInclude(const std::string& key) {
|
||||
auto iter = fElements.find(key);
|
||||
if (iter == fElements.end()) {
|
||||
BuiltinElement* elem = fElements.find(key);
|
||||
if (!elem) {
|
||||
return fParent ? fParent->findAndInclude(key) : nullptr;
|
||||
}
|
||||
if (iter->second.fAlreadyIncluded) {
|
||||
if (elem->fAlreadyIncluded) {
|
||||
return nullptr;
|
||||
}
|
||||
iter->second.fAlreadyIncluded = true;
|
||||
return iter->second.fElement.get();
|
||||
elem->fAlreadyIncluded = true;
|
||||
return elem->fElement.get();
|
||||
}
|
||||
|
||||
void BuiltinMap::resetAlreadyIncluded() {
|
||||
for (auto& pair : fElements) {
|
||||
pair.second.fAlreadyIncluded = false;
|
||||
}
|
||||
fElements.foreach([](const std::string&, BuiltinElement* elem) {
|
||||
elem->fAlreadyIncluded = false;
|
||||
});
|
||||
if (fParent) {
|
||||
fParent->resetAlreadyIncluded();
|
||||
}
|
||||
|
@ -9,9 +9,9 @@
|
||||
#define SKSL_BUILTINMAP
|
||||
|
||||
#include "include/private/SkSLString.h"
|
||||
#include "include/private/SkTHash.h"
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace SkSL {
|
||||
|
||||
@ -38,7 +38,7 @@ private:
|
||||
bool fAlreadyIncluded = false;
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, BuiltinElement> fElements;
|
||||
SkTHashMap<std::string, BuiltinElement> fElements;
|
||||
BuiltinMap* fParent = nullptr;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user