Skip to content

Commit

Permalink
Rewrite Display implementation to avoid extra allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
optout21 committed Aug 13, 2023
1 parent b845717 commit 7561dce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Readable for PaymentId {

impl core::fmt::Display for PaymentId {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.write_str(&self.0.to_hex())
crate::util::logger::DebugBytes(&self.0).fmt(f)
}
}

Expand Down
6 changes: 2 additions & 4 deletions lightning/src/ln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
pub struct PaymentHash(pub [u8; 32]);

use bitcoin::hashes::hex::ToHex;

impl core::fmt::Display for PaymentHash {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.write_str(&self.0.to_hex())
crate::util::logger::DebugBytes(&self.0).fmt(f)
}
}

Expand All @@ -91,7 +89,7 @@ pub struct PaymentPreimage(pub [u8; 32]);

impl core::fmt::Display for PaymentPreimage {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.write_str(&self.0.to_hex())
crate::util::logger::DebugBytes(&self.0).fmt(f)
}
}

Expand Down
6 changes: 3 additions & 3 deletions lightning/src/routing/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bitcoin::secp256k1;

use bitcoin::hashes::sha256d::Hash as Sha256dHash;
use bitcoin::hashes::Hash;
use bitcoin::hashes::hex::{FromHex, ToHex};
use bitcoin::hashes::hex::FromHex;
use bitcoin::hash_types::BlockHash;

use bitcoin::network::constants::Network;
Expand Down Expand Up @@ -88,12 +88,12 @@ impl NodeId {

impl fmt::Debug for NodeId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "NodeId({})", self.0.to_hex())
write!(f, "NodeId({})", crate::util::logger::DebugBytes(&self.0))
}
}
impl fmt::Display for NodeId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0.to_hex())
crate::util::logger::DebugBytes(&self.0).fmt(f)
}
}

Expand Down

0 comments on commit 7561dce

Please sign in to comment.