aboutsummaryrefslogtreecommitdiff
path: root/grid.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-07 15:10:30 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-07 15:10:30 +0000
commitf2363c23915aeab1900842f815ccfcf5f67f8210 (patch)
tree0da7c78cd7b85f182264a7dedc7763f7ae0b1b04 /grid.c
parentgrid: grid_memset() -> grid_memclear() (diff)
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.
Diffstat (limited to 'grid.c')
-rw-r--r--grid.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/grid.c b/grid.c
index a09e3d21..c08a002e 100644
--- a/grid.c
+++ b/grid.c
@@ -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];