What changed, and why it matters
This commit only adds Rust compiler hints (`#[inline]`) to a few small functions that convert Bitcoin merkle node values to and from bytes. It does not change what the code does, only gives the compiler a stronger suggestion to embed these tiny functions at call sites. There is no security relevance.
No security action needed. Treat as a normal optimization/style commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds #[inline] attributes to encoder(), decoder(), new(), and default() implementations for TxMerkleNode and WitnessMerkleNode, mirroring existing BlockHash style. This is a pure performance/code-style hint with no functional, API, or behavioral change. No input validation, parsing logic, arithmetic, memory handling, or cryptographic operations are modified.
Changed components
primitives/src/hash_types/transaction_merkle_node.rsprimitives/src/hash_types/witness_merkle_node.rsInspect captured patch +8 / −0
diff --git a/primitives/src/hash_types/transaction_merkle_node.rs b/primitives/src/hash_types/transaction_merkle_node.rs
index e4b92c50..c8746b58 100644
--- a/primitives/src/hash_types/transaction_merkle_node.rs
+++ b/primitives/src/hash_types/transaction_merkle_node.rs
@@ -52,6 +52,7 @@ impl TxMerkleNode {
impl encoding::Encodable for TxMerkleNode {
type Encoder<'e> = TxMerkleNodeEncoder<'e>;
+ #[inline]
fn encoder(&self) -> Self::Encoder<'_> {
TxMerkleNodeEncoder::new(encoding::ArrayRefEncoder::without_length_prefix(
self.as_byte_array(),
@@ -61,6 +62,7 @@ impl encoding::Encodable for TxMerkleNode {
impl encoding::Decodable for TxMerkleNode {
type Decoder = TxMerkleNodeDecoder;
+ #[inline]
fn decoder() -> Self::Decoder { TxMerkleNodeDecoder(encoding::ArrayDecoder::<32>::new()) }
}
@@ -74,10 +76,12 @@ pub struct TxMerkleNodeDecoder(encoding::ArrayDecoder<32>);
impl TxMerkleNodeDecoder {
/// Constructs a new [`TxMerkleNode`] decoder.
+ #[inline]
pub const fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
}
impl Default for TxMerkleNodeDecoder {
+ #[inline]
fn default() -> Self { Self::new() }
}
diff --git a/primitives/src/hash_types/witness_merkle_node.rs b/primitives/src/hash_types/witness_merkle_node.rs
index 9319520c..05f8ced6 100644
--- a/primitives/src/hash_types/witness_merkle_node.rs
+++ b/primitives/src/hash_types/witness_merkle_node.rs
@@ -52,6 +52,7 @@ impl WitnessMerkleNode {
impl encoding::Encodable for WitnessMerkleNode {
type Encoder<'e> = WitnessMerkleNodeEncoder<'e>;
+ #[inline]
fn encoder(&self) -> Self::Encoder<'_> {
WitnessMerkleNodeEncoder::new(encoding::ArrayRefEncoder::without_length_prefix(
self.as_byte_array(),
@@ -61,6 +62,7 @@ impl encoding::Encodable for WitnessMerkleNode {
impl encoding::Decodable for WitnessMerkleNode {
type Decoder = WitnessMerkleNodeDecoder;
+ #[inline]
fn decoder() -> Self::Decoder { WitnessMerkleNodeDecoder(encoding::ArrayDecoder::<32>::new()) }
}
@@ -74,10 +76,12 @@ pub struct WitnessMerkleNodeDecoder(encoding::ArrayDecoder<32>);
impl WitnessMerkleNodeDecoder {
/// Constructs a new [`WitnessMerkleNode`] decoder.
+ #[inline]
pub const fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
}
impl Default for WitnessMerkleNodeDecoder {
+ #[inline]
fn default() -> Self { Self::new() }
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.