From 1bf9147a6e65198f2127251d593f835df0d20d5a Mon Sep 17 00:00:00 2001 From: Vis Virial Date: Tue, 29 Jun 2021 07:14:01 +0900 Subject: [PATCH] Optimize `Transaction.get_vsize()` (thanks @TheBlueMatt). --- src/blockdata/transaction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 8906daef..7fef077b 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -430,7 +430,7 @@ impl Transaction { #[inline] pub fn get_vsize(&self) -> usize { let weight = self.get_weight(); - (weight / WITNESS_SCALE_FACTOR) + if weight % WITNESS_SCALE_FACTOR == 0 { 0 } else { 1 } + (weight + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR } /// Internal utility function for get_{size,weight}