From 1c4c158053b480a60d8a1d522b943beffd2782d1 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 3 Nov 2024 11:42:19 -0500 Subject: [PATCH] perf: borrow in the evalscore piece changes --- src/eval.rs | 12 ++++++------ src/lib.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/eval.rs b/src/eval.rs index 16426fc..8936407 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -52,14 +52,14 @@ pub(crate) mod eval_score { /// Add/remove the value of a piece based on the PST. /// /// Use +1 as sign to add, -1 to delete. - fn change_piece(&mut self, pc: ColPiece, sq: Square, sign: i8) { + fn change_piece(&mut self, pc: &ColPiece, sq: &Square, sign: i8) { assert!(sign == 1 || sign == -1); let tables = [ - (&mut self.midgame, PST_MIDGAME), - (&mut self.endgame, PST_ENDGAME), + (&mut self.midgame, &PST_MIDGAME), + (&mut self.endgame, &PST_ENDGAME), ]; for (phase, pst) in tables { - phase.score += pst[pc.pc][pc.col][sq] * EvalInt::from(pc.col.sign() * sign); + phase.score += pst[pc.pc][pc.col][*sq] * EvalInt::from(pc.col.sign() * sign); } use crate::Piece::*; @@ -73,12 +73,12 @@ pub(crate) mod eval_score { } /// Remove the value of a piece on a square. - pub fn del_piece(&mut self, pc: ColPiece, sq: Square) { + pub fn del_piece(&mut self, pc: &ColPiece, sq: &Square) { self.change_piece(pc, sq, -1); } /// Add the value of a piece on a square. - pub fn add_piece(&mut self, pc: ColPiece, sq: Square) { + pub fn add_piece(&mut self, pc: &ColPiece, sq: &Square) { self.change_piece(pc, sq, 1); } } diff --git a/src/lib.rs b/src/lib.rs index da59360..3d23516 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -469,7 +469,7 @@ impl Board { let pl = &mut self[pc.col]; pl[pc.into()].on_sq(sq); *self.mail.sq_mut(sq) = Some(pc); - self.eval.add_piece(pc, sq); + self.eval.add_piece(&pc, &sq); dest_pc } @@ -487,7 +487,7 @@ impl Board { let pl = &mut self[pc.col]; pl[pc.into()].off_sq(sq); *self.mail.sq_mut(sq) = None; - self.eval.del_piece(pc, sq); + self.eval.del_piece(&pc, &sq); Some(pc) } else { None