Skip to content

Commit 7561dce

Browse files
committed
Rewrite Display implementation to avoid extra allocation
1 parent b845717 commit 7561dce

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

lightning/src/ln/channelmanager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl Readable for PaymentId {
243243

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

lightning/src/ln/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
7575
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
7676
pub struct PaymentHash(pub [u8; 32]);
7777

78-
use bitcoin::hashes::hex::ToHex;
79-
8078
impl core::fmt::Display for PaymentHash {
8179
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
82-
f.write_str(&self.0.to_hex())
80+
crate::util::logger::DebugBytes(&self.0).fmt(f)
8381
}
8482
}
8583

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

9290
impl core::fmt::Display for PaymentPreimage {
9391
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
94-
f.write_str(&self.0.to_hex())
92+
crate::util::logger::DebugBytes(&self.0).fmt(f)
9593
}
9694
}
9795

lightning/src/routing/gossip.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bitcoin::secp256k1;
1616

1717
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
1818
use bitcoin::hashes::Hash;
19-
use bitcoin::hashes::hex::{FromHex, ToHex};
19+
use bitcoin::hashes::hex::FromHex;
2020
use bitcoin::hash_types::BlockHash;
2121

2222
use bitcoin::network::constants::Network;
@@ -88,12 +88,12 @@ impl NodeId {
8888

8989
impl fmt::Debug for NodeId {
9090
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
91-
write!(f, "NodeId({})", self.0.to_hex())
91+
write!(f, "NodeId({})", crate::util::logger::DebugBytes(&self.0))
9292
}
9393
}
9494
impl fmt::Display for NodeId {
9595
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
96-
write!(f, "{}", self.0.to_hex())
96+
crate::util::logger::DebugBytes(&self.0).fmt(f)
9797
}
9898
}
9999

0 commit comments

Comments
 (0)