]> granicus.if.org Git - graphviz/commitdiff
remove a manual allocation
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 21 Nov 2020 02:04:10 +0000 (18:04 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 23 Jan 2021 18:29:33 +0000 (10:29 -0800)
lib/vpsc/remove_rectangle_overlap.cpp

index 62910fd3d4cb3dbf7121b8636e587e3cd8617224..f62dbb956dd4a3ff8182646375c483c0b3da8262 100644 (file)
@@ -23,6 +23,7 @@
 #include <vpsc/constraint.h>
 #include <fstream>
 #include <vpsc/blocks.h>
+#include <vector>
 using std::ios;
 using std::ofstream;
 
@@ -57,10 +58,11 @@ void removeRectangleOverlap(int n, Rectangle *rs[], double xBorder, double yBord
                vs[i]=new Variable(i,0,1);
        }
        Constraint **cs;
-       double *oldX = new double[n];
+       std::vector<double> oldX;
+       oldX.reserve(n);
        int m=generateXConstraints(n,rs,vs,cs,true);
        for(int i=0;i<n;i++) {
-               oldX[i]=vs[i]->desiredPosition;
+               oldX.push_back(vs[i]->desiredPosition);
        }
        VPSC vpsc_x(n,vs,m,cs);
        if (RECTANGLE_OVERLAP_LOGGING) {
@@ -89,7 +91,6 @@ void removeRectangleOverlap(int n, Rectangle *rs[], double xBorder, double yBord
                rs[i]->moveCentreY(vs[i]->position());
                rs[i]->moveCentreX(oldX[i]);
        }
-       delete [] oldX;
        for(int i = 0; i < m; ++i) {
                delete cs[i];
        }