From 38d887ac644d114c242e273c9b605aca7fbb034d Mon Sep 17 00:00:00 2001 From: FauziAkram Date: Sun, 26 Apr 2026 09:25:41 +0200 Subject: [PATCH] Reuse Promotion Type Natively Piece promotion is generated, and then type_of(promotion) is used to retrieve the underlying type. The class Move provides .promotion_type() natively, meaning we can cache the type directly and avoid extracting it indirectly afterward. By extracting pt = m.promotion_type(); up front, we don't need to call type_of(promotion) iteratively inside the assertions or conditions below. closes https://github.com/official-stockfish/Stockfish/pull/6759 No functional change --- src/position.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 1f3eba7f6..521142a20 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -996,11 +996,11 @@ void Position::do_move(Move m, else if (m.type_of() == PROMOTION) { - Piece promotion = make_piece(us, m.promotion_type()); - PieceType promotionType = type_of(promotion); + PieceType pt = m.promotion_type(); + Piece promotion = make_piece(us, pt); assert(relative_rank(us, to) == RANK_8); - assert(type_of(promotion) >= KNIGHT && type_of(promotion) <= QUEEN); + assert(pt >= KNIGHT && pt <= QUEEN); dp.add_pc = promotion; dp.add_sq = to; @@ -1013,7 +1013,7 @@ void Position::do_move(Move m, ^ Zobrist::psq[pc][8 + pieceCount[pc]]; st->nonPawnKey[us] ^= Zobrist::psq[promotion][to]; - if (promotionType <= BISHOP) + if (pt <= BISHOP) st->minorPieceKey ^= Zobrist::psq[promotion][to]; // Update material