Skip to content

Commit

Permalink
optimize emit macro to reduce cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
ngundotra committed May 3, 2023
1 parent bbd869b commit 7bc2c25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lang/attribute/event/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ pub fn emit_cpi(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let second = &elems[1];

proc_macro::TokenStream::from(quote! {
let program_info: &anchor_lang::solana_program::account_info::AccountInfo = &#first;
let program_info: anchor_lang::solana_program::account_info::AccountInfo = #first;

let __disc = crate::event::EVENT_IX_TAG_LE;
let __inner_data: Vec<u8> = anchor_lang::Event::data(&#second);
let ix_data: Vec<u8> = __disc.into_iter().chain(__inner_data.into_iter()).collect();
let __ix_data: Vec<u8> = __disc.into_iter().chain(__inner_data.into_iter()).collect();

let ix = anchor_lang::solana_program::instruction::Instruction::new_with_bytes(
program_info.key.clone(),
ix_data.as_ref(),
let __ix = anchor_lang::solana_program::instruction::Instruction::new_with_bytes(
*program_info.key,
__ix_data.as_ref(),
vec![anchor_lang::solana_program::instruction::AccountMeta::new_readonly(*program_info.key, false)],
);
anchor_lang::solana_program::program::invoke(&ix, &[program_info.clone()])
.map_err(|e: anchor_lang::solana_program::program_error::ProgramError| crate::Error::from(e))?;
anchor_lang::solana_program::program::invoke(&__ix, &[program_info])
.map_err(anchor_lang::error::Error::from)?;
})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/events/programs/events/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod events {

pub fn test_event_cpi(ctx: Context<TestEventCpi>) -> Result<()> {
emit_cpi!((
&ctx.accounts.program.to_account_info(),
ctx.accounts.program.to_account_info(),
MyOtherEvent {
data: 7,
label: "cpi".to_string(),
Expand Down

0 comments on commit 7bc2c25

Please sign in to comment.