mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
wip: use a sliding window instead of memmove() to scroll
Instead of memmoving a large amount of data on every scroll, use a sliding window. That is, each time we scroll, we offset origin.
This commit is contained in:
parent
9e3b8ab3ff
commit
d70956da08
7 changed files with 140 additions and 108 deletions
34
grid.c
34
grid.c
|
|
@ -6,3 +6,37 @@
|
|||
#define LOG_MODULE "grid"
|
||||
#define LOG_ENABLE_DBG 1
|
||||
#include "log.h"
|
||||
|
||||
struct cell *
|
||||
grid_get_range(struct grid *grid, size_t start, size_t *length)
|
||||
{
|
||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||
assert(*length <= grid->size);
|
||||
|
||||
size_t real_start = (grid->offset + start) % grid->size;
|
||||
assert(real_start < grid->size);
|
||||
|
||||
*length = min(*length, grid->size - real_start);
|
||||
assert(real_start + *length <= grid->size);
|
||||
|
||||
return &grid->cells[real_start];
|
||||
#undef min
|
||||
}
|
||||
|
||||
void
|
||||
grid_memset(struct grid *grid, size_t start, int c, size_t length)
|
||||
{
|
||||
size_t left = length;
|
||||
while (left > 0) {
|
||||
size_t count = left;
|
||||
struct cell *cells = grid_get_range(grid, start, &count);
|
||||
|
||||
assert(count > 0);
|
||||
assert(count <= left);
|
||||
|
||||
memset(cells, c, count * sizeof(cells[0]));
|
||||
|
||||
left -= count;
|
||||
start += count;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue