aboutsummaryrefslogtreecommitdiff
path: root/grid.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-11-26 19:57:08 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-11-26 19:57:08 +0000
commit76992713161b589407060c2fc7a42e7ffb192844 (patch)
tree00cc23f34904eb01938abcbb1ccdbefbcb98ffad /grid.c
parentgrid: resize without reflow: only verify URI ranges in debug builds (diff)
grid: reflow: no need to keep a uri-range-idx variable
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).
Diffstat (limited to 'grid.c')
-rw-r--r--grid.c24
1 files 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++;
}
}