Before, whenever anything changed (two elements get fused or one
element gets dropped), we would start all over from scratch.
Pairs that were already considered before and that are not related
to the change do not need to be reconsidered.
We may still reconsider some pairs, even after this commit.
In particular, if one element gets dropped, then we will still reconsider
all combinations with the element that did not get dropped.
{
int i, j;
- for (i = 0; i < map->n - 1; ++i)
+ for (i = map->n - 2; i >= 0; --i)
+restart:
for (j = i + 1; j < map->n; ++j) {
int changed;
changed = coalesce_pair(map, i, j, tabs);
if (changed < 0)
goto error;
if (changed)
- return coalesce(map, tabs);
+ goto restart;
}
return map;
error: