]> granicus.if.org Git - graphviz/commitdiff
gvmap make_map_internal: operate directly on 'xcombined' instead of 'xtemp'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 20 Jan 2023 16:05:58 +0000 (08:05 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 21 Jan 2023 21:44:04 +0000 (13:44 -0800)
Nothing appears to alias `xcombined` within this block. So we can save an
intermediate allocation and the cost of data movement by simply writing results
into their final destination.

cmd/gvmap/make_map.c

index e61725a94fb7bb85606049f10b9fabc8bbddeb5c..ab4d9dae7af8db96c488f13a7d797ebca0829b93 100644 (file)
@@ -1217,24 +1217,22 @@ static int make_map_internal(int exclude_random, int include_OK_points,
 
   {
     int nz, nh = 0;/* the set to highlight */
-    double *xtemp;
     if (HIGHLIGHT_SET){
       if (Verbose) fprintf(stderr," highlight cluster %d, n = %d\n",HIGHLIGHT_SET, n);
-      xtemp = gv_calloc(n * dim, sizeof(double));
       /* shift set to the beginning */
       nz = 0;
       for (i = 0; i < n; i++){
        if (grouping[i] == HIGHLIGHT_SET){
          nh++;
          for (j = 0; j < dim; j++){
-           xtemp[nz++] = x[i*dim+j];
+           (*xcombined)[nz++] = x[i*dim+j];
          }
        }
       }
       for (i = 0; i < n; i++){
        if (grouping[i] != HIGHLIGHT_SET){
          for (j = 0; j < dim; j++){
-           xtemp[nz++] = x[i*dim+j];
+           (*xcombined)[nz++] = x[i*dim+j];
          }
        }
       }
@@ -1245,11 +1243,9 @@ static int make_map_internal(int exclude_random, int include_OK_points,
       for (i = nh; i < n; i++){
        grouping[i] = 2;
       }
-      memcpy(*xcombined, xtemp, n*dim*sizeof(double));
       *nrandom += n - nh;/* count everything except cluster HIGHLIGHT_SET as random */
       n = nh;
       if (Verbose) fprintf(stderr,"nh = %d\n",nh);
-      free(xtemp);
     }
   }