Skip to content

Commit 5850c9c

Browse files
lang: Reduce cloning in realloc constraint when shrinking (#4642)
* lang: Reduce cloning in `realloc` constraint when shrinking * tests: Remove the unused Cargo profile in `realloc` * Update CHANGELOG --------- Co-authored-by: Jamie Hill-Daniel <134328753+jamie-osec@users.noreply.github.com>
1 parent 5e426b4 commit 5850c9c

3 files changed

Lines changed: 3 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ The minor version will be incremented upon a breaking change and the patch versi
5151
- ts: Validate instruction args in `BorshInstructionCoder.encode` to reject typo'd or missing fields instead of silently ignoring them ([#4560](https://github.com/solana-foundation/anchor/pull/4560)).
5252
- ts: Align TS `camelCase` conversion with Rust `heck` for digit-letter identifiers so generated client names match Rust identifiers ([#4571](https://github.com/solana-foundation/anchor/pull/4571)).
5353
- cli: Warn if `event-cpi` instruction is unreachable with custom discriminators ([#4614](https://github.com/solana-foundation/anchor/pull/4614)).
54+
- lang: Reduce cloning in `realloc` constraint when shrinking ([#4642](https://github.com/solana-foundation/anchor/pull/4642)).
5455
- syn: Remove `anyhow` ([#4640](https://github.com/solana-foundation/anchor/pull/4640)).
5556
- ts: Update `engines.node` to `>= 20.18` ([#4647](https://github.com/solana-foundation/anchor/pull/4647)).
5657

lang/syn/src/codegen/accounts/constraints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ fn generate_constraint_realloc(
484484
}
485485
} else {
486486
let __lamport_amt = __field_info.lamports().checked_sub(__new_rent_minimum).unwrap();
487-
**#payer.to_account_info().lamports.borrow_mut() = #payer.to_account_info().lamports().checked_add(__lamport_amt).unwrap();
488-
**__field_info.lamports.borrow_mut() = __field_info.lamports().checked_sub(__lamport_amt).unwrap();
487+
anchor_lang::Lamports::add_lamports(&#payer, __lamport_amt)?;
488+
anchor_lang::Lamports::sub_lamports(&__field_info, __lamport_amt)?;
489489
}
490490

491491
__field_info.resize(#new_space)?;

tests/realloc/programs/realloc/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,5 @@ cpi = ["no-entrypoint"]
1515
default = []
1616
idl-build = ["anchor-lang/idl-build"]
1717

18-
[profile.release]
19-
overflow-checks = true
20-
2118
[dependencies]
2219
anchor-lang = { path = "../../../../lang" }

0 commit comments

Comments
 (0)