BlockHash: Inline all the consensus encoding stuff
What changed, and why it matters
This commit only adds Rust compiler hints (`#[inline]`) to a few small functions related to encoding and decoding block hashes. It does not change what the code does, only gives the compiler permission to embed these tiny functions directly at call sites for potential performance gains. There is no security relevance.
No security action needed. Treat as a normal performance/refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds #[inline] attributes to BlockHash::encoder, BlockHash::decoder, BlockHashDecoder::new, and BlockHashDecoder::default. These are pure performance-oriented annotations; they do not alter semantics, error handling, input validation, or memory safety. No security bug is introduced or fixed.
Changed components
primitives/src/hash_types/block_hash.rsInspect captured patch +4 / −0
diff --git a/primitives/src/hash_types/block_hash.rs b/primitives/src/hash_types/block_hash.rs
index b305966e..d2784f37 100644
--- a/primitives/src/hash_types/block_hash.rs
+++ b/primitives/src/hash_types/block_hash.rs
@@ -37,6 +37,7 @@ encoding::encoder_newtype_exact! {
impl encoding::Encodable for BlockHash {
type Encoder<'e> = BlockHashEncoder<'e>;
+ #[inline]
fn encoder(&self) -> Self::Encoder<'_> {
BlockHashEncoder::new(encoding::ArrayRefEncoder::without_length_prefix(self.as_byte_array()))
}
@@ -44,6 +45,7 @@ impl encoding::Encodable for BlockHash {
impl encoding::Decodable for BlockHash {
type Decoder = BlockHashDecoder;
+ #[inline]
fn decoder() -> Self::Decoder { BlockHashDecoder(encoding::ArrayDecoder::<32>::new()) }
}
@@ -52,10 +54,12 @@ pub struct BlockHashDecoder(encoding::ArrayDecoder<32>);
impl BlockHashDecoder {
/// Constructs a new [`BlockHash`] decoder.
+ #[inline]
pub const fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
}
impl Default for BlockHashDecoder {
+ #[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.