From 5fc8b27db9a1d9fffeb46d0e2ef40803c55fd4f9 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Mon, 22 Oct 2012 00:53:17 +0200 Subject: [PATCH] Don't copy a full Position object in print() Function move_to_san() requires the Position to be passed by referenced because a do/undo move is done inside the function to detect a possible mate and to add to the san string the corresponding '#' suffix. Instead of passing a copy of current position pass directly the original position object after const casting it. This has the advantage to avoid a costly Position copy, on the down side a bench test could report different searched nodes if print(move) is used, due to the additionals do_move() calls. No functional change. --- src/position.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index c693b660..3f819946 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -400,10 +400,8 @@ void Position::print(Move move) const { sync_cout; if (move) - { - Position p(*this); - cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move); - } + cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") + << move_to_san(*const_cast(this), move); for (Square sq = SQ_A1; sq <= SQ_H8; sq++) if (piece_on(sq) != NO_PIECE) -- 2.39.2