Skip to content

Commit

Permalink
improve Rust close-account fn performance (#42)
Browse files Browse the repository at this point in the history
* improve Rust close-account fn performance

* Add changeset

* add system program import
  • Loading branch information
samuelvanderwaal authored May 16, 2024
1 parent a514aa8 commit 2d199b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-experts-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-solana-program": patch
---

Improve close account helper function performance in Rust client
8 changes: 3 additions & 5 deletions template/programs/counter-shank/program/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use solana_program::{
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
system_instruction,
system_instruction, system_program,
sysvar::Sysvar,
};

Expand Down Expand Up @@ -83,10 +83,8 @@ pub fn close_account<'a>(
.unwrap();
**target_account.lamports.borrow_mut() = 0;

let mut src_data = target_account.data.borrow_mut();
src_data.fill(0);

Ok(())
target_account.assign(&system_program::ID);
target_account.realloc(0, false)
}

/// Transfer lamports.
Expand Down

0 comments on commit 2d199b4

Please sign in to comment.