From 76992713161b589407060c2fc7a42e7ffb192844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 26 Nov 2021 20:57:08 +0100 Subject: [PATCH] grid: reflow: no need to keep a uri-range-idx variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The URI ranges are now an array, which means we can get the next URI range by incrementing the pointer. Instead of checking if range is not NULL, check that it isn’t the range terminator (which is NULL when we don’t have any ranges, and the first address *after* the last range otherwise). --- grid.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/grid.c b/grid.c index dd6011c1..e168353f 100644 --- a/grid.c +++ b/grid.c @@ -684,19 +684,20 @@ grid_resize_and_reflow( tp = NULL; /* Does this row have any URIs? */ - struct row_uri_range *range; + struct row_uri_range *range, *range_terminator; struct row_data *extra = old_row->extra; - size_t uri_range_idx = 0; if (extra != NULL && extra->uri_ranges.count > 0) { - range = &extra->uri_ranges.v[uri_range_idx]; + range = &extra->uri_ranges.v[0]; + range_terminator = &extra->uri_ranges.v[extra->uri_ranges.count]; - /* Make sure the *last* URI range's end point is included in the copy */ + /* Make sure the *last* URI range's end point is included + * in the copy */ const struct row_uri_range *last_on_row = &extra->uri_ranges.v[extra->uri_ranges.count - 1]; col_count = max(col_count, last_on_row->end + 1); } else - range = NULL; + range = range_terminator = NULL; for (int start = 0, left = col_count; left > 0;) { int end; @@ -710,7 +711,7 @@ grid_resize_and_reflow( * If there are no more tracking points, or URI ranges, * the end-coordinate will be at the end of the row, */ - if (range != NULL) { + if (range != range_terminator) { int uri_col = (range->start >= start ? range->start : range->end) + 1; if (tp != NULL) { @@ -835,20 +836,15 @@ grid_resize_and_reflow( } if (uri_break) { + xassert(range != NULL); + if (range->start == end - 1) reflow_uri_range_start(range, new_row, new_col_idx - 1); if (range->end == end - 1) { reflow_uri_range_end(range, new_row, new_col_idx - 1); - - xassert(&extra->uri_ranges.v[uri_range_idx] == range); grid_row_uri_range_destroy(range); - - uri_range_idx++; - - range = uri_range_idx < extra->uri_ranges.count - ? &old_row->extra->uri_ranges.v[uri_range_idx] - : NULL; + range++; } }