From 68f0b0a08f58723a8897e5e503863620003a61c6 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 30 Sep 2024 23:59:03 +0200 Subject: [PATCH] perf(db): use Into to encode StoredNibbles (#11350) --- crates/primitives/src/transaction/mod.rs | 2 +- crates/storage/db-api/src/models/mod.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 1e604acdf08d..a1e070e28a14 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -862,7 +862,7 @@ impl TransactionSignedNoHash { /// Recover signer from signature and hash _without ensuring that the signature has a low `s` /// value_. /// - /// Re-uses a given buffer to avoid numerous reallocations when recovering batches. **Clears the + /// Reuses a given buffer to avoid numerous reallocations when recovering batches. **Clears the /// buffer before use.** /// /// Returns `None` if the transaction's signature is invalid, see also diff --git a/crates/storage/db-api/src/models/mod.rs b/crates/storage/db-api/src/models/mod.rs index 9e7e8957b5a9..2466a42c52cd 100644 --- a/crates/storage/db-api/src/models/mod.rs +++ b/crates/storage/db-api/src/models/mod.rs @@ -125,9 +125,9 @@ impl Encode for StoredNibbles { // Delegate to the Compact implementation fn encode(self) -> Self::Encoded { - let mut buf = Vec::with_capacity(self.0.len()); - self.to_compact(&mut buf); - buf + // NOTE: This used to be `to_compact`, but all it does is append the bytes to the buffer, + // so we can just use the implementation of `Into>` to reuse the buffer. + self.0.into() } }