From d79e9c5e969cffb8ddf55db4d63df1782069e98f Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 30 Sep 2019 22:27:44 +0000 Subject: [PATCH] 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 --- gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/escape.cc | 54 ++++++++++++++++++++++----------------------- gcc/go/gofrontend/escape.h | 6 ++--- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 3f2c3dc..f7c45ee 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -10a1671d94ddc0c39f2f4b039e5ea33358f414c0 +07faafda5fbd66a710153814f30d93c91461e7cb The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/escape.cc b/gcc/go/gofrontend/escape.cc index 91f43a6..bfd1a39 100644 --- a/gcc/go/gofrontend/escape.cc +++ b/gcc/go/gofrontend/escape.cc @@ -579,9 +579,9 @@ Node::is_sink() const return false; } -std::map Node::objects; -std::map Node::expressions; -std::map Node::statements; +Unordered_map(Named_object*, Node*) Node::objects; +Unordered_map(Expression*, Node*) Node::expressions; +Unordered_map(Statement*, Node*) Node::statements; std::vector Node::indirects; // Make a object node or return a cached node for this object. @@ -589,13 +589,12 @@ std::vector Node::indirects; Node* Node::make_node(Named_object* no) { - if (Node::objects.find(no) != Node::objects.end()) - return Node::objects[no]; - - Node* n = new Node(no); - std::pair val(no, n); - Node::objects.insert(val); - return n; + std::pair val(no, NULL); + std::pair ins = + Node::objects.insert(val); + if (ins.second) + ins.first->second = new Node(no); + return ins.first->second; } // Make an expression node or return a cached node for this expression. @@ -603,13 +602,12 @@ Node::make_node(Named_object* no) Node* Node::make_node(Expression* e) { - if (Node::expressions.find(e) != Node::expressions.end()) - return Node::expressions[e]; - - Node* n = new Node(e); - std::pair val(e, n); - Node::expressions.insert(val); - return n; + std::pair val(e, NULL); + std::pair ins = + Node::expressions.insert(val); + if (ins.second) + ins.first->second = new Node(e); + return ins.first->second; } // Make a statement node or return a cached node for this statement. @@ -617,13 +615,12 @@ Node::make_node(Expression* e) Node* Node::make_node(Statement* s) { - if (Node::statements.find(s) != Node::statements.end()) - return Node::statements[s]; - - Node* n = new Node(s); - std::pair val(s, n); - Node::statements.insert(val); - return n; + std::pair val(s, NULL); + std::pair ins = + Node::statements.insert(val); + if (ins.second) + ins.first->second = new Node(s); + return ins.first->second; } // Make an indirect node with given child. @@ -3447,19 +3444,22 @@ Gogo::reclaim_escape_nodes() void Node::reclaim_nodes() { - for (std::map::iterator p = Node::objects.begin(); + for (Unordered_map(Named_object*, Node*)::iterator p = + Node::objects.begin(); p != Node::objects.end(); ++p) delete p->second; Node::objects.clear(); - for (std::map::iterator p = Node::expressions.begin(); + for (Unordered_map(Expression*, Node*)::iterator p = + Node::expressions.begin(); p != Node::expressions.end(); ++p) delete p->second; Node::expressions.clear(); - for (std::map::iterator p = Node::statements.begin(); + for (Unordered_map(Statement*, Node*)::iterator p = + Node::statements.begin(); p != Node::statements.end(); ++p) delete p->second; diff --git a/gcc/go/gofrontend/escape.h b/gcc/go/gofrontend/escape.h index 88e23ce..e97b529 100644 --- a/gcc/go/gofrontend/escape.h +++ b/gcc/go/gofrontend/escape.h @@ -329,9 +329,9 @@ class Node Node* child_; // Cache all the Nodes created via Node::make_node to make the API simpler. - static std::map objects; - static std::map expressions; - static std::map statements; + static Unordered_map(Named_object*, Node*) objects; + static Unordered_map(Expression*, Node*) expressions; + static Unordered_map(Statement*, Node*) statements; // Collection of all NODE_INDIRECT Nodes, used for reclaiming memory. This // is not a cache -- each make_indirect_node will make a fresh Node. -- 2.7.4