Commits

Chris Reuter  committed 53c90d9

Allocate ContribRow.Weights as one big chunk of RAM.

Previously, each ContribRow entry contained a pointer to an array of
double containing the weights. Previously, each of these was alloc'd
(as one would expect) but this change makes the code alloc them as
one contiguous chunk of RAM and then point each Weights pointer to the
appropriate offset in the chunk.

This yields a significant performance improvement.

  • Participants
  • Parent commits 4f65a3e
  • Branches suetanvil-weights-linear-mem

Comments (0)

Files changed (1)

File src/gd_interpolation.c

 typedef struct
 {
 	double *Weights;  /* Normalized weights of neighboring pixels */
-	int Left,Right;   /* Bounds of source pixels window */
-} ContributionType;  /* Contirbution information for a single pixel */
+	int Left,Right;     /* Bounds of source pixels window */
+} ContributionType;     /* Contirbution information for a single pixel */
 
 typedef struct
 {
 {
 	unsigned int u = 0;
 	LineContribType *res;
+	double *weights;
 
 	res = (LineContribType *) gdMalloc(sizeof(LineContribType));
 	if (!res) {
 	res->LineLength = line_length;
 	res->ContribRow = (ContributionType *) gdMalloc(line_length * sizeof(ContributionType));
 
+	weights = gdMalloc(windows_size * line_length * sizeof(double));
 	for (u = 0 ; u < line_length ; u++) {
-		res->ContribRow[u].Weights = (double *) gdMalloc(windows_size * sizeof(double));
+		res->ContribRow[u].Weights = &weights[u * windows_size];
 	}
 	return res;
 }
 static inline void _gdContributionsFree(LineContribType * p)
 {
 	unsigned int u;
-	for (u = 0; u < p->LineLength; u++)  {
-		gdFree(p->ContribRow[u].Weights);
-	}
+
+	/* Weights is one contiguous chunk of RAM so we can free it with one op. */
+	gdFree(p->ContribRow[0].Weights);
+
 	gdFree(p->ContribRow);
 	gdFree(p);
 }