Skip to content

Commit bc359c0

Browse files
committed
Clone sub instead of creating new Arc
Currently we are creating a new `Arc<Policy::Threshold>` from the pieces of `sub` that we pattern matched on. We can just clone the original `sub` instead.
1 parent 92a41f8 commit bc359c0

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/policy/semantic.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,13 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
439439
Policy::Trivial | Policy::Unsatisfiable => {}
440440
Policy::Threshold(ref k, ref subs) => {
441441
match (is_and, is_or) {
442-
(true, true) => {
443-
// means m = n = 1, thresh(1,X) type thing.
444-
ret_subs.push(Arc::new(Policy::Threshold(*k, subs.to_vec())));
445-
}
442+
(true, true) => ret_subs.push(Arc::clone(&sub)), // m = n = 1, thresh(1,X) type thing.
446443
(true, false) if *k == subs.len() => ret_subs.extend(subs.to_vec()), // and case
447444
(false, true) if *k == 1 => ret_subs.extend(subs.to_vec()), // or case
448-
_ => ret_subs.push(Arc::new(Policy::Threshold(*k, subs.to_vec()))),
445+
_ => ret_subs.push(Arc::clone(&sub)),
449446
}
450447
}
451-
x => ret_subs.push(Arc::new(x.clone())),
448+
_ => ret_subs.push(Arc::clone(&sub)),
452449
}
453450
}
454451
// Now reason about m of n threshold
@@ -458,8 +455,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
458455
Policy::Unsatisfiable
459456
} else if ret_subs.len() == 1 {
460457
let policy = ret_subs.pop().unwrap();
461-
// Only one strong reference because we created the Arc when pushing to ret_subs.
462-
Arc::try_unwrap(policy).unwrap()
458+
(*policy).clone() // I'm lost now, can we try_unwrap still?
463459
} else if is_and {
464460
Policy::Threshold(ret_subs.len(), ret_subs)
465461
} else if is_or {

0 commit comments

Comments
 (0)