From bd6db524d36605b8eae0159f943b7e9e9361d7a5 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 9 Jan 2013 13:47:57 -0800 Subject: [PATCH] cyclegraph: remove redundant code The edgeCreatesCycle() function can simply be reduced to checkReachable(), since checkReachable() will detect "to == from". --- cyclegraph.cc | 18 +++--------------- cyclegraph.h | 2 -- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/cyclegraph.cc b/cyclegraph.cc index ec0ce45..2dc2eae 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -63,7 +63,7 @@ void CycleGraph::addEdge(const ModelAction *from, const ModelAction *to) CycleNode *tonode = getNode(to); if (!hasCycles) - hasCycles = edgeCreatesCycle(fromnode, tonode); + hasCycles = checkReachable(tonode, fromnode); if (fromnode->addEdge(tonode)) rollbackvector.push_back(fromnode); @@ -81,7 +81,7 @@ void CycleGraph::addEdge(const ModelAction *from, const ModelAction *to) */ if (rmwnode != NULL && !to->is_rmw()) { if (!hasCycles) - hasCycles = edgeCreatesCycle(rmwnode, tonode); + hasCycles = checkReachable(tonode, rmwnode); if (rmwnode->addEdge(tonode)) rollbackvector.push_back(rmwnode); @@ -124,7 +124,7 @@ void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw) } if (!hasCycles) - hasCycles = edgeCreatesCycle(fromnode, rmwnode); + hasCycles = checkReachable(rmwnode, fromnode); if (fromnode->addEdge(rmwnode)) rollbackvector.push_back(fromnode); @@ -160,18 +160,6 @@ void CycleGraph::dumpGraphToFile(const char *filename) const } #endif -/** - * Checks whether the addition of an edge between these two nodes would create - * a cycle in the graph. - * @param from The CycleNode from which the edge would start - * @param to The CycleNode to which the edge would point - * @return True if this edge would create a cycle; false otherwise - */ -bool CycleGraph::edgeCreatesCycle(const CycleNode *from, const CycleNode *to) const -{ - return (from == to) || checkReachable(to, from); -} - /** * Checks whether one ModelAction can reach another. * @param from The ModelAction from which to begin exploration diff --git a/cyclegraph.h b/cyclegraph.h index 5d9c976..45e49fb 100644 --- a/cyclegraph.h +++ b/cyclegraph.h @@ -52,8 +52,6 @@ class CycleGraph { bool checkReachable(const CycleNode *from, const CycleNode *to) const; - bool edgeCreatesCycle(const CycleNode *from, const CycleNode *to) const; - /** @brief A flag: true if this graph contains cycles */ bool hasCycles; bool oldCycles; -- 2.34.1