Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating BytesMut with appropriate capacity in ENR Builder #83

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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