Skip to content

Commit

Permalink
opt vec alloc in nft transfer execute
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Nov 7, 2024
1 parent f54cc14 commit 6761a45
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ where
// overwrite even if they are set in MsgTransfer
if let Some(uris) = &mut packet_data.token_uris {
uris.clear();
uris.reserve_exact(token_ids.0.len());

Check warning on line 175 in ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs

View check run for this annotation

Codecov / codecov/patch

ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs#L175

Added line #L175 was not covered by tests
}
if let Some(data) = &mut packet_data.token_data {
data.clear();
data.reserve_exact(token_ids.0.len());

Check warning on line 179 in ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs

View check run for this annotation

Codecov / codecov/patch

ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs#L179

Added line #L179 was not covered by tests
}
for token_id in token_ids.as_ref() {
if is_sender_chain_source(msg.port_id_on_a.clone(), msg.chan_id_on_a.clone(), class_id) {
Expand All @@ -197,14 +199,14 @@ where
let nft = transfer_ctx.get_nft(class_id, token_id)?;
// Set the URI and the data if both exists
if let (Some(uri), Some(data)) = (nft.get_uri(), nft.get_data()) {
match &mut packet_data.token_uris {
Some(uris) => uris.push(uri.clone()),
None => packet_data.token_uris = Some(vec![uri.clone()]),
}
match &mut packet_data.token_data {
Some(token_data) => token_data.push(data.clone()),
None => packet_data.token_data = Some(vec![data.clone()]),
}
packet_data
.token_uris
.get_or_insert_with(|| Vec::with_capacity(token_ids.0.len()))
.push(uri.clone());
packet_data
.token_data
.get_or_insert_with(|| Vec::with_capacity(token_ids.0.len()))
.push(data.clone());

Check warning on line 209 in ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs

View check run for this annotation

Codecov / codecov/patch

ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs#L202-L209

Added lines #L202 - L209 were not covered by tests
}
}

Expand Down

0 comments on commit 6761a45

Please sign in to comment.