]> granicus.if.org Git - graphviz/commitdiff
Render_Contour2: allocate vertices as a single block
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 14 Aug 2021 20:59:21 +0000 (13:59 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 23 Aug 2021 14:56:33 +0000 (07:56 -0700)
Rather than an array of pointers and then individual allocations for each
vertex, we can simply allocate a single block ahead of time. This decreases
memory requirements and increases cache locality. Note that this does nothing
about the fairly egregious memory leak in this code.

cmd/smyrna/polytess.c

index 4b0b331af14bd05bd9f3b0b3d0e56971e7eec1d1..5c43bc83515b51ad059c410fa4912ec2e4c216d2 100644 (file)
@@ -63,20 +63,18 @@ static int Set_Winding_Rule(GLUtesselator *tobj,GLenum winding_rule)
 
 static int Render_Contour2(GLUtesselator *tobj,sdot_op* p)
 {
-    GLdouble** d;
     int x=0;
 
-    d = calloc(p->op.u.polygon.cnt, sizeof(GLdouble*));
+    GLdouble* d = calloc(p->op.u.polygon.cnt * 3, sizeof(GLdouble));
     for (x=0;x < p->op.u.polygon.cnt; x++)
     {
-       d[x]=malloc(sizeof(GLdouble)*3);
-       d[x][0]=p->op.u.polygon.pts[x].x;
-       d[x][1]=p->op.u.polygon.pts[x].y;
-       d[x][2]=p->op.u.polygon.pts[x].z+view->Topview->global_z;
+        d[x * 3] = p->op.u.polygon.pts[x].x;
+        d[x * 3 + 1] = p->op.u.polygon.pts[x].y;
+        d[x * 3 + 2] = p->op.u.polygon.pts[x].z + view->Topview->global_z;
     }
     for (x = 0; x < p->op.u.polygon.cnt; x++) //loop through the vertices
     {
-       gluTessVertex(tobj, d[x],d[x]); //store the vertex
+        gluTessVertex(tobj, &d[x * 3], &d[x * 3]); //store the vertex
     }
 
     return(1);