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:
Daniel Eklöf 2019-07-01 12:23:38 +02:00
parent 9e3b8ab3ff
commit d70956da08
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 140 additions and 108 deletions

34
grid.c
View file

@ -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;
}
}