]> granicus.if.org Git - graphviz/commitdiff
manage graph collection in VPSC::blockGraphIsCyclic with smart pointers
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 8 May 2021 03:58:16 +0000 (20:58 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 14 May 2021 15:26:49 +0000 (08:26 -0700)
This avoids some manual memory management.

lib/vpsc/solve_VPSC.cpp

index 596c5f6952b578b140b7c0ded176c80854cf1893..10bf69e039e0600cc7406de7ab34f3c37d57b49c 100644 (file)
@@ -348,11 +348,10 @@ bool VPSC::constraintGraphIsCyclic(const unsigned n, Variable *vs[]) {
 // useful in debugging - cycles would be BAD
 bool VPSC::blockGraphIsCyclic() {
        map<Block*, node*> bmap;
-       vector<node*> graph;
+       vector<std::unique_ptr<node>> graph;
        for(Block *b : bs) {
-               node *u=new node;
-               graph.push_back(u);
-               bmap[b]=u;
+               graph.emplace_back(new node);
+               bmap[b]=graph.back().get();
        }
        for(Block *b : bs) {
                b->setUpInConstraints();
@@ -375,9 +374,9 @@ bool VPSC::blockGraphIsCyclic() {
        }
        while(!graph.empty()) {
                node *u=nullptr;
-               vector<node*>::iterator i=graph.begin();
+               vector<std::unique_ptr<node>>::iterator i=graph.begin();
                for(;i!=graph.end();i++) {
-                       u=*i;
+                       u=(*i).get();
                        if(u->in.empty()) {
                                break;
                        }
@@ -390,12 +389,8 @@ bool VPSC::blockGraphIsCyclic() {
                        for(node * v : u->out) {
                                v->in.erase(u);
                        }
-                       delete u;
                }
        }
-       for(unsigned i=0; i<graph.size(); i++) {
-               delete graph[i];
-       }
        return false;
 }