+/* This is simple, but not complete. We don't take into account
+ * indirect dependencies. */
+static void optimize_dependencies(struct op *op[], unsigned int num_ops[],
+ unsigned int num)
+{
+ unsigned int i, j;
+
+ /* There can only be one real dependency on each file */
+ for (i = 0; i < num; i++) {
+ for (j = 1; j < num_ops[i]; j++) {
+ struct depend *dep, *next;
+ struct depend *prev[num];
+
+ memset(prev, 0, sizeof(prev));
+
+ list_for_each_safe(&op[i][j].pre, dep, next, pre_list) {
+ if (!prev[dep->satisfies_file]) {
+ prev[dep->satisfies_file] = dep;
+ continue;
+ }
+ if (prev[dep->satisfies_file]->satisfies_opnum
+ < dep->satisfies_opnum) {
+ talloc_free(prev[dep->satisfies_file]);
+ prev[dep->satisfies_file] = dep;
+ } else
+ talloc_free(dep);
+ }
+ }
+ }
+
+ for (i = 0; i < num; i++) {
+ int deps[num];
+
+ for (j = 0; j < num; j++)
+ deps[j] = -1;
+
+ for (j = 1; j < num_ops[i]; j++) {
+ struct depend *dep, *next;
+
+ list_for_each_safe(&op[i][j].pre, dep, next, pre_list) {
+ if (deps[dep->satisfies_file]
+ >= (int)dep->satisfies_opnum)
+ talloc_free(dep);
+ else
+ deps[dep->satisfies_file]
+ = dep->satisfies_opnum;
+ }
+ }
+ }
+}
+