mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-29 07:58:01 -04:00
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:
parent
48528419c4
commit
f2363c2391
1 changed files with 13 additions and 0 deletions
13
grid.c
13
grid.c
|
|
@ -47,6 +47,19 @@ grid_memclear(struct grid *grid, int start, int length)
|
||||||
void
|
void
|
||||||
grid_memmove(struct grid *grid, int dst, int src, int length)
|
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 left = length;
|
||||||
int copy_idx = 0;
|
int copy_idx = 0;
|
||||||
struct cell copy[left];
|
struct cell copy[left];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue