On 07/25/2011 09:48 PM, Anthony Liguori wrote:
+/* Attempt to simplify a view by merging ajacent ranges */ +static void flatview_simplify(FlatView *view) +{ + unsigned i; + FlatRange *r1, *r2; + + for (i = 0; i + 1< view->nr; ++i) { + r1 =&view->ranges[i]; + r2 =&view->ranges[i+1]; + if (addrrange_end(r1->addr) == r2->addr.start +&& r1->mr == r2->mr +&& r1->offset_in_region + r1->addr.size == r2->offset_in_region +&& r1->dirty_log_mask == r2->dirty_log_mask) { + r1->addr.size += r2->addr.size; + memmove(r2, r2 + 1, (view->nr - (i + 2)) * sizeof(*r2)); + --view->nr; + --i; + }The --i is pretty subtle. Moving the index variable backwards in a conditional in a for loop is pretty evil :-) I started writing up why this was wrong until I noticed that.I think the following would be more straight forward: i = 0; while (i + 1 < view->nr) { int begin = i, end = i + 1; while (matches(&view->ranges[begin], &view->ranges[end])) { end++; } memmove(...) }
Right; updated to something along these lines. -- error compiling committee.c: too many arguments to function -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
