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

Side by Side Diff: src/sksl/ir/SkSLSymbolTable.h

Issue 2131223002: SkSL performance improvements (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: minor fixes 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SKSL_SYMBOLTABLE 8 #ifndef SKSL_SYMBOLTABLE
9 #define SKSL_SYMBOLTABLE 9 #define SKSL_SYMBOLTABLE
10 10
11 #include <memory> 11 #include <memory>
12 #include <unordered_map> 12 #include <unordered_map>
13 #include "SkSLErrorReporter.h" 13 #include "SkSLErrorReporter.h"
14 #include "SkSLSymbol.h" 14 #include "SkSLSymbol.h"
15 #include "SkSLUnresolvedFunction.h" 15 #include "SkSLUnresolvedFunction.h"
16 16
17 namespace SkSL { 17 namespace SkSL {
18 18
19 /** 19 /**
20 * Maps identifiers to symbols. Functions, in particular, are mapped to either F unctionDeclaration 20 * Maps identifiers to symbols. Functions, in particular, are mapped to either F unctionDeclaration
21 * or UnresolvedFunction depending on whether they are overloaded or not. 21 * or UnresolvedFunction depending on whether they are overloaded or not.
22 */ 22 */
23 class SymbolTable { 23 class SymbolTable {
24 public: 24 public:
25 SymbolTable(ErrorReporter& errorReporter) 25 SymbolTable(ErrorReporter& errorReporter)
26 : fErrorReporter(errorReporter) {} 26 : fOwner(true)
dogben 2016/07/08 19:56:40 Would it be simpler for Block and FunctionDeclarat
27
28 SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter& errorReporte r)
29 : fParent(parent)
30 , fErrorReporter(errorReporter) {} 27 , fErrorReporter(errorReporter) {}
31 28
32 std::shared_ptr<Symbol> operator[](const std::string& name); 29 SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter& errorReporte r,
30 bool owner = false)
31 : fParent(parent)
32 , fOwner(owner)
33 , fErrorReporter(errorReporter) {}
33 34
34 void add(const std::string& name, std::shared_ptr<Symbol> symbol); 35 ~SymbolTable();
36
37 const Symbol* operator[](const std::string& name);
38
39 // SymbolTable will take ownership of the pointer, deleting it when it is de stroyed
40 void add(const std::string& name, Symbol* symbol);
dogben 2016/07/08 19:56:40 nit: use std::unique_ptr to transfer ownership
41
42 void addWithoutOwnership(const std::string& name, const Symbol* symbol);
43
44 void takeOwnership(Symbol* s);
35 45
36 const std::shared_ptr<SymbolTable> fParent; 46 const std::shared_ptr<SymbolTable> fParent;
37 47
38 private: 48 private:
39 static std::vector<std::shared_ptr<FunctionDeclaration>> GetFunctions( 49 static std::vector<const FunctionDeclaration*> GetFunctions(const Symbol& s) ;
40 const std::sha red_ptr<Symbol>& s);
41 50
42 std::unordered_map<std::string, std::shared_ptr<Symbol>> fSymbols; 51 // true if this symbol should directly own the pointers it contains, false t o delegate ownership
52 // to its parent
53 const bool fOwner;
54
55 std::vector<Symbol*> fOwnedPointers;
dogben 2016/07/08 19:56:40 nit: std::vector<std::unique_ptr<Symbol>> eliminat
56
57 std::unordered_map<std::string, const Symbol*> fSymbols;
43 58
44 ErrorReporter& fErrorReporter; 59 ErrorReporter& fErrorReporter;
45 }; 60 };
46 61
47 } // namespace 62 } // namespace
48 63
49 #endif 64 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698