Skip to content

Commit

Permalink
Creating BytesMut with appropriate capacity in ENR Builder (#83)
Browse files Browse the repository at this point in the history
Signed-off-by: Archisman-Mridha <[email protected]>
  • Loading branch information
Archisman-Mridha authored Sep 17, 2024
1 parent 6c64250 commit 80d220e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<K: EnrKey> Builder<K> {

/// Adds an arbitrary key-value to the `ENRBuilder`.
pub fn add_value<T: Encodable>(&mut self, key: impl AsRef<[u8]>, value: &T) -> &mut Self {
let mut out = BytesMut::new();
let mut out = BytesMut::with_capacity(value.length());
value.encode(&mut out);
self.add_value_rlp(key, out.freeze())
}
Expand Down Expand Up @@ -140,7 +140,7 @@ impl<K: EnrKey> Builder<K> {
list: true,
payload_length: list.len(),
};
let mut out = BytesMut::new();
let mut out = BytesMut::with_capacity(header.length() + list.len());
header.encode(&mut out);
out.extend_from_slice(&list);
out
Expand Down Expand Up @@ -177,7 +177,7 @@ impl<K: EnrKey> Builder<K> {
Header::decode(&mut value.as_ref())?;
}

let mut id_bytes = BytesMut::with_capacity(3);
let mut id_bytes = BytesMut::with_capacity(self.id.length());
self.id.as_bytes().encode(&mut id_bytes);
self.add_value_rlp("id", id_bytes.freeze());

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ impl<K: EnrKey> Enr<K> {

/// Sets a new public key for the record.
pub fn set_public_key(&mut self, public_key: &K::PublicKey, key: &K) -> Result<(), Error> {
self.insert(&public_key.enr_key(), &public_key.encode().as_ref(), key)
self.insert(public_key.enr_key(), &public_key.encode().as_ref(), key)
.map(|_| {})
}

Expand Down

0 comments on commit 80d220e

Please sign in to comment.