Skip to content

Commit 4ea9fb8

Browse files
committed
Minor refactor
1 parent a547575 commit 4ea9fb8

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/filesystem/search_id.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::num::Wrapping;
2+
13
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
24
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
35
/// Unique ID used to search for files and directories in the open File/Directory lists
@@ -7,19 +9,21 @@ pub struct SearchId(pub(crate) u32);
79
///
810
/// This object will always return a different ID.
911
pub struct IdGenerator {
10-
next_id: u32,
12+
next_id: Wrapping<u32>,
1113
}
1214

1315
impl IdGenerator {
1416
/// Create a new [`IdGenerator`].
1517
pub const fn new() -> Self {
16-
Self { next_id: 0 }
18+
Self {
19+
next_id: Wrapping(0),
20+
}
1721
}
1822

1923
/// Generate a new, unique [`SearchId`].
2024
pub fn get(&mut self) -> SearchId {
2125
let id = self.next_id;
22-
self.next_id = self.next_id.wrapping_add(1);
23-
SearchId(id)
26+
self.next_id += 1;
27+
SearchId(id.0)
2428
}
2529
}

src/volume_mgr.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -737,16 +737,20 @@ where
737737
}
738738
}
739739

740-
fn cluster_position_by_id(list: &[ClusterDescriptor], id_to_find: SearchId) -> Option<usize> {
741-
list.iter().position(|f| f.compare_id(id_to_find))
740+
fn cluster_position_by_id(
741+
cluster_list: &[ClusterDescriptor],
742+
id_to_find: SearchId,
743+
) -> Option<usize> {
744+
cluster_list.iter().position(|f| f.compare_id(id_to_find))
742745
}
743746

744747
fn cluster_already_open(
745-
vec: &[ClusterDescriptor],
748+
cluster_list: &[ClusterDescriptor],
746749
volume_idx: VolumeIdx,
747750
cluster: Cluster,
748751
) -> bool {
749-
vec.iter()
752+
cluster_list
753+
.iter()
750754
.any(|d| d.compare_volume_and_cluster(volume_idx, cluster))
751755
}
752756

0 commit comments

Comments
 (0)