compiler: change escape maps to hash tables

Also use just one table lookup, not two.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/197759

From-SVN: r276382
This commit is contained in:
Ian Lance Taylor 2019-09-30 22:27:44 +00:00
parent 6ba3c0f717
commit d79e9c5e96
3 changed files with 31 additions and 31 deletions

View File

@ -1,4 +1,4 @@
10a1671d94ddc0c39f2f4b039e5ea33358f414c0 07faafda5fbd66a710153814f30d93c91461e7cb
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.

View File

@ -579,9 +579,9 @@ Node::is_sink() const
return false; return false;
} }
std::map<Named_object*, Node*> Node::objects; Unordered_map(Named_object*, Node*) Node::objects;
std::map<Expression*, Node*> Node::expressions; Unordered_map(Expression*, Node*) Node::expressions;
std::map<Statement*, Node*> Node::statements; Unordered_map(Statement*, Node*) Node::statements;
std::vector<Node*> Node::indirects; std::vector<Node*> Node::indirects;
// Make a object node or return a cached node for this object. // Make a object node or return a cached node for this object.
@ -589,13 +589,12 @@ std::vector<Node*> Node::indirects;
Node* Node*
Node::make_node(Named_object* no) Node::make_node(Named_object* no)
{ {
if (Node::objects.find(no) != Node::objects.end()) std::pair<Named_object*, Node*> val(no, NULL);
return Node::objects[no]; std::pair<Unordered_map(Named_object*, Node*)::iterator, bool> ins =
Node::objects.insert(val);
Node* n = new Node(no); if (ins.second)
std::pair<Named_object*, Node*> val(no, n); ins.first->second = new Node(no);
Node::objects.insert(val); return ins.first->second;
return n;
} }
// Make an expression node or return a cached node for this expression. // Make an expression node or return a cached node for this expression.
@ -603,13 +602,12 @@ Node::make_node(Named_object* no)
Node* Node*
Node::make_node(Expression* e) Node::make_node(Expression* e)
{ {
if (Node::expressions.find(e) != Node::expressions.end()) std::pair<Expression*, Node*> val(e, NULL);
return Node::expressions[e]; std::pair<Unordered_map(Expression*, Node*)::iterator, bool> ins =
Node::expressions.insert(val);
Node* n = new Node(e); if (ins.second)
std::pair<Expression*, Node*> val(e, n); ins.first->second = new Node(e);
Node::expressions.insert(val); return ins.first->second;
return n;
} }
// Make a statement node or return a cached node for this statement. // Make a statement node or return a cached node for this statement.
@ -617,13 +615,12 @@ Node::make_node(Expression* e)
Node* Node*
Node::make_node(Statement* s) Node::make_node(Statement* s)
{ {
if (Node::statements.find(s) != Node::statements.end()) std::pair<Statement*, Node*> val(s, NULL);
return Node::statements[s]; std::pair<Unordered_map(Statement*, Node*)::iterator, bool> ins =
Node::statements.insert(val);
Node* n = new Node(s); if (ins.second)
std::pair<Statement*, Node*> val(s, n); ins.first->second = new Node(s);
Node::statements.insert(val); return ins.first->second;
return n;
} }
// Make an indirect node with given child. // Make an indirect node with given child.
@ -3447,19 +3444,22 @@ Gogo::reclaim_escape_nodes()
void void
Node::reclaim_nodes() Node::reclaim_nodes()
{ {
for (std::map<Named_object*, Node*>::iterator p = Node::objects.begin(); for (Unordered_map(Named_object*, Node*)::iterator p =
Node::objects.begin();
p != Node::objects.end(); p != Node::objects.end();
++p) ++p)
delete p->second; delete p->second;
Node::objects.clear(); Node::objects.clear();
for (std::map<Expression*, Node*>::iterator p = Node::expressions.begin(); for (Unordered_map(Expression*, Node*)::iterator p =
Node::expressions.begin();
p != Node::expressions.end(); p != Node::expressions.end();
++p) ++p)
delete p->second; delete p->second;
Node::expressions.clear(); Node::expressions.clear();
for (std::map<Statement*, Node*>::iterator p = Node::statements.begin(); for (Unordered_map(Statement*, Node*)::iterator p =
Node::statements.begin();
p != Node::statements.end(); p != Node::statements.end();
++p) ++p)
delete p->second; delete p->second;

View File

@ -329,9 +329,9 @@ class Node
Node* child_; Node* child_;
// Cache all the Nodes created via Node::make_node to make the API simpler. // Cache all the Nodes created via Node::make_node to make the API simpler.
static std::map<Named_object*, Node*> objects; static Unordered_map(Named_object*, Node*) objects;
static std::map<Expression*, Node*> expressions; static Unordered_map(Expression*, Node*) expressions;
static std::map<Statement*, Node*> statements; static Unordered_map(Statement*, Node*) statements;
// Collection of all NODE_INDIRECT Nodes, used for reclaiming memory. This // Collection of all NODE_INDIRECT Nodes, used for reclaiming memory. This
// is not a cache -- each make_indirect_node will make a fresh Node. // is not a cache -- each make_indirect_node will make a fresh Node.