Merge rust-bitcoin/rust-bitcoin#1672: Accept borrowed values in InputWeightPrediction::new()
f62885890d
Accept borrowed values in InputWeightPrediction::new() (Harshil Jani) Pull request description: The updated implementation accepts borrowed values and now it is convenient to use with slices. closes #1669 ACKs for top commit: Kixunil: ACKf62885890d
apoelstra: ACKf62885890d
Tree-SHA512: 59459e640a9676f3c293b10227026635b06fe55d31ffd2da606c0c70aac614694f48ba2f43bb3e8dce047e35e007fb2b09528d7dcfd0772e6b678680e2d781ea
This commit is contained in:
commit
277eef486a
|
@ -1278,11 +1278,12 @@ pub struct InputWeightPrediction {
|
||||||
|
|
||||||
impl InputWeightPrediction {
|
impl InputWeightPrediction {
|
||||||
/// Computes the prediction for a single input.
|
/// Computes the prediction for a single input.
|
||||||
pub fn new<I>(input_script_len: usize, witness_element_lengths: I) -> Self
|
pub fn new<T>(input_script_len: usize, witness_element_lengths: T) -> Self
|
||||||
where I: IntoIterator<Item = usize>,
|
where T :IntoIterator, T::Item:Borrow<usize>,
|
||||||
{
|
{
|
||||||
let (count, total_size) = witness_element_lengths.into_iter()
|
let (count, total_size) = witness_element_lengths.into_iter()
|
||||||
.fold((0, 0), |(count, total_size), elem_len| {
|
.fold((0, 0), |(count, total_size), elem_len| {
|
||||||
|
let elem_len = *elem_len.borrow();
|
||||||
let elem_size = elem_len + VarInt(elem_len as u64).len();
|
let elem_size = elem_len + VarInt(elem_len as u64).len();
|
||||||
(count + 1, total_size + elem_size)
|
(count + 1, total_size + elem_size)
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue