Skip to content

Commit 9bb7a7e

Browse files
committed
refactor(hardlink): extract sorting_key method on ReflectionEntry
https://claude.ai/code/session_01QP9wZyoZcGmJsEsA66ZRok
1 parent 39cbd96 commit 9bb7a7e

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/hardlink/hardlink_list/reflection.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,23 @@ impl<Size> ReflectionEntry<Size> {
8787
let paths = paths.into();
8888
(InodeKey { ino, dev }, Value { size, links, paths })
8989
}
90+
91+
/// Sorting key to be used in the "sort by key" family of functions.
92+
///
93+
/// Sort by the inode number first, then by the device number.
94+
///
95+
/// This function returns a pair of 2 `u64`s instead a pair of 2 wrapper
96+
/// types because we prefer them not to have to implement `Ord`.
97+
#[inline]
98+
fn sorting_key(&self) -> (u64, u64) {
99+
(u64::from(self.ino), u64::from(self.dev))
100+
}
90101
}
91102

92103
impl<Size> From<Vec<ReflectionEntry<Size>>> for Reflection<Size> {
93104
/// Sort the list by inode numbers and device numbers, then create the reflection.
94105
fn from(list: Vec<ReflectionEntry<Size>>) -> Self {
95-
list.into_sorted_unstable_by_key(|entry| (u64::from(entry.ino), u64::from(entry.dev)))
106+
list.into_sorted_unstable_by_key(ReflectionEntry::sorting_key)
96107
.pipe(Reflection)
97108
}
98109
}

0 commit comments

Comments
 (0)