grid: add a fast path to grid_memmove()

Recognize the case where both the destination and source can be fully
accessed, and to a plain memmove() in this case.
This commit is contained in:
Daniel Eklöf 2019-07-07 17:10:30 +02:00
parent 48528419c4
commit f2363c2391
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

13
grid.c
View file

@ -47,6 +47,19 @@ grid_memclear(struct grid *grid, int start, int length)
void
grid_memmove(struct grid *grid, int dst, int src, int length)
{
/* Fast path, we can move everything in one swoop */
{
int count = length;
struct cell *dst_cells = grid_get_range(grid, dst, &count);
if (count == length) {
struct cell *src_cells = grid_get_range(grid, src, &count);
if (count == length) {
memmove(dst_cells, src_cells, length * sizeof(dst_cells[0]));
return;
}
}
}
int left = length;
int copy_idx = 0;
struct cell copy[left];