mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
grid: uri_range_erase: walk the ranges backwards
This way, ranges are deleted last-to-first, thus avoiding memmoving multiple ranges over and over again when erasing e.g. a full line.
This commit is contained in:
parent
747da83c76
commit
66b8c92c30
1 changed files with 4 additions and 5 deletions
9
grid.c
9
grid.c
|
|
@ -1143,19 +1143,18 @@ grid_row_uri_range_erase(struct row *row, int start, int end)
|
|||
struct row_data *extra = row->extra;
|
||||
|
||||
/* Split up, or remove, URI ranges affected by the erase */
|
||||
for (ssize_t i = 0; i < extra->uri_ranges.count; i++) {
|
||||
for (ssize_t i = (ssize_t)extra->uri_ranges.count - 1; i >= 0; i--) {
|
||||
struct row_uri_range *old = &extra->uri_ranges.v[i];
|
||||
|
||||
if (old->end < start)
|
||||
continue;
|
||||
return;
|
||||
|
||||
if (old->start > end)
|
||||
return;
|
||||
continue;
|
||||
|
||||
if (start <= old->start && end >= old->end) {
|
||||
/* Erase range covers URI completely - remove it */
|
||||
uri_range_delete(extra, i);
|
||||
i--;
|
||||
}
|
||||
|
||||
else if (start > old->start && end < old->end) {
|
||||
|
|
@ -1170,13 +1169,13 @@ grid_row_uri_range_erase(struct row *row, int start, int end)
|
|||
/* Erase range erases the head of the URI */
|
||||
xassert(start <= old->start);
|
||||
old->start = end + 1;
|
||||
return; /* There can be no more overlapping URIs */
|
||||
}
|
||||
|
||||
else if (start <= old->end && end >= old->end) {
|
||||
/* Erase range erases the tail of the URI */
|
||||
xassert(end >= old->end);
|
||||
old->end = start - 1;
|
||||
return; /* There can be no more overlapping URIs */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue