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

Allocate Vec capacity based on size hints during decoding #293

Merged
merged 5 commits into from
Apr 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions ethabi/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn decode_impl(types: &[ParamType], data: &[u8], validate: bool) -> Result<(Vec<
));
}

let mut tokens = vec![];
let mut tokens = Vec::with_capacity(types.len());
let mut offset = 0;

for param in types {
Expand Down Expand Up @@ -177,7 +177,7 @@ fn decode_param(param: &ParamType, data: &[u8], offset: usize, validate: bool) -
let tail_offset = len_offset + 32;
let tail = &data[tail_offset..];

let mut tokens = vec![];
let mut tokens = Vec::with_capacity(len);
let mut new_offset = 0;

for _ in 0..len {
Expand All @@ -203,7 +203,7 @@ fn decode_param(param: &ParamType, data: &[u8], offset: usize, validate: bool) -
(data, offset)
};

let mut tokens = vec![];
let mut tokens = Vec::with_capacity(len);

for _ in 0..len {
let res = decode_param(t, tail, new_offset, validate)?;
Expand Down