Skip to content

Commit fbb4da3

Browse files
committed
Remove lazy_static from the codebase.
This means we're using `LazyLock` for all relevant deferred initialization. Closes #109
1 parent 9597b37 commit fbb4da3

4 files changed

Lines changed: 17 additions & 35 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ erased_set = "0.8.0"
1919
hex = "0.4.3"
2020
indicatif = "0.18.2"
2121
instant = { version = "0.1.13", features = ["wasm-bindgen"] }
22-
lazy_static = "1.5.0"
2322
multiset = "0.0.5"
2423
num-integer = "0.1.46"
2524
rand = "0.9.2"

src/lib/scramble/puzzles/square1/phase1.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ use super::{
3434
square1_shape_traversal_filter::shape_traversal_filter_pattern,
3535
};
3636

37-
use lazy_static::lazy_static;
38-
3937
// Note that this entire struct consists of single coordinate.
4038
// The fields themselves are more like "subcoordinates" rather than coordinates in themselves.
4139
// TODO: Implement automatic coordinate composition?
@@ -75,16 +73,14 @@ pub(crate) type Square1Phase1Puzzle =
7573
// TODO: allow flipping this depending on whether this is for a scramble (backwards) or a solution (forwards)?
7674
const D_SQ_MOVE_RESTRICTED_RANGE: Range<i32> = -3..3;
7775

76+
const D_MOVE_CLASS_INDEX: MoveClassIndex = MoveClassIndex(1);
77+
7878
// This is exported so it can be reused by phase 2.
7979
#[allow(non_snake_case)]
8080
pub fn restrict_D_move(
8181
move_transformation_info: &MoveTransformationInfo<Square1Phase1Puzzle>,
8282
) -> bool {
83-
lazy_static! {
84-
// TODO: perform a one-time check that this matches the search generator indexing.
85-
static ref D_MOVE_CLASS_INDEX: MoveClassIndex = MoveClassIndex(1);
86-
}
87-
if move_transformation_info.move_class_index != *D_MOVE_CLASS_INDEX {
83+
if move_transformation_info.move_class_index != D_MOVE_CLASS_INDEX {
8884
return true;
8985
}
9086
let Move { amount, .. } = move_transformation_info.r#move;

src/lib/scramble/puzzles/square1/phase2.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use cubing::{
22
alg::{parse_alg, parse_move, Alg, Move},
33
kpuzzle::{InvalidAlgError, KPattern, KPuzzle, KPuzzleOrbitInfo},
44
};
5-
use lazy_static::lazy_static;
6-
use std::cmp::max;
5+
use std::{cmp::max, sync::LazyLock};
76

87
use crate::{
98
_internal::{
@@ -107,22 +106,23 @@ pub(crate) struct Square0EquatorlessPattern {
107106
pub(crate) pattern: KPattern,
108107
}
109108

109+
static WEDGES_ORBIT_INFO: LazyLock<&'static KPuzzleOrbitInfo> = LazyLock::new(|| {
110+
let orbit_info: &'static KPuzzleOrbitInfo =
111+
&square1_unbandaged_kpuzzle().data.ordered_orbit_info[0];
112+
assert_eq!(orbit_info.name.0, "WEDGES");
113+
orbit_info
114+
});
115+
110116
const NUM_SQUARE0_EQUATORLESS_WEDGES: u8 = 8;
111117
impl Square0EquatorlessPattern {
112118
// TODO: define this as a static method instead and just output a `KPattern` instead of a `Square0EquatorlessCoordinate`? Or ideally add a type-safe way for coordinates to us different masks/conversions into the same coordinates (and tables).
113119
fn from_edges_pattern(square1_edges_pattern: &KPattern) -> Self {
114-
lazy_static! {
115-
static ref orbit_info: &'static KPuzzleOrbitInfo =
116-
&square1_unbandaged_kpuzzle().data.ordered_orbit_info[0];
117-
};
118-
assert_eq!(orbit_info.name.0, "WEDGES"); // TODO: only do this at orbit info time, using the former pattern for retrieving an `OrbitInfo` from a definition.
119-
120120
let mut square0_equatorless_pattern =
121121
square0_equatorless_kpuzzle().default_pattern().clone();
122122

123123
let mut square0_equatorless_i = 0;
124-
for square1_i in 0..orbit_info.num_pieces {
125-
let piece = square1_edges_pattern.get_piece(&orbit_info, square1_i);
124+
for square1_i in 0..WEDGES_ORBIT_INFO.num_pieces {
125+
let piece = square1_edges_pattern.get_piece(*WEDGES_ORBIT_INFO, square1_i);
126126
let square0_piece = match piece {
127127
// TODO: unify this with `WEDGE_TYPE_LOOKUP`?
128128
0 => None,
@@ -153,7 +153,7 @@ impl Square0EquatorlessPattern {
153153
};
154154
if let Some(square0_piece) = square0_piece {
155155
square0_equatorless_pattern.set_piece(
156-
&orbit_info,
156+
*WEDGES_ORBIT_INFO,
157157
square0_equatorless_i,
158158
square0_piece,
159159
);
@@ -168,18 +168,12 @@ impl Square0EquatorlessPattern {
168168

169169
// TODO: define this as a static method instead and just output a `KPattern` instead of a `Square0EquatorlessCoordinate`? Or ideally add a type-safe way for coordinates to us different masks/conversions into the same coordinates (and tables).
170170
fn from_corners_pattern(square1_corners_pattern: &KPattern) -> Self {
171-
lazy_static! {
172-
static ref orbit_info: &'static KPuzzleOrbitInfo =
173-
&square1_unbandaged_kpuzzle().data.ordered_orbit_info[0];
174-
};
175-
assert_eq!(orbit_info.name.0, "WEDGES"); // TODO: only do this at orbit info time, using the former pattern for retrieving an `OrbitInfo` from a definition.
176-
177171
let mut square0_equatorless_pattern =
178172
square0_equatorless_kpuzzle().default_pattern().clone();
179173

180174
let mut square0_equatorless_i = 0;
181-
for square1_i in 0..orbit_info.num_pieces {
182-
let piece = square1_corners_pattern.get_piece(&orbit_info, square1_i);
175+
for square1_i in 0..WEDGES_ORBIT_INFO.num_pieces {
176+
let piece = square1_corners_pattern.get_piece(&WEDGES_ORBIT_INFO, square1_i);
183177
let square0_piece = match piece {
184178
// TODO: unify this with `WEDGE_TYPE_LOOKUP`?
185179
0 => Some(0),
@@ -210,7 +204,7 @@ impl Square0EquatorlessPattern {
210204
};
211205
if let Some(square0_piece) = square0_piece {
212206
square0_equatorless_pattern.set_piece(
213-
&orbit_info,
207+
*WEDGES_ORBIT_INFO,
214208
square0_equatorless_i,
215209
square0_piece,
216210
);

0 commit comments

Comments
 (0)