diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-07-07 15:10:30 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-07-07 15:10:30 +0000 |
| commit | f2363c23915aeab1900842f815ccfcf5f67f8210 (patch) | |
| tree | 0da7c78cd7b85f182264a7dedc7763f7ae0b1b04 /grid.c | |
| parent | grid: 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.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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]; |
