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

eips: update fn encoded_2718 #1475

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Conversation

nkysg
Copy link
Contributor

@nkysg nkysg commented Oct 14, 2024

use Vec::with_capacity avoid realloc

Motivation

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@@ -208,7 +208,7 @@ pub trait Encodable2718: Sized + Send + Sync + 'static {
/// This is a convenience method for encoding into a vec, and returning the
/// vec.
fn encoded_2718(&self) -> Vec<u8> {
let mut out = vec![];
let mut out = Vec::with_capacity(self.encode_2718_len());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is problematic because this could end up doing encoding twice @klkvr ?

but idk

Copy link
Member

@klkvr klkvr Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already do this in alloy_rlp::encode: https://github.com/alloy-rs/rlp/blob/44606e88cb7ca9397a5b5e57a3299d4ae0305e01/crates/rlp/src/encode.rs#L292

and we don't even provide default encode_2718_len here so I think it's OK to expect implementations to provide a smarter impl

should be fine imo

@mattsse mattsse merged commit f3de42e into alloy-rs:main Oct 18, 2024
26 checks passed
@nkysg nkysg deleted the update_encoded_2718 branch October 23, 2024 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants