Remove quadratic algorithm
Currently we loop over transaction inputs within a loop over transaction inputs - ouch. Cache the `use_segwit_serialization` outside the iteration loop. Fix: #2357
This commit is contained in:
parent
9eec1082ec
commit
a338a61cc3
|
@ -773,8 +773,9 @@ impl Transaction {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn total_size(&self) -> usize {
|
pub fn total_size(&self) -> usize {
|
||||||
let mut size: usize = 4; // Serialized length of a u32 for the version number.
|
let mut size: usize = 4; // Serialized length of a u32 for the version number.
|
||||||
|
let use_segwit = self.use_segwit_serialization();
|
||||||
|
|
||||||
if self.use_segwit_serialization() {
|
if use_segwit {
|
||||||
size += 2; // 1 byte for the marker and 1 for the flag.
|
size += 2; // 1 byte for the marker and 1 for the flag.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -783,7 +784,7 @@ impl Transaction {
|
||||||
.input
|
.input
|
||||||
.iter()
|
.iter()
|
||||||
.map(|input| {
|
.map(|input| {
|
||||||
if self.use_segwit_serialization() {
|
if use_segwit {
|
||||||
input.total_size()
|
input.total_size()
|
||||||
} else {
|
} else {
|
||||||
input.base_size()
|
input.base_size()
|
||||||
|
|
Loading…
Reference in New Issue