From 0e4506cd524539906f24a0a13be7472d1162b345 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Tue, 25 Feb 2020 19:32:11 +0100 Subject: [PATCH] Implement support for board preallocation --- board.c | 5 +---- board.h | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/board.c b/board.c index c0d70be..070c09d 100644 --- a/board.c +++ b/board.c @@ -597,6 +597,7 @@ board_place ( struct board * board_place_speculative ( const struct board *board, + struct board *board_duplicate, board_pos x, board_pos y, element_value value @@ -608,14 +609,10 @@ board_place_speculative ( if (board_can_place_value (board, x, y, value)) { /* Create duplicate and place value */ - struct board *board_duplicate = malloc (sizeof (struct board)); board_copy (board, board_duplicate); if (! board_place (board_duplicate, x, y, value)) - { - free (board_duplicate); return NULL; - } return board_duplicate; } diff --git a/board.h b/board.h index 214dde8..d40c610 100644 --- a/board.h +++ b/board.h @@ -261,6 +261,7 @@ board_place ( struct board * board_place_speculative ( const struct board *board, + struct board *board_duplicate, board_pos x, board_pos y, element_value value