Skip to content

Commit d3d4564

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 285214e commit d3d4564

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
@@ -430,16 +430,13 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
430430
Policy::Trivial | Policy::Unsatisfiable => {}
431431
Policy::Threshold(ref k, ref subs) => {
432432
match (is_and, is_or) {
433-
(true, true) => {
434-
// means m = n = 1, thresh(1,X) type thing.
435-
ret_subs.push(Arc::new(Policy::Threshold(*k, subs.to_vec())));
436-
}
433+
(true, true) => ret_subs.push(Arc::clone(&sub)), // m = n = 1, thresh(1,X) type thing.
437434
(true, false) if *k == subs.len() => ret_subs.extend(subs.to_vec()), // and case
438435
(false, true) if *k == 1 => ret_subs.extend(subs.to_vec()), // or case
439-
_ => ret_subs.push(Arc::new(Policy::Threshold(*k, subs.to_vec()))),
436+
_ => ret_subs.push(Arc::clone(&sub)),
440437
}
441438
}
442-
x => ret_subs.push(Arc::new(x.clone())),
439+
_ => ret_subs.push(Arc::clone(&sub)),
443440
}
444441
}
445442
// Now reason about m of n threshold
@@ -449,8 +446,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
449446
Policy::Unsatisfiable
450447
} else if ret_subs.len() == 1 {
451448
let policy = ret_subs.pop().unwrap();
452-
// Only one strong reference because we created the Arc when pushing to ret_subs.
453-
Arc::try_unwrap(policy).unwrap()
449+
(*policy).clone() // More than one strong reference, can't use `try_unwrap()`.
454450
} else if is_and {
455451
Policy::Threshold(ret_subs.len(), ret_subs)
456452
} else if is_or {

0 commit comments

Comments
 (0)