]> git.sesse.net Git - stockfish/commitdiff
Don't copy a full Position object in print()
authorMarco Costalba <mcostalba@gmail.com>
Sun, 21 Oct 2012 22:53:17 +0000 (00:53 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 21 Oct 2012 22:55:16 +0000 (00:55 +0200)
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

index c693b660cc7c3a7a80fa7f6502a17fa16d5c64a7..3f81994611975aaaf31c8f397b1613cf85edb297 100644 (file)
@@ -400,10 +400,8 @@ void Position::print(Move move) const {
   sync_cout;
 
   if (move)
   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<Position*>(this), move);
 
   for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
       if (piece_on(sq) != NO_PIECE)
 
   for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
       if (piece_on(sq) != NO_PIECE)