Profiled and added a map to GraphStructuredStack's getContainingFrontier to massivly improve the C++ Kraken compiler's compile time by improving parsing time (parsing time cut by significantly more than half)

This commit is contained in:
Nathan Braswell
2016-01-29 14:09:09 -05:00
parent 17d4371d5c
commit da38ae03ed
2 changed files with 15 additions and 11 deletions

View File

@@ -32,6 +32,7 @@ class GraphStructuredStack {
private:
std::vector<std::vector<NodeTree<int>*>*> gss;
std::map< std::pair< NodeTree<int>*, NodeTree<int>* >, NodeTree<Symbol>* > edges;
std::map< NodeTree<int>*, int > containing_frontier_map;
};
#endif

View File

@@ -15,11 +15,10 @@ NodeTree<int>* GraphStructuredStack::newNode(int stateNum) {
void GraphStructuredStack::addToFrontier(int frontier, NodeTree<int>* node) {
//First, make sure our vector has this and lesser frontiers. If not, add it and up to it
while (gss.size() <= frontier) {
//std::cout << "Adding a new frontier: " << gss.size() << std::endl;
gss.push_back(new std::vector<NodeTree<int>*>());
}
//std::cout << "Adding " << node << " (" << node->getData() << ") to frontier " << frontier << std::endl;
gss[frontier]->push_back(node);
containing_frontier_map[node] = frontier;
}
NodeTree<int>* GraphStructuredStack::inFrontier(int frontier, int state) {
@@ -33,15 +32,19 @@ NodeTree<int>* GraphStructuredStack::inFrontier(int frontier, int state) {
}
int GraphStructuredStack::getContainingFrontier(NodeTree<int>* node) {
for (std::vector<std::vector<NodeTree<int>*>*>::size_type i = 0; i < gss.size(); i++) {
if (frontierIsEmpty(i))
continue;
for (std::vector<NodeTree<int>*>::size_type j = 0; j < gss[i]->size(); j++) {
if ((*(gss[i]))[j] == node)
return i;
}
}
return -1;
auto iter = containing_frontier_map.find(node);
if (iter != containing_frontier_map.end())
return iter->second;
return -1;
//for (std::vector<std::vector<NodeTree<int>*>*>::size_type i = 0; i < gss.size(); i++) {
//if (frontierIsEmpty(i))
//continue;
//for (std::vector<NodeTree<int>*>::size_type j = 0; j < gss[i]->size(); j++) {
//if ((*(gss[i]))[j] == node)
//return i;
//}
//}
//return -1;
}
bool GraphStructuredStack::frontierIsEmpty(int frontier) {