Skip to content

Commit 9beb72b

Browse files
committed
ref: change passes_filter to cell, to avoid mutability in filter_database
1 parent 03da759 commit 9beb72b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

crates/legacy-zebra/src/thordb.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,13 +1061,13 @@ impl ThorHash {
10611061
FILTER_DATABASE
10621062
Applies the current filter rules to the database DB.
10631063
*/
1064-
fn filter_database(db: &mut DatabaseType, tournaments_: &[TournamentType], players_: &[PlayerType], filter_: &FilterType) {
1064+
fn filter_database(db: &DatabaseType, tournaments_: &[TournamentType], players_: &[PlayerType], filter_: &FilterType) {
10651065
let mut category: i32 = 0;
10661066
let mut passes_filter: i32 = 0;
10671067
let mut year: i32 = 0;
10681068
let mut i = 0;
10691069
while i < (*db).count {
1070-
let game = (*db).games.offset(i as isize);
1070+
let game = (*db).games.as_slice().offset(i as isize);
10711071
passes_filter = 1;
10721072
/* Apply the tournament filter */
10731073
if passes_filter != 0 && (*tournaments_.offset((*game).tournament_no as isize)).selected == 0 {
@@ -1115,7 +1115,7 @@ fn filter_database(db: &mut DatabaseType, tournaments_: &[TournamentType], playe
11151115
}
11161116
passes_filter = category & filter_.game_categories
11171117
}
1118-
(*game).passes_filter = passes_filter as i16;
1118+
(*game).passes_filter.set(passes_filter as i16);
11191119
i += 1
11201120
};
11211121
}
@@ -2437,7 +2437,7 @@ pub unsafe fn database_search(in_board: &[i32], side_to_move: i32) {
24372437
i = 0;
24382438
while i < (*current_db).count {
24392439
let game = (*current_db).games.as_slice().offset(i as isize);
2440-
if (*game).passes_filter != 0 {
2440+
if (*game).passes_filter.get() != 0 {
24412441
if disc_count[0] == (*game).black_disc_count[move_count as usize] as i32 {
24422442
if position_match(game, &mut board, &mut thor_hash, &mut thor_opening_tree, move_count, side_to_move, &mut shape_lo, &mut shape_hi, corner_mask, target_hash1, target_hash2) != 0 {
24432443
let ref mut fresh7 = *thor_search.match_list.offset(game.sort_order.get() as _);

crates/thordb-types/thordb-types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub struct GameType {
119119
pub corner_descriptor: u32,
120120
pub sort_order: Cell<i32>,
121121
pub matching_symmetry: Cell<i16>,
122-
pub passes_filter: i16,
122+
pub passes_filter: Cell<i16>,
123123
}
124124

125125
impl GameType {
@@ -142,7 +142,7 @@ impl GameType {
142142
corner_descriptor: 0,
143143
sort_order: Cell::new(0),
144144
matching_symmetry: Cell::new(0),
145-
passes_filter: 0,
145+
passes_filter: Cell::new(0),
146146
}
147147
}
148148
}
@@ -379,7 +379,7 @@ impl SearchResultType {
379379
in the list of matching games generated by DATABASE_SEARCH.
380380
*/
381381

382-
unsafe fn get_thor_game_move_count(&self, index: i32) -> i32 {
382+
fn get_thor_game_move_count(&self, index: i32) -> i32 {
383383
if index < 0 || index >= self.match_count {
384384
/* Bad index */
385385
return -1

0 commit comments

Comments
 (0)