Skip to content

Commit 2b6a7fa

Browse files
committed
unwrap_or_clone is fast as fuck and safe...
1 parent 7e87156 commit 2b6a7fa

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/core/cache.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ impl<T> CachedValue<T> {
3030

3131
impl<T> CachedValue<T>
3232
where
33-
T: std::fmt::Debug,
33+
T: std::fmt::Debug + std::clone::Clone,
3434
{
35-
pub fn unwrap(self) -> T {
36-
Arc::try_unwrap(self.0).unwrap()
35+
#[inline]
36+
pub fn clone_inner(self) -> T {
37+
Arc::unwrap_or_clone(self.0)
3738
}
3839
}
3940

@@ -50,7 +51,7 @@ impl<T> VirolutionCache<T> {
5051

5152
pub fn cache_get(&self, key: &usize) -> Option<CachedValue<T>> {
5253
let mut cache = self.cache.lock().unwrap();
53-
cache.cache_get(&key).cloned()
54+
cache.cache_get(key).cloned()
5455
}
5556

5657
pub fn cache_set(&self, key: usize, value: T) -> CachedValue<T> {

src/core/haplotype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl Haplotype {
353353
format!(
354354
";{position}:{}->{}",
355355
char::from(STRICT_ENCODE[&f]),
356-
char::from(STRICT_ENCODE[&t])
356+
char::from(STRICT_ENCODE[t])
357357
)
358358
.as_str(),
359359
);
@@ -364,7 +364,7 @@ impl Haplotype {
364364
format!(
365365
";{position}:{}->{}",
366366
char::from(STRICT_ENCODE[&wt_symbol]),
367-
char::from(STRICT_ENCODE[&t])
367+
char::from(STRICT_ENCODE[t])
368368
)
369369
.as_str(),
370370
)
@@ -678,7 +678,7 @@ impl Mutant {
678678
}
679679

680680
pub fn get_mutations(&self) -> CachedValue<HashMap<usize, Symbol>> {
681-
let mut mutations = self.ancestor.get_mutations().unwrap().clone();
681+
let mut mutations = self.ancestor.get_mutations().clone_inner();
682682

683683
let wt_ref = self.wildtype.upgrade().unwrap();
684684

0 commit comments

Comments
 (0)