From f2363c23915aeab1900842f815ccfcf5f67f8210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 7 Jul 2019 17:10:30 +0200 Subject: [PATCH] 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. --- grid.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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];