Skip to content

Commit

Permalink
Only get the next order when needed (#128)
Browse files Browse the repository at this point in the history
* move get next

* rename

* refactor
  • Loading branch information
brittcyr authored Oct 2, 2024
1 parent 4b4d7fe commit 240628f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions programs/manifest/src/state/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,13 @@ impl<Fixed: DerefOrBorrowMut<MarketFixed>, Dynamic: DerefOrBorrowMut<[u8]>>

let mut remaining_base_atoms: BaseAtoms = num_base_atoms;
while remaining_base_atoms > BaseAtoms::ZERO && current_order_index != NIL {
let next_order_index: DataIndex =
get_next_candidate_match_index(fixed, dynamic, current_order_index, is_bid);

let other_order: &RestingOrder =
get_helper::<RBNode<RestingOrder>>(dynamic, current_order_index).get_value();

// Remove the resting order if expired.
if other_order.is_expired(now_slot) {
let next_order_index: DataIndex =
get_next_candidate_match_index(fixed, dynamic, current_order_index, is_bid);
remove_and_update_balances(
fixed,
dynamic,
Expand Down Expand Up @@ -693,6 +692,8 @@ impl<Fixed: DerefOrBorrowMut<MarketFixed>, Dynamic: DerefOrBorrowMut<[u8]>>
}),
)?;
if !has_enough_tokens {
let next_order_index: DataIndex =
get_next_candidate_match_index(fixed, dynamic, current_order_index, is_bid);
remove_and_update_balances(
fixed,
dynamic,
Expand Down Expand Up @@ -821,6 +822,8 @@ impl<Fixed: DerefOrBorrowMut<MarketFixed>, Dynamic: DerefOrBorrowMut<[u8]>>
remove_from_global(&global_trade_accounts_opt, &maker)?;
}

let next_order_index: DataIndex =
get_next_candidate_match_index(fixed, dynamic, current_order_index, is_bid);
remove_order_from_tree_and_free(fixed, dynamic, current_order_index, !is_bid)?;
remaining_base_atoms = remaining_base_atoms.checked_sub(base_atoms_traded)?;
current_order_index = next_order_index;
Expand Down

0 comments on commit 240628f

Please sign in to comment.