Merge rust-bitcoin/rust-bitcoin#2358: Remove quadratic algorithm

a338a61cc3 Remove quadratic algorithm (Tobin C. Harding)

Pull request description:

  Currently we loop over transaction inputs within a loop over transaction inputs - ouch.

  Cache the `use_segwit_serialization` outside the iteration loop.

  Fix: #2357

ACKs for top commit:
  Kixunil:
    ACK a338a61cc3
  apoelstra:
    ACK a338a61cc3

Tree-SHA512: 91d0b46b235db57d9c28fc8da5d43a52c76a29916797a4ec44273b91eb120a928050a79cdbd704b922635dd2130db7b6e7863fd10e878eee52882c661af54c11
This commit is contained in:
Andrew Poelstra 2024-01-19 15:20:15 +00:00
commit 01c8f2021e
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 3 additions and 2 deletions

View File

@ -773,8 +773,9 @@ impl Transaction {
#[inline]
pub fn total_size(&self) -> usize {
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.
}
@ -783,7 +784,7 @@ impl Transaction {
.input
.iter()
.map(|input| {
if self.use_segwit_serialization() {
if use_segwit {
input.total_size()
} else {
input.base_size()