aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-10 14:08:53 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-10 14:08:53 +0000
commit8f0d574dcb0dc0f94a3e5da13331b8913ec9cd93 (patch)
tree43771f32119bc2a82a9fb46fffaac87fef2a2029
parentvt: implement \ED and \EE (diff)
grid: don't implement grid_swap_row() in the header file
-rw-r--r--grid.c91
-rw-r--r--grid.h25
2 files changed, 14 insertions, 102 deletions
diff --git a/grid.c b/grid.c
index b36c5e0b..6b89ad85 100644
--- a/grid.c
+++ b/grid.c
@@ -1,92 +1,27 @@
#include "grid.h"
-#include <string.h>
+//#include <string.h>
#include <assert.h>
#define LOG_MODULE "grid"
#define LOG_ENABLE_DBG 0
#include "log.h"
-#if 0
-struct cell *
-grid_get_range(struct grid *grid, int start, int *length)
-{
-#define min(x, y) ((x) < (y) ? (x) : (y))
- assert(*length <= grid->size);
-
- int real_start = (grid->offset + start) % grid->size;
- if (real_start < 0)
- real_start += grid->size;
- assert(real_start >= 0);
- assert(real_start < grid->size);
-
- *length = min(*length, grid->size - real_start);
- assert(real_start + *length <= grid->size);
-
- return &grid->cells[real_start];
-#undef min
-}
void
-grid_memclear(struct grid *grid, int start, int length)
+grid_swap_row(struct grid *grid, int row_a, int row_b)
{
- int left = length;
- while (left > 0) {
- int count = left;
- struct cell *cells = grid_get_range(grid, start, &count);
-
- assert(count > 0);
- assert(count <= left);
-
- memset(cells, 0, count * sizeof(cells[0]));
-
- left -= count;
- start += count;
- }
-}
-
-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];
-
- while (left > 0) {
- int count = left;
- struct cell *src_cells = grid_get_range(grid, src, &count);
-
- memcpy(&copy[copy_idx], src_cells, count * sizeof(copy[0]));
-
- left -= count;
- src += count;
- copy_idx += count;
- }
-
- left = length;
- copy_idx = 0;
+ assert(grid->offset >= 0);
+ assert(row_a != row_b);
+ assert(row_a >= 0);
+ assert(row_b >= 0);
- while (left > 0) {
- int count = left;
- struct cell *dst_cells = grid_get_range(grid, dst, &count);
+ int real_a = (grid->offset + row_a + grid->num_rows) % grid->num_rows;
+ int real_b = (grid->offset + row_b + grid->num_rows) % grid->num_rows;
- memcpy(dst_cells, &copy[copy_idx], count * sizeof(copy[0]));
+ struct row *tmp = grid->rows[real_a];
+ grid->rows[real_a] = grid->rows[real_b];
+ grid->rows[real_b] = tmp;
- left -= count;
- dst += count;
- copy_idx += count;
- }
+ grid->rows[real_a]->dirty = true;
+ grid->rows[real_b]->dirty = true;
}
-#endif
diff --git a/grid.h b/grid.h
index e170f6dd..ba31fe4e 100644
--- a/grid.h
+++ b/grid.h
@@ -17,27 +17,4 @@ grid_row_in_view(struct grid *grid, int row)
return grid->rows[(grid->view + row + grid->num_rows) % grid->num_rows];
}
-static inline void
-grid_swap_row(struct grid *grid, int row_a, int row_b)
-{
- assert(grid->offset >= 0);
- assert(row_a != row_b);
- assert(row_a >= 0);
- assert(row_b >= 0);
-
- int real_a = (grid->offset + row_a + grid->num_rows) % grid->num_rows;
- int real_b = (grid->offset + row_b + grid->num_rows) % grid->num_rows;
-
- struct row *tmp = grid->rows[real_a];
- grid->rows[real_a] = grid->rows[real_b];
- grid->rows[real_b] = tmp;
-
- grid->rows[real_a]->dirty = true;
- grid->rows[real_b]->dirty = true;
-}
-
-#if 0
-struct cell *grid_get_range(struct grid *grid, int start, int *length);
-void grid_memclear(struct grid *grid, int start, int length);
-void grid_memmove(struct grid *grid, int dst, int src, int length);
-#endif
+void grid_swap_row(struct grid *grid, int row_a, int row_b);