Merge rust-bitcoin/rust-bitcoin#1538: A crash course in rust perf (#988 nits)

1a409ecc8e Use &[u8] instead of Cursor as Read (DanGould)
81ca10701a Use as_ref() instead of costly clone() (DanGould)
debcce6a03 Improve magic bytes push performance (DanGould)

Pull request description:

  A follow up to address [nits in  #988](https://github.com/rust-bitcoin/rust-bitcoin/pull/988#pullrequestreview-1233687052)

ACKs for top commit:
  tcharding:
    ACK 1a409ecc8e
  elichai:
    ACK 1a409ecc8e
  sanket1729:
    utACK 1a409ecc8e

Tree-SHA512: bc6c538d8f92b0efa8063ba33bb47f0c9dc2f99eb5db267b66aa01fc70fd634695a0cd9c27fb0f33e3498628729a8e0f622d9876dc1c83fab4a1e46484d425b2
This commit is contained in:
sanket1729 2023-01-11 02:38:17 -08:00
commit ac6340943c
No known key found for this signature in database
GPG Key ID: 648FFB183E0870A2
4 changed files with 5 additions and 5 deletions

View File

@ -54,7 +54,7 @@ macro_rules! impl_psbtmap_deserialize {
($thing:ty) => { ($thing:ty) => {
impl $crate::psbt::serialize::Deserialize for $thing { impl $crate::psbt::serialize::Deserialize for $thing {
fn deserialize(bytes: &[u8]) -> Result<Self, $crate::consensus::encode::Error> { fn deserialize(bytes: &[u8]) -> Result<Self, $crate::consensus::encode::Error> {
let mut decoder = crate::io::Cursor::new(bytes); let mut decoder = bytes;
Self::decode(&mut decoder) Self::decode(&mut decoder)
} }
} }

View File

@ -11,7 +11,7 @@ use crate::prelude::*;
use core::fmt; use core::fmt;
use core::convert::TryFrom; use core::convert::TryFrom;
use crate::io::{self, Cursor}; use crate::io;
use crate::consensus::encode::{self, ReadExt, WriteExt, Decodable, Encodable, VarInt, serialize, deserialize, MAX_VEC_SIZE}; use crate::consensus::encode::{self, ReadExt, WriteExt, Decodable, Encodable, VarInt, serialize, deserialize, MAX_VEC_SIZE};
use crate::psbt::Error; use crate::psbt::Error;
@ -125,7 +125,7 @@ impl Serialize for Pair {
impl Deserialize for Pair { impl Deserialize for Pair {
fn deserialize(bytes: &[u8]) -> Result<Self, encode::Error> { fn deserialize(bytes: &[u8]) -> Result<Self, encode::Error> {
let mut decoder = Cursor::new(bytes); let mut decoder = bytes;
Pair::decode(&mut decoder) Pair::decode(&mut decoder)
} }
} }

View File

@ -53,7 +53,7 @@ impl PartiallySignedTransaction {
let mut buf: Vec<u8> = Vec::new(); let mut buf: Vec<u8> = Vec::new();
// <magic> // <magic>
buf.extend(b"psbt"); buf.extend_from_slice(b"psbt");
buf.push(0xff_u8); buf.push(0xff_u8);

View File

@ -437,7 +437,7 @@ fn finalize_psbt(mut psbt: Psbt) -> Psbt {
// Input 1: SegWit UTXO // Input 1: SegWit UTXO
let script_sig = script::Builder::new() let script_sig = script::Builder::new()
.push_slice(psbt.inputs[1].redeem_script.clone().unwrap().as_bytes()) .push_slice(psbt.inputs[1].redeem_script.as_ref().unwrap().as_bytes())
.into_script(); .into_script();
psbt.inputs[1].final_script_sig = Some(script_sig); psbt.inputs[1].final_script_sig = Some(script_sig);