Remove malloc from parse_counts_for_cdf_opt
No need for this malloc. I also extracted total_modes out of the if
statement and added a CDF_MAX_SIZE constant.
Change-Id: I104387e0b9d62869b461020fcc01ef088d50516c
diff --git a/tools/aom_entropy_optimizer.c b/tools/aom_entropy_optimizer.c
index 37062e1..d60f1e3 100644
--- a/tools/aom_entropy_optimizer.c
+++ b/tools/aom_entropy_optimizer.c
@@ -29,6 +29,7 @@
#include "av1/common/entropymode.h"
#define SPACES_PER_TAB 2
+#define CDF_MAX_SIZE 16
typedef unsigned int aom_count_type;
// A log file recording parsed counts
@@ -147,8 +148,8 @@
static void counts_to_cdf(const aom_count_type *counts, aom_cdf_prob *cdf,
int modes) {
- int64_t csum[16];
- assert(modes <= 16);
+ int64_t csum[CDF_MAX_SIZE];
+ assert(modes <= CDF_MAX_SIZE);
csum[0] = counts[0] + 1;
for (int i = 1; i < modes; ++i) csum[i] = counts[i] + 1 + csum[i - 1];
@@ -173,15 +174,11 @@
fprintf(stderr, "The dimension of a counts vector should be at least 1!\n");
return 1;
}
+ const int total_modes = cts_each_dim[0];
if (dim_of_cts == 1) {
- const int total_modes = cts_each_dim[0];
+ assert(total_modes <= CDF_MAX_SIZE);
+ aom_cdf_prob cdfs[CDF_MAX_SIZE];
aom_count_type *counts1d = *ct_ptr;
- aom_cdf_prob *cdfs = aom_malloc(sizeof(*cdfs) * total_modes);
-
- if (cdfs == NULL) {
- fprintf(stderr, "Allocating cdf array failed!\n");
- return 1;
- }
counts_to_cdf(counts1d, cdfs, total_modes);
(*ct_ptr) += total_modes;
@@ -194,7 +191,7 @@
}
fprintf(probsfile, " )");
} else {
- for (int k = 0; k < cts_each_dim[0]; ++k) {
+ for (int k = 0; k < total_modes; ++k) {
int tabs_next_level;
if (dim_of_cts == 2)
@@ -209,19 +206,18 @@
}
if (dim_of_cts == 2) {
- if (k == cts_each_dim[0] - 1)
+ if (k == total_modes - 1)
fprintf(probsfile, "}\n");
else
fprintf(probsfile, "},\n");
} else {
- if (k == cts_each_dim[0] - 1)
+ if (k == total_modes - 1)
fprintf(probsfile, "%*c}\n", tabs * SPACES_PER_TAB, ' ');
else
fprintf(probsfile, "%*c},\n", tabs * SPACES_PER_TAB, ' ');
}
}
}
-
return 0;
}