More dependency optimization: seems to happen with transactions enabled.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 14 Jul 2009 02:20:26 +0000 (11:50 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 14 Jul 2009 02:20:26 +0000 (11:50 +0930)
ccan/tdb/tools/replay_trace.c

index f9552b92637e1f73a2a10e29730940f00a393b9e..0d53f1fea71cb03ea6266adb0417e561a047cc90 100644 (file)
@@ -1165,8 +1165,10 @@ static void add_dependency(void *ctx,
        unsigned int needs_start, sat_start;
 
        /* We don't depend on ourselves. */
-       if (needs_file == satisfies_file)
+       if (needs_file == satisfies_file) {
+               assert(satisfies_opnum < needs_opnum);
                return;
+       }
 
 #if DEBUG_DEPS
        printf("%s:%u: depends on %s:%u\n",
@@ -1319,6 +1321,29 @@ static void optimize_dependencies(struct op *op[], unsigned int num_ops[],
 {
        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];