Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: src/sksl/ir/SkSLSymbolTable.cpp

Issue 2143323003: Revert of SkSL performance improvements (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/sksl/ir/SkSLSymbolTable.h ('k') | src/sksl/ir/SkSLType.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/sksl/ir/SkSLSymbolTable.cpp
diff --git a/src/sksl/ir/SkSLSymbolTable.cpp b/src/sksl/ir/SkSLSymbolTable.cpp
index 80e22da0092073cf3d8b0378890b6399778c439e..af83f7a456241abe4615a92e702d7084da5dc497 100644
--- a/src/sksl/ir/SkSLSymbolTable.cpp
+++ b/src/sksl/ir/SkSLSymbolTable.cpp
@@ -5,23 +5,23 @@
* found in the LICENSE file.
*/
-#include "SkSLSymbolTable.h"
-#include "SkSLUnresolvedFunction.h"
+ #include "SkSLSymbolTable.h"
namespace SkSL {
-std::vector<const FunctionDeclaration*> SymbolTable::GetFunctions(const Symbol& s) {
- switch (s.fKind) {
+std::vector<std::shared_ptr<FunctionDeclaration>> SymbolTable::GetFunctions(
+ const std::shared_ptr<Symbol>& s) {
+ switch (s->fKind) {
case Symbol::kFunctionDeclaration_Kind:
- return { &((FunctionDeclaration&) s) };
+ return { std::static_pointer_cast<FunctionDeclaration>(s) };
case Symbol::kUnresolvedFunction_Kind:
- return ((UnresolvedFunction&) s).fFunctions;
+ return ((UnresolvedFunction&) *s).fFunctions;
default:
return { };
}
}
-const Symbol* SymbolTable::operator[](const std::string& name) {
+std::shared_ptr<Symbol> SymbolTable::operator[](const std::string& name) {
const auto& entry = fSymbols.find(name);
if (entry == fSymbols.end()) {
if (fParent) {
@@ -30,15 +30,15 @@
return nullptr;
}
if (fParent) {
- auto functions = GetFunctions(*entry->second);
+ auto functions = GetFunctions(entry->second);
if (functions.size() > 0) {
bool modified = false;
- const Symbol* previous = (*fParent)[name];
+ std::shared_ptr<Symbol> previous = (*fParent)[name];
if (previous) {
- auto previousFunctions = GetFunctions(*previous);
- for (const FunctionDeclaration* prev : previousFunctions) {
+ auto previousFunctions = GetFunctions(previous);
+ for (const std::shared_ptr<FunctionDeclaration>& prev : previousFunctions) {
bool found = false;
- for (const FunctionDeclaration* current : functions) {
+ for (const std::shared_ptr<FunctionDeclaration>& current : functions) {
if (current->matches(*prev)) {
found = true;
break;
@@ -51,7 +51,7 @@
}
if (modified) {
ASSERT(functions.size() > 1);
- return this->takeOwnership(new UnresolvedFunction(functions));
+ return std::shared_ptr<Symbol>(new UnresolvedFunction(functions));
}
}
}
@@ -59,42 +59,27 @@
return entry->second;
}
-Symbol* SymbolTable::takeOwnership(Symbol* s) {
- fOwnedPointers.push_back(std::unique_ptr<Symbol>(s));
- return s;
-}
-
-void SymbolTable::add(const std::string& name, std::unique_ptr<Symbol> symbol) {
- this->addWithoutOwnership(name, symbol.get());
- fOwnedPointers.push_back(std::move(symbol));
-}
-
-void SymbolTable::addWithoutOwnership(const std::string& name, const Symbol* symbol) {
- const auto& existing = fSymbols.find(name);
- if (existing == fSymbols.end()) {
- fSymbols[name] = symbol;
- } else if (symbol->fKind == Symbol::kFunctionDeclaration_Kind) {
- const Symbol* oldSymbol = existing->second;
- if (oldSymbol->fKind == Symbol::kFunctionDeclaration_Kind) {
- std::vector<const FunctionDeclaration*> functions;
- functions.push_back((const FunctionDeclaration*) oldSymbol);
- functions.push_back((const FunctionDeclaration*) symbol);
- UnresolvedFunction* u = new UnresolvedFunction(std::move(functions));
- fSymbols[name] = u;
- this->takeOwnership(u);
- } else if (oldSymbol->fKind == Symbol::kUnresolvedFunction_Kind) {
- std::vector<const FunctionDeclaration*> functions;
- for (const auto* f : ((UnresolvedFunction&) *oldSymbol).fFunctions) {
- functions.push_back(f);
+void SymbolTable::add(const std::string& name, std::shared_ptr<Symbol> symbol) {
+ const auto& existing = fSymbols.find(name);
+ if (existing == fSymbols.end()) {
+ fSymbols[name] = symbol;
+ } else if (symbol->fKind == Symbol::kFunctionDeclaration_Kind) {
+ const std::shared_ptr<Symbol>& oldSymbol = existing->second;
+ if (oldSymbol->fKind == Symbol::kFunctionDeclaration_Kind) {
+ std::vector<std::shared_ptr<FunctionDeclaration>> functions;
+ functions.push_back(std::static_pointer_cast<FunctionDeclaration>(oldSymbol));
+ functions.push_back(std::static_pointer_cast<FunctionDeclaration>(symbol));
+ fSymbols[name].reset(new UnresolvedFunction(std::move(functions)));
+ } else if (oldSymbol->fKind == Symbol::kUnresolvedFunction_Kind) {
+ std::vector<std::shared_ptr<FunctionDeclaration>> functions;
+ for (const auto& f : ((UnresolvedFunction&) *oldSymbol).fFunctions) {
+ functions.push_back(f);
+ }
+ functions.push_back(std::static_pointer_cast<FunctionDeclaration>(symbol));
+ fSymbols[name].reset(new UnresolvedFunction(std::move(functions)));
}
- functions.push_back((const FunctionDeclaration*) symbol);
- UnresolvedFunction* u = new UnresolvedFunction(std::move(functions));
- fSymbols[name] = u;
- this->takeOwnership(u);
+ } else {
+ fErrorReporter.error(symbol->fPosition, "symbol '" + name + "' was already defined");
}
- } else {
- fErrorReporter.error(symbol->fPosition, "symbol '" + name + "' was already defined");
}
-}
-
} // namespace
« no previous file with comments | « src/sksl/ir/SkSLSymbolTable.h ('k') | src/sksl/ir/SkSLType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698